Skip to content

Commit d007869

Browse files
committed
chore(deps): update mcp-go to 0.29.0 and handle the breaking changes
1 parent 81e256a commit d007869

File tree

3 files changed

+55
-72
lines changed

3 files changed

+55
-72
lines changed

filesystemserver/handler.go

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ func (fs *FilesystemHandler) handleReadFile(
480480
ctx context.Context,
481481
request mcp.CallToolRequest,
482482
) (*mcp.CallToolResult, error) {
483-
path, ok := request.Params.Arguments["path"].(string)
484-
if !ok {
485-
return nil, fmt.Errorf("path must be a string")
483+
path, err := request.RequireString("path")
484+
if err != nil {
485+
return nil, err
486486
}
487487

488488
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -685,13 +685,13 @@ func (fs *FilesystemHandler) handleWriteFile(
685685
ctx context.Context,
686686
request mcp.CallToolRequest,
687687
) (*mcp.CallToolResult, error) {
688-
path, ok := request.Params.Arguments["path"].(string)
689-
if !ok {
690-
return nil, fmt.Errorf("path must be a string")
688+
path, err := request.RequireString("path")
689+
if err != nil {
690+
return nil, err
691691
}
692-
content, ok := request.Params.Arguments["content"].(string)
693-
if !ok {
694-
return nil, fmt.Errorf("content must be a string")
692+
content, err := request.RequireString("content")
693+
if err != nil {
694+
return nil, err
695695
}
696696

697697
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -801,9 +801,9 @@ func (fs *FilesystemHandler) handleListDirectory(
801801
ctx context.Context,
802802
request mcp.CallToolRequest,
803803
) (*mcp.CallToolResult, error) {
804-
path, ok := request.Params.Arguments["path"].(string)
805-
if !ok {
806-
return nil, fmt.Errorf("path must be a string")
804+
path, err := request.RequireString("path")
805+
if err != nil {
806+
return nil, err
807807
}
808808

809809
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -920,9 +920,9 @@ func (fs *FilesystemHandler) handleCreateDirectory(
920920
ctx context.Context,
921921
request mcp.CallToolRequest,
922922
) (*mcp.CallToolResult, error) {
923-
path, ok := request.Params.Arguments["path"].(string)
924-
if !ok {
925-
return nil, fmt.Errorf("path must be a string")
923+
path, err := request.RequireString("path")
924+
if err != nil {
925+
return nil, err
926926
}
927927

928928
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -1023,13 +1023,13 @@ func (fs *FilesystemHandler) handleCopyFile(
10231023
ctx context.Context,
10241024
request mcp.CallToolRequest,
10251025
) (*mcp.CallToolResult, error) {
1026-
source, ok := request.Params.Arguments["source"].(string)
1027-
if !ok {
1028-
return nil, fmt.Errorf("source must be a string")
1026+
source, err := request.RequireString("source")
1027+
if err != nil {
1028+
return nil, err
10291029
}
1030-
destination, ok := request.Params.Arguments["destination"].(string)
1031-
if !ok {
1032-
return nil, fmt.Errorf("destination must be a string")
1030+
destination, err := request.RequireString("destination")
1031+
if err != nil {
1032+
return nil, err
10331033
}
10341034

10351035
// Handle empty or relative paths for source
@@ -1259,13 +1259,13 @@ func (fs *FilesystemHandler) handleMoveFile(
12591259
ctx context.Context,
12601260
request mcp.CallToolRequest,
12611261
) (*mcp.CallToolResult, error) {
1262-
source, ok := request.Params.Arguments["source"].(string)
1263-
if !ok {
1264-
return nil, fmt.Errorf("source must be a string")
1262+
source, err := request.RequireString("source")
1263+
if err != nil {
1264+
return nil, err
12651265
}
1266-
destination, ok := request.Params.Arguments["destination"].(string)
1267-
if !ok {
1268-
return nil, fmt.Errorf("destination must be a string")
1266+
destination, err := request.RequireString("destination")
1267+
if err != nil {
1268+
return nil, err
12691269
}
12701270

12711271
// Handle empty or relative paths for source
@@ -1396,13 +1396,13 @@ func (fs *FilesystemHandler) handleSearchFiles(
13961396
ctx context.Context,
13971397
request mcp.CallToolRequest,
13981398
) (*mcp.CallToolResult, error) {
1399-
path, ok := request.Params.Arguments["path"].(string)
1400-
if !ok {
1401-
return nil, fmt.Errorf("path must be a string")
1399+
path, err := request.RequireString("path")
1400+
if err != nil {
1401+
return nil, err
14021402
}
1403-
pattern, ok := request.Params.Arguments["pattern"].(string)
1404-
if !ok {
1405-
return nil, fmt.Errorf("pattern must be a string")
1403+
pattern, err := request.RequireString("pattern")
1404+
if err != nil {
1405+
return nil, err
14061406
}
14071407

14081408
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -1520,9 +1520,9 @@ func (fs *FilesystemHandler) handleTree(
15201520
ctx context.Context,
15211521
request mcp.CallToolRequest,
15221522
) (*mcp.CallToolResult, error) {
1523-
path, ok := request.Params.Arguments["path"].(string)
1524-
if !ok {
1525-
return nil, fmt.Errorf("path must be a string")
1523+
path, err := request.RequireString("path")
1524+
if err != nil {
1525+
return nil, err
15261526
}
15271527

15281528
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -1545,18 +1545,14 @@ func (fs *FilesystemHandler) handleTree(
15451545

15461546
// Extract depth parameter (optional, default: 3)
15471547
depth := 3 // Default value
1548-
if depthParam, ok := request.Params.Arguments["depth"]; ok {
1549-
if d, ok := depthParam.(float64); ok {
1550-
depth = int(d)
1551-
}
1548+
if depthParam, err := request.RequireFloat("depth"); err != nil {
1549+
depth = int(depthParam)
15521550
}
15531551

15541552
// Extract follow_symlinks parameter (optional, default: false)
15551553
followSymlinks := false // Default value
1556-
if followParam, ok := request.Params.Arguments["follow_symlinks"]; ok {
1557-
if f, ok := followParam.(bool); ok {
1558-
followSymlinks = f
1559-
}
1554+
if followParam, err := request.RequireBool("follow_symlinks"); err != nil {
1555+
followSymlinks = followParam
15601556
}
15611557

15621558
// Validate the path is within allowed directories
@@ -1653,9 +1649,9 @@ func (fs *FilesystemHandler) handleGetFileInfo(
16531649
ctx context.Context,
16541650
request mcp.CallToolRequest,
16551651
) (*mcp.CallToolResult, error) {
1656-
path, ok := request.Params.Arguments["path"].(string)
1657-
if !ok {
1658-
return nil, fmt.Errorf("path must be a string")
1652+
path, err := request.RequireString("path")
1653+
if err != nil {
1654+
return nil, err
16591655
}
16601656

16611657
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -1756,15 +1752,9 @@ func (fs *FilesystemHandler) handleReadMultipleFiles(
17561752
ctx context.Context,
17571753
request mcp.CallToolRequest,
17581754
) (*mcp.CallToolResult, error) {
1759-
pathsParam, ok := request.Params.Arguments["paths"]
1760-
if !ok {
1761-
return nil, fmt.Errorf("paths parameter is required")
1762-
}
1763-
1764-
// Convert the paths parameter to a string slice
1765-
pathsSlice, ok := pathsParam.([]any)
1766-
if !ok {
1767-
return nil, fmt.Errorf("paths must be an array of strings")
1755+
pathsSlice, err := request.RequireStringSlice("paths")
1756+
if err != nil {
1757+
return nil, err
17681758
}
17691759

17701760
if len(pathsSlice) == 0 {
@@ -1795,12 +1785,7 @@ func (fs *FilesystemHandler) handleReadMultipleFiles(
17951785

17961786
// Process each file
17971787
var results []mcp.Content
1798-
for _, pathInterface := range pathsSlice {
1799-
path, ok := pathInterface.(string)
1800-
if !ok {
1801-
return nil, fmt.Errorf("each path must be a string")
1802-
}
1803-
1788+
for _, path := range pathsSlice {
18041789
// Handle empty or relative paths like "." or "./" by converting to absolute path
18051790
if path == "." || path == "./" {
18061791
// Get current working directory
@@ -1941,9 +1926,9 @@ func (fs *FilesystemHandler) handleDeleteFile(
19411926
ctx context.Context,
19421927
request mcp.CallToolRequest,
19431928
) (*mcp.CallToolResult, error) {
1944-
path, ok := request.Params.Arguments["path"].(string)
1945-
if !ok {
1946-
return nil, fmt.Errorf("path must be a string")
1929+
path, err := request.RequireString("path")
1930+
if err != nil {
1931+
return nil, err
19471932
}
19481933

19491934
// Handle empty or relative paths like "." or "./" by converting to absolute path
@@ -2003,10 +1988,8 @@ func (fs *FilesystemHandler) handleDeleteFile(
20031988

20041989
// Extract recursive parameter (optional, default: false)
20051990
recursive := false
2006-
if recursiveParam, ok := request.Params.Arguments["recursive"]; ok {
2007-
if r, ok := recursiveParam.(bool); ok {
2008-
recursive = r
2009-
}
1991+
if recursiveParam, err := request.RequireBool("recursive"); err != nil {
1992+
recursive = recursiveParam
20101993
}
20111994

20121995
// Check if it's a directory and handle accordingly

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.2
44

55
require (
66
github.com/gabriel-vasile/mimetype v1.4.3
7-
github.com/mark3labs/mcp-go v0.26.0
7+
github.com/mark3labs/mcp-go v0.29.0
88
github.com/stretchr/testify v1.9.0
99
)
1010

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1212
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1313
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1414
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
15-
github.com/mark3labs/mcp-go v0.26.0 h1:xz/Kv1cHLYovF8txv6btBM39/88q3YOjnxqhi51jB0w=
16-
github.com/mark3labs/mcp-go v0.26.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
15+
github.com/mark3labs/mcp-go v0.29.0 h1:sH1NBcumKskhxqYzhXfGc201D7P76TVXiT0fGVhabeI=
16+
github.com/mark3labs/mcp-go v0.29.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
1717
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1818
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1919
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=

0 commit comments

Comments
 (0)