Skip to content

Commit f1cb49e

Browse files
committed
rename tools and remove codelens
1 parent 9c42d5f commit f1cb49e

File tree

6 files changed

+79
-77
lines changed

6 files changed

+79
-77
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,14 @@ This is an [MCP](https://modelcontextprotocol.io/introduction) server that runs
140140

141141
## Tools
142142

143-
- `read_definition`: Retrieves the complete source code definition of any symbol (function, type, constant, etc.) from your codebase.
144-
- `find_references`: Locates all usages and references of a symbol throughout the codebase.
145-
- `get_diagnostics`: Provides diagnostic information for a specific file, including warnings and errors.
146-
- `get_codelens`: Retrieves code lens hints for additional context and actions on your code.
147-
- `execute_codelens`: Runs a code lens action.
143+
- `definition`: Retrieves the complete source code definition of any symbol (function, type, constant, etc.) from your codebase.
144+
- `references`: Locates all usages and references of a symbol throughout the codebase.
145+
- `diagnostics`: Provides diagnostic information for a specific file, including warnings and errors.
148146
- `hover`: Display documentation, type hints, or other hover information for a given location.
149147
- `rename_symbol`: Rename a symbol across a project.
150-
- `apply_text_edit`: Allows making multiple text edits to a file programmatically.
148+
- `edit_file`: Allows making multiple text edits to a file programmatically.
151149

152-
Behind the scenes, this MCP server can act on `workspace/applyEdit` requests from the language server.
150+
The `edit_file` tool is not strictly related to the language server but it provides a more reliable and context economical way to edit files compared to search and replace based edit tools, provided you have line numbers.
153151

154152
## About
155153

integrationtests/tests/go/codelens/codelens_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414

1515
// TestCodeLens tests the codelens functionality with the Go language server
1616
func TestCodeLens(t *testing.T) {
17+
t.Skip("Remove this line to run codelens tool tests")
18+
1719
// Test GetCodeLens with a file that should have codelenses
1820
t.Run("GetCodeLens", func(t *testing.T) {
1921
suite := internal.GetTestSuite(t)

tools.go

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func (s *mcpServer) registerTools() error {
1212
coreLogger.Debug("Registering MCP tools")
1313

14-
applyTextEditTool := mcp.NewTool("apply_text_edit",
14+
applyTextEditTool := mcp.NewTool("edit_file",
1515
mcp.WithDescription("Apply multiple text edits to a file."),
1616
mcp.WithArray("edits",
1717
mcp.Required(),
@@ -86,7 +86,7 @@ func (s *mcpServer) registerTools() error {
8686
})
8787
}
8888

89-
coreLogger.Debug("Executing apply_text_edit for file: %s", filePath)
89+
coreLogger.Debug("Executing edit_file for file: %s", filePath)
9090
response, err := tools.ApplyTextEdits(s.ctx, s.lspClient, filePath, edits)
9191
if err != nil {
9292
coreLogger.Error("Failed to apply edits: %v", err)
@@ -95,7 +95,7 @@ func (s *mcpServer) registerTools() error {
9595
return mcp.NewToolResultText(response), nil
9696
})
9797

98-
readDefinitionTool := mcp.NewTool("read_definition",
98+
readDefinitionTool := mcp.NewTool("definition",
9999
mcp.WithDescription("Read the source code definition of a symbol (function, type, constant, etc.) from the codebase. Returns the complete implementation code where the symbol is defined."),
100100
mcp.WithString("symbolName",
101101
mcp.Required(),
@@ -119,7 +119,7 @@ func (s *mcpServer) registerTools() error {
119119
showLineNumbers = showLineNumbersArg
120120
}
121121

122-
coreLogger.Debug("Executing read_definition for symbol: %s", symbolName)
122+
coreLogger.Debug("Executing definition for symbol: %s", symbolName)
123123
text, err := tools.ReadDefinition(s.ctx, s.lspClient, symbolName, showLineNumbers)
124124
if err != nil {
125125
coreLogger.Error("Failed to get definition: %v", err)
@@ -128,7 +128,7 @@ func (s *mcpServer) registerTools() error {
128128
return mcp.NewToolResultText(text), nil
129129
})
130130

131-
findReferencesTool := mcp.NewTool("find_references",
131+
findReferencesTool := mcp.NewTool("references",
132132
mcp.WithDescription("Find all usages and references of a symbol throughout the codebase. Returns a list of all files and locations where the symbol appears."),
133133
mcp.WithString("symbolName",
134134
mcp.Required(),
@@ -152,7 +152,7 @@ func (s *mcpServer) registerTools() error {
152152
showLineNumbers = showLineNumbersArg
153153
}
154154

155-
coreLogger.Debug("Executing find_references for symbol: %s", symbolName)
155+
coreLogger.Debug("Executing references for symbol: %s", symbolName)
156156
text, err := tools.FindReferences(s.ctx, s.lspClient, symbolName, showLineNumbers)
157157
if err != nil {
158158
coreLogger.Error("Failed to find references: %v", err)
@@ -161,7 +161,7 @@ func (s *mcpServer) registerTools() error {
161161
return mcp.NewToolResultText(text), nil
162162
})
163163

164-
getDiagnosticsTool := mcp.NewTool("get_diagnostics",
164+
getDiagnosticsTool := mcp.NewTool("diagnostics",
165165
mcp.WithDescription("Get diagnostic information for a specific file from the language server."),
166166
mcp.WithString("filePath",
167167
mcp.Required(),
@@ -194,7 +194,7 @@ func (s *mcpServer) registerTools() error {
194194
showLineNumbers = showLineNumbersArg
195195
}
196196

197-
coreLogger.Debug("Executing get_diagnostics for file: %s", filePath)
197+
coreLogger.Debug("Executing diagnostics for file: %s", filePath)
198198
text, err := tools.GetDiagnosticsForFile(s.ctx, s.lspClient, filePath, contextLines, showLineNumbers)
199199
if err != nil {
200200
coreLogger.Error("Failed to get diagnostics: %v", err)
@@ -203,68 +203,70 @@ func (s *mcpServer) registerTools() error {
203203
return mcp.NewToolResultText(text), nil
204204
})
205205

206-
getCodeLensTool := mcp.NewTool("get_codelens",
207-
mcp.WithDescription("Get code lens hints for a given file from the language server."),
208-
mcp.WithString("filePath",
209-
mcp.Required(),
210-
mcp.Description("The path to the file to get code lens information for"),
211-
),
212-
)
213-
214-
s.mcpServer.AddTool(getCodeLensTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
215-
// Extract arguments
216-
filePath, ok := request.Params.Arguments["filePath"].(string)
217-
if !ok {
218-
return mcp.NewToolResultError("filePath must be a string"), nil
219-
}
220-
221-
coreLogger.Debug("Executing get_codelens for file: %s", filePath)
222-
text, err := tools.GetCodeLens(s.ctx, s.lspClient, filePath)
223-
if err != nil {
224-
coreLogger.Error("Failed to get code lens: %v", err)
225-
return mcp.NewToolResultError(fmt.Sprintf("failed to get code lens: %v", err)), nil
226-
}
227-
return mcp.NewToolResultText(text), nil
228-
})
229-
230-
executeCodeLensTool := mcp.NewTool("execute_codelens",
231-
mcp.WithDescription("Execute a code lens command for a given file and lens index."),
232-
mcp.WithString("filePath",
233-
mcp.Required(),
234-
mcp.Description("The path to the file containing the code lens to execute"),
235-
),
236-
mcp.WithNumber("index",
237-
mcp.Required(),
238-
mcp.Description("The index of the code lens to execute (from get_codelens output), 1 indexed"),
239-
),
240-
)
241-
242-
s.mcpServer.AddTool(executeCodeLensTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
243-
// Extract arguments
244-
filePath, ok := request.Params.Arguments["filePath"].(string)
245-
if !ok {
246-
return mcp.NewToolResultError("filePath must be a string"), nil
247-
}
248-
249-
// Handle both float64 and int for index due to JSON parsing
250-
var index int
251-
switch v := request.Params.Arguments["index"].(type) {
252-
case float64:
253-
index = int(v)
254-
case int:
255-
index = v
256-
default:
257-
return mcp.NewToolResultError("index must be a number"), nil
258-
}
259-
260-
coreLogger.Debug("Executing execute_codelens for file: %s index: %d", filePath, index)
261-
text, err := tools.ExecuteCodeLens(s.ctx, s.lspClient, filePath, index)
262-
if err != nil {
263-
coreLogger.Error("Failed to execute code lens: %v", err)
264-
return mcp.NewToolResultError(fmt.Sprintf("failed to execute code lens: %v", err)), nil
265-
}
266-
return mcp.NewToolResultText(text), nil
267-
})
206+
// Uncomment to add codelens tools
207+
//
208+
// getCodeLensTool := mcp.NewTool("get_codelens",
209+
// mcp.WithDescription("Get code lens hints for a given file from the language server."),
210+
// mcp.WithString("filePath",
211+
// mcp.Required(),
212+
// mcp.Description("The path to the file to get code lens information for"),
213+
// ),
214+
// )
215+
//
216+
// s.mcpServer.AddTool(getCodeLensTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
217+
// // Extract arguments
218+
// filePath, ok := request.Params.Arguments["filePath"].(string)
219+
// if !ok {
220+
// return mcp.NewToolResultError("filePath must be a string"), nil
221+
// }
222+
//
223+
// coreLogger.Debug("Executing get_codelens for file: %s", filePath)
224+
// text, err := tools.GetCodeLens(s.ctx, s.lspClient, filePath)
225+
// if err != nil {
226+
// coreLogger.Error("Failed to get code lens: %v", err)
227+
// return mcp.NewToolResultError(fmt.Sprintf("failed to get code lens: %v", err)), nil
228+
// }
229+
// return mcp.NewToolResultText(text), nil
230+
// })
231+
//
232+
// executeCodeLensTool := mcp.NewTool("execute_codelens",
233+
// mcp.WithDescription("Execute a code lens command for a given file and lens index."),
234+
// mcp.WithString("filePath",
235+
// mcp.Required(),
236+
// mcp.Description("The path to the file containing the code lens to execute"),
237+
// ),
238+
// mcp.WithNumber("index",
239+
// mcp.Required(),
240+
// mcp.Description("The index of the code lens to execute (from get_codelens output), 1 indexed"),
241+
// ),
242+
// )
243+
//
244+
// s.mcpServer.AddTool(executeCodeLensTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
245+
// // Extract arguments
246+
// filePath, ok := request.Params.Arguments["filePath"].(string)
247+
// if !ok {
248+
// return mcp.NewToolResultError("filePath must be a string"), nil
249+
// }
250+
//
251+
// // Handle both float64 and int for index due to JSON parsing
252+
// var index int
253+
// switch v := request.Params.Arguments["index"].(type) {
254+
// case float64:
255+
// index = int(v)
256+
// case int:
257+
// index = v
258+
// default:
259+
// return mcp.NewToolResultError("index must be a number"), nil
260+
// }
261+
//
262+
// coreLogger.Debug("Executing execute_codelens for file: %s index: %d", filePath, index)
263+
// text, err := tools.ExecuteCodeLens(s.ctx, s.lspClient, filePath, index)
264+
// if err != nil {
265+
// coreLogger.Error("Failed to execute code lens: %v", err)
266+
// return mcp.NewToolResultError(fmt.Sprintf("failed to execute code lens: %v", err)), nil
267+
// }
268+
// return mcp.NewToolResultText(text), nil
269+
// })
268270

269271
hoverTool := mcp.NewTool("hover",
270272
mcp.WithDescription("Get hover information (type, documentation) for a symbol at the specified position."),

0 commit comments

Comments
 (0)