Skip to content

Fix compilation errors in upgraded mcp-go #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.24.0
require (
github.com/davecgh/go-spew v1.1.1
github.com/fsnotify/fsnotify v1.9.0
github.com/mark3labs/mcp-go v0.25.0
github.com/mark3labs/mcp-go v0.31.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/stretchr/testify v1.10.0
golang.org/x/text v0.25.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mark3labs/mcp-go v0.25.0 h1:UUpcMT3L5hIhuDy7aifj4Bphw4Pfx1Rf8mzMXDe8RQw=
github.com/mark3labs/mcp-go v0.25.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/mark3labs/mcp-go v0.31.0 h1:4UxSV8aM770OPmTvaVe/b1rA2oZAjBMhGBfUgOGut+4=
github.com/mark3labs/mcp-go v0.31.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
Expand Down
99 changes: 36 additions & 63 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(applyTextEditTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
filePath, ok := request.Params.Arguments["filePath"].(string)
if !ok {
return mcp.NewToolResultError("filePath must be a string"), nil
filePath, err := request.RequireString("filePath")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

// Extract edits array
editsArg, ok := request.Params.Arguments["edits"]
editsArg, ok := request.GetArguments()["edits"]
if !ok {
return mcp.NewToolResultError("edits is required"), nil
}
Expand Down Expand Up @@ -105,9 +105,9 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(readDefinitionTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
symbolName, ok := request.Params.Arguments["symbolName"].(string)
if !ok {
return mcp.NewToolResultError("symbolName must be a string"), nil
symbolName, err := request.RequireString("symbolName")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

coreLogger.Debug("Executing definition for symbol: %s", symbolName)
Expand All @@ -129,9 +129,9 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(findReferencesTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
symbolName, ok := request.Params.Arguments["symbolName"].(string)
if !ok {
return mcp.NewToolResultError("symbolName must be a string"), nil
symbolName, err := request.RequireString("symbolName")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

coreLogger.Debug("Executing references for symbol: %s", symbolName)
Expand Down Expand Up @@ -161,20 +161,13 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(getDiagnosticsTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
filePath, ok := request.Params.Arguments["filePath"].(string)
if !ok {
return mcp.NewToolResultError("filePath must be a string"), nil
}

contextLines := 5 // default value
if contextLinesArg, ok := request.Params.Arguments["contextLines"].(int); ok {
contextLines = contextLinesArg
filePath, err := request.RequireString("filePath")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

showLineNumbers := true // default value
if showLineNumbersArg, ok := request.Params.Arguments["showLineNumbers"].(bool); ok {
showLineNumbers = showLineNumbersArg
}
contextLines := request.GetInt("contextLines", 5)
showLineNumbers := request.GetBool("showLineNumbers", true)

coreLogger.Debug("Executing diagnostics for file: %s", filePath)
text, err := tools.GetDiagnosticsForFile(s.ctx, s.lspClient, filePath, contextLines, showLineNumbers)
Expand Down Expand Up @@ -268,29 +261,19 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(hoverTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
filePath, ok := request.Params.Arguments["filePath"].(string)
if !ok {
return mcp.NewToolResultError("filePath must be a string"), nil
filePath, err := request.RequireString("filePath")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

// Handle both float64 and int for line and column due to JSON parsing
var line, column int
switch v := request.Params.Arguments["line"].(type) {
case float64:
line = int(v)
case int:
line = v
default:
return mcp.NewToolResultError("line must be a number"), nil
line, err := request.RequireInt("line")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

switch v := request.Params.Arguments["column"].(type) {
case float64:
column = int(v)
case int:
column = v
default:
return mcp.NewToolResultError("column must be a number"), nil
column, err := request.RequireInt("column")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

coreLogger.Debug("Executing hover for file: %s line: %d column: %d", filePath, line, column)
Expand Down Expand Up @@ -324,34 +307,24 @@ func (s *mcpServer) registerTools() error {

s.mcpServer.AddTool(renameSymbolTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Extract arguments
filePath, ok := request.Params.Arguments["filePath"].(string)
if !ok {
return mcp.NewToolResultError("filePath must be a string"), nil
filePath, err := request.RequireString("filePath")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

newName, ok := request.Params.Arguments["newName"].(string)
if !ok {
return mcp.NewToolResultError("newName must be a string"), nil
newName, err := request.RequireString("newName")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

// Handle both float64 and int for line and column due to JSON parsing
var line, column int
switch v := request.Params.Arguments["line"].(type) {
case float64:
line = int(v)
case int:
line = v
default:
return mcp.NewToolResultError("line must be a number"), nil
line, err := request.RequireInt("line")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

switch v := request.Params.Arguments["column"].(type) {
case float64:
column = int(v)
case int:
column = v
default:
return mcp.NewToolResultError("column must be a number"), nil
column, err := request.RequireInt("column")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

coreLogger.Debug("Executing rename_symbol for file: %s line: %d column: %d newName: %s", filePath, line, column, newName)
Expand Down
Loading