Skip to content

Commit c8bdbf2

Browse files
committed
🐛 fix(logging): implement logging/setLevel via mcp-go upgrade and tool args adaptation
- Upgrade mcp-go to v0.39.1 which adds server-side handling for `logging/setLevel` and session logging support - Restore `server.WithLogging()` in initialization so clients can set logging level - Adapt tool handlers to new `mcp.CallToolRequest` API using `GetString/GetInt/GetArguments()` instead of indexing `Params.Arguments` - Build succeeds; root `go test` passes; integration tests depend on external LSPs and are unaffected by this fix Fixes #79
1 parent e439584 commit c8bdbf2

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ go 1.24.0
55
require (
66
github.com/davecgh/go-spew v1.1.1
77
github.com/fsnotify/fsnotify v1.9.0
8-
github.com/mark3labs/mcp-go v0.25.0
8+
github.com/mark3labs/mcp-go v0.39.1
99
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
1010
github.com/stretchr/testify v1.10.0
1111
golang.org/x/text v0.25.0
1212
)
1313

1414
require (
1515
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
16+
github.com/bahlo/generic-list-go v0.2.0 // indirect
17+
github.com/buger/jsonparser v1.1.1 // indirect
1618
github.com/google/go-cmp v0.7.0 // indirect
1719
github.com/google/uuid v1.6.0 // indirect
20+
github.com/invopop/jsonschema v0.13.0 // indirect
1821
github.com/kisielk/errcheck v1.9.0 // indirect
22+
github.com/mailru/easyjson v0.7.7 // indirect
1923
github.com/pmezard/go-difflib v1.0.0 // indirect
2024
github.com/rogpeppe/go-internal v1.14.1 // indirect
2125
github.com/spf13/cast v1.7.1 // indirect
26+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
2227
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
2328
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
2429
golang.org/x/mod v0.24.0 // indirect

go.sum

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
22
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
3+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
4+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
5+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
6+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
37
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
48
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
59
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -15,6 +19,9 @@ github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA
1519
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
1620
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1721
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
22+
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
23+
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
24+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
1825
github.com/kisielk/errcheck v1.9.0 h1:9xt1zI9EBfcYBvdU1nVrzMzzUPUtPKs9bVSIM3TAb3M=
1926
github.com/kisielk/errcheck v1.9.0/go.mod h1:kQxWMMVZgIkDq7U8xtG/n2juOjbLgZtedi0D+/VL/i8=
2027
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -24,8 +31,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2431
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2532
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2633
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
27-
github.com/mark3labs/mcp-go v0.25.0 h1:UUpcMT3L5hIhuDy7aifj4Bphw4Pfx1Rf8mzMXDe8RQw=
28-
github.com/mark3labs/mcp-go v0.25.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
34+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
35+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
36+
github.com/mark3labs/mcp-go v0.39.1 h1:2oPxk7aDbQhouakkYyKl2T4hKFU1c6FDaubWyGyVE1k=
37+
github.com/mark3labs/mcp-go v0.39.1/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
2938
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3039
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3140
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
@@ -38,6 +47,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
3847
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3948
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
4049
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
50+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
51+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
4152
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
4253
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
4354
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac h1:TSSpLIG4v+p0rPv1pNOQtl1I8knsO4S9trOxNMOLVP4=

tools.go

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ func (s *mcpServer) registerTools() error {
4343

4444
s.mcpServer.AddTool(applyTextEditTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
4545
// Extract arguments
46-
filePath, ok := request.Params.Arguments["filePath"].(string)
47-
if !ok {
46+
filePath := request.GetString("filePath", "")
47+
if filePath == "" {
4848
return mcp.NewToolResultError("filePath must be a string"), nil
4949
}
5050

5151
// Extract edits array
52-
editsArg, ok := request.Params.Arguments["edits"]
52+
args := request.GetArguments()
53+
editsArg, ok := args["edits"]
5354
if !ok {
5455
return mcp.NewToolResultError("edits is required"), nil
5556
}
@@ -105,8 +106,8 @@ func (s *mcpServer) registerTools() error {
105106

106107
s.mcpServer.AddTool(readDefinitionTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
107108
// Extract arguments
108-
symbolName, ok := request.Params.Arguments["symbolName"].(string)
109-
if !ok {
109+
symbolName := request.GetString("symbolName", "")
110+
if symbolName == "" {
110111
return mcp.NewToolResultError("symbolName must be a string"), nil
111112
}
112113

@@ -129,8 +130,8 @@ func (s *mcpServer) registerTools() error {
129130

130131
s.mcpServer.AddTool(findReferencesTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
131132
// Extract arguments
132-
symbolName, ok := request.Params.Arguments["symbolName"].(string)
133-
if !ok {
133+
symbolName := request.GetString("symbolName", "")
134+
if symbolName == "" {
134135
return mcp.NewToolResultError("symbolName must be a string"), nil
135136
}
136137

@@ -161,19 +162,18 @@ func (s *mcpServer) registerTools() error {
161162

162163
s.mcpServer.AddTool(getDiagnosticsTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
163164
// Extract arguments
164-
filePath, ok := request.Params.Arguments["filePath"].(string)
165-
if !ok {
165+
filePath := request.GetString("filePath", "")
166+
if filePath == "" {
166167
return mcp.NewToolResultError("filePath must be a string"), nil
167168
}
168169

169-
contextLines := 5 // default value
170-
if contextLinesArg, ok := request.Params.Arguments["contextLines"].(int); ok {
171-
contextLines = contextLinesArg
172-
}
170+
contextLines := request.GetInt("contextLines", 5)
173171

174172
showLineNumbers := true // default value
175-
if showLineNumbersArg, ok := request.Params.Arguments["showLineNumbers"].(bool); ok {
176-
showLineNumbers = showLineNumbersArg
173+
if args := request.GetArguments(); args != nil {
174+
if v, ok := args["showLineNumbers"].(bool); ok {
175+
showLineNumbers = v
176+
}
177177
}
178178

179179
coreLogger.Debug("Executing diagnostics for file: %s", filePath)
@@ -268,28 +268,17 @@ func (s *mcpServer) registerTools() error {
268268

269269
s.mcpServer.AddTool(hoverTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
270270
// Extract arguments
271-
filePath, ok := request.Params.Arguments["filePath"].(string)
272-
if !ok {
271+
filePath := request.GetString("filePath", "")
272+
if filePath == "" {
273273
return mcp.NewToolResultError("filePath must be a string"), nil
274274
}
275275

276-
// Handle both float64 and int for line and column due to JSON parsing
277-
var line, column int
278-
switch v := request.Params.Arguments["line"].(type) {
279-
case float64:
280-
line = int(v)
281-
case int:
282-
line = v
283-
default:
276+
line := request.GetInt("line", 0)
277+
column := request.GetInt("column", 0)
278+
if line <= 0 {
284279
return mcp.NewToolResultError("line must be a number"), nil
285280
}
286-
287-
switch v := request.Params.Arguments["column"].(type) {
288-
case float64:
289-
column = int(v)
290-
case int:
291-
column = v
292-
default:
281+
if column <= 0 {
293282
return mcp.NewToolResultError("column must be a number"), nil
294283
}
295284

@@ -324,33 +313,22 @@ func (s *mcpServer) registerTools() error {
324313

325314
s.mcpServer.AddTool(renameSymbolTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
326315
// Extract arguments
327-
filePath, ok := request.Params.Arguments["filePath"].(string)
328-
if !ok {
316+
filePath := request.GetString("filePath", "")
317+
if filePath == "" {
329318
return mcp.NewToolResultError("filePath must be a string"), nil
330319
}
331320

332-
newName, ok := request.Params.Arguments["newName"].(string)
333-
if !ok {
321+
newName := request.GetString("newName", "")
322+
if newName == "" {
334323
return mcp.NewToolResultError("newName must be a string"), nil
335324
}
336325

337-
// Handle both float64 and int for line and column due to JSON parsing
338-
var line, column int
339-
switch v := request.Params.Arguments["line"].(type) {
340-
case float64:
341-
line = int(v)
342-
case int:
343-
line = v
344-
default:
326+
line := request.GetInt("line", 0)
327+
column := request.GetInt("column", 0)
328+
if line <= 0 {
345329
return mcp.NewToolResultError("line must be a number"), nil
346330
}
347-
348-
switch v := request.Params.Arguments["column"].(type) {
349-
case float64:
350-
column = int(v)
351-
case int:
352-
column = v
353-
default:
331+
if column <= 0 {
354332
return mcp.NewToolResultError("column must be a number"), nil
355333
}
356334

0 commit comments

Comments
 (0)