@@ -48,97 +48,11 @@ type CreateOp struct {
4848 Content string `json:"content"` // full file content
4949 }
5050
51+// anchor is the JSON schema fragment for a hashline anchor object.
52+const anchorSchema = `{"type": "object", "properties": {"line": {"type": "integer", "description": "1-indexed line number"}, "hash": {"type": "string", "description": "2-char hex hash from Read output"}}, "required": ["line", "hash"]}`
53+
5154 // NewEditTool creates the Edit tool definition.
5255 func NewEditTool() mcp.Tool {
53- schema := map[string]interface{}{
54- "type": "object",
55- "properties": map[string]interface{}{
56- "file": map[string]interface{}{
57- "type": "string",
58- "description": "Path to the file to edit",
59- },
60- "replace": map[string]interface{}{
61- "type": "object",
62- "description": "Replace lines from start to end (inclusive) with new content",
63- "properties": map[string]interface{}{
64- "start": map[string]interface{}{
65- "type": "object",
66- "description": "Anchor for first line to replace",
67- "properties": map[string]interface{}{
68- "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
69- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
70- },
71- "required": []string{"line", "hash"},
72- },
73- "end": map[string]interface{}{
74- "type": "object",
75- "description": "Anchor for last line to replace",
76- "properties": map[string]interface{}{
77- "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
78- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
79- },
80- "required": []string{"line", "hash"},
81- },
82- "content": map[string]interface{}{"type": "string", "description": "Replacement text (may be multiple lines)"},
83- },
84- "required": []string{"start", "end", "content"},
85- },
86- "insert": map[string]interface{}{
87- "type": "object",
88- "description": "Insert new lines after the anchored line",
89- "properties": map[string]interface{}{
90- "after": map[string]interface{}{
91- "type": "object",
92- "description": "Anchor for the line to insert after",
93- "properties": map[string]interface{}{
94- "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
95- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
96- },
97- "required": []string{"line", "hash"},
98- },
99- "content": map[string]interface{}{"type": "string", "description": "Text to insert (may be multiple lines)"},
100- },
101- "required": []string{"after", "content"},
102- },
103- "delete": map[string]interface{}{
104- "type": "object",
105- "description": "Delete lines from start to end (inclusive)",
106- "properties": map[string]interface{}{
107- "start": map[string]interface{}{
108- "type": "object",
109- "description": "Anchor for first line to delete",
110- "properties": map[string]interface{}{
111- "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
112- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
113- },
114- "required": []string{"line", "hash"},
115- },
116- "end": map[string]interface{}{
117- "type": "object",
118- "description": "Anchor for last line to delete",
119- "properties": map[string]interface{}{
120- "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
121- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
122- },
123- "required": []string{"line", "hash"},
124- },
125- },
126- "required": []string{"start", "end"},
127- },
128- "create": map[string]interface{}{
129- "type": "object",
130- "description": "Create a new file (fails if file already exists)",
131- "properties": map[string]interface{}{
132- "content": map[string]interface{}{"type": "string", "description": "Full file content"},
133- },
134- "required": []string{"content"},
135- },
136- },
137- "required": []string{"file"},
138- }
139-
140- schemaJSON, _ := json.Marshal(schema)
141-
14256 return mcp.Tool{
14357 Name: "Edit",
14458 Description: `Edit a file using hash-anchored operations. You MUST Read the file first to get line hashes.
@@ -146,7 +60,49 @@ Each line from Read is tagged as "linenum:hash|content". Use the line number and
14660 Exactly one operation per call: replace, insert, delete, or create.
14761 If a hash does not match, the file changed since you read it — re-Read and retry.
14862 After each edit you receive fresh hashes — use those for subsequent edits, not the old ones.`,
149- InputSchema: schemaJSON,
63+ InputSchema: json.RawMessage(`{
64+ "type": "object",
65+ "properties": {
66+ "file": {"type": "string", "description": "Path to the file to edit"},
67+ "replace": {
68+ "type": "object",
69+ "description": "Replace lines from start to end (inclusive) with new content",
70+ "properties": {
71+ "start": ` + anchorSchema + `,
72+ "end": ` + anchorSchema + `,
73+ "content": {"type": "string", "description": "Replacement text (may be multiple lines)"}
74+ },
75+ "required": ["start", "end", "content"]
76+ },
77+ "insert": {
78+ "type": "object",
79+ "description": "Insert new lines after the anchored line",
80+ "properties": {
81+ "after": ` + anchorSchema + `,
82+ "content": {"type": "string", "description": "Text to insert (may be multiple lines)"}
83+ },
84+ "required": ["after", "content"]
85+ },
86+ "delete": {
87+ "type": "object",
88+ "description": "Delete lines from start to end (inclusive)",
89+ "properties": {
90+ "start": ` + anchorSchema + `,
91+ "end": ` + anchorSchema + `
92+ },
93+ "required": ["start", "end"]
94+ },
95+ "create": {
96+ "type": "object",
97+ "description": "Create a new file (fails if file already exists)",
98+ "properties": {
99+ "content": {"type": "string", "description": "Full file content"}
100+ },
101+ "required": ["content"]
102+ }
103+ },
104+ "required": ["file"]
105+ }`),
150106 }
151107 }
152108