Skip to content

Add missing items property to schema of read_multiple_files tool #23

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
37 changes: 3 additions & 34 deletions filesystemserver/inprocess_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package filesystemserver_test

import (
"context"
"testing"

"github.com/mark3labs/mcp-filesystem-server/filesystemserver"
"github.com/mark3labs/mcp-go/client"
"github.com/mark3labs/mcp-go/mcp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,37 +12,9 @@ func TestInProcess(t *testing.T) {
fss, err := filesystemserver.NewFilesystemServer([]string{"."})
require.NoError(t, err)

mcpClient, err := client.NewInProcessClient(fss)
require.NoError(t, err)

err = mcpClient.Start(context.Background())
require.NoError(t, err)

// Initialize the client
initRequest := mcp.InitializeRequest{}
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
initRequest.Params.ClientInfo = mcp.Implementation{
Name: "test-client",
Version: "1.0.0",
}
result, err := mcpClient.Initialize(context.Background(), initRequest)
require.NoError(t, err)
assert.Equal(t, "secure-filesystem-server", result.ServerInfo.Name)
assert.Equal(t, filesystemserver.Version, result.ServerInfo.Version)
mcpClient := startTestClient(t, fss)

// just check for a specific tool
toolListResult, err := mcpClient.ListTools(context.Background(), mcp.ListToolsRequest{})
require.NoError(t, err)
assert.NotEmpty(t, toolListResult.Tools)
found := false
for _, tool := range toolListResult.Tools {
if tool.Name == "read_file" {
found = true
break
}
}
assert.True(t, found, "read_file tool not found in the list of tools")

err = mcpClient.Close()
require.NoError(t, err)
tool := getTool(t, mcpClient, "read_file")
assert.NotNil(t, tool, "read_file tool not found in the list of tools")
}
1 change: 1 addition & 0 deletions filesystemserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func NewFilesystemServer(allowedDirs []string) (*server.MCPServer, error) {
mcp.WithArray("paths",
mcp.Description("List of file paths to read"),
mcp.Required(),
mcp.Items(map[string]any{"type": "string"}),
),
), h.handleReadMultipleFiles)

Expand Down
28 changes: 28 additions & 0 deletions filesystemserver/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package filesystemserver_test

import (
"testing"

"github.com/mark3labs/mcp-filesystem-server/filesystemserver"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// regression test for invalid schema => missing items in array definition
func TestReadMultipleFilesSchema(t *testing.T) {
fsserver, err := filesystemserver.NewFilesystemServer([]string{t.TempDir()})
require.NoError(t, err)

mcpClient := startTestClient(t, fsserver)

tool := getTool(t, mcpClient, "read_multiple_files")
require.NotNil(t, tool)

// make sure that the tool has the correct schema
paths, ok := tool.InputSchema.Properties["paths"]
assert.True(t, ok)
pathsMap, ok := paths.(map[string]any)
assert.True(t, ok)
_, ok = pathsMap["items"]
assert.True(t, ok)
}
51 changes: 51 additions & 0 deletions filesystemserver/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package filesystemserver_test

import (
"context"
"testing"

"github.com/mark3labs/mcp-filesystem-server/filesystemserver"
"github.com/mark3labs/mcp-go/client"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func startTestClient(t *testing.T, fss *server.MCPServer) client.MCPClient {
t.Helper()

mcpClient, err := client.NewInProcessClient(fss)
require.NoError(t, err)
t.Cleanup(func() { mcpClient.Close() })

err = mcpClient.Start(context.Background())
require.NoError(t, err)

// Initialize the client
initRequest := mcp.InitializeRequest{}
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
initRequest.Params.ClientInfo = mcp.Implementation{
Name: "test-client",
Version: "1.0.0",
}
result, err := mcpClient.Initialize(context.Background(), initRequest)
require.NoError(t, err)
assert.Equal(t, "secure-filesystem-server", result.ServerInfo.Name)
assert.Equal(t, filesystemserver.Version, result.ServerInfo.Version)

return mcpClient
}

func getTool(t *testing.T, mcpClient client.MCPClient, toolName string) *mcp.Tool {
result, err := mcpClient.ListTools(context.Background(), mcp.ListToolsRequest{})
require.NoError(t, err)
for _, tool := range result.Tools {
if tool.Name == toolName {
return &tool
}
}
require.Fail(t, "Tool not found", toolName)
return nil
}