Skip to content

Commit c69e90c

Browse files
authored
fix(mcp): InputSchema schema with empty properties for no-arg tools (#341)
Signed-off-by: Marc Nuri <[email protected]>
1 parent 053fb2e commit c69e90c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/mcp/m3labs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ func ServerToolToM3LabsServerTool(s *Server, tools []api.ServerTool) ([]server.S
3030
if err != nil {
3131
return nil, fmt.Errorf("failed to marshal tool input schema for tool %s: %v", tool.Tool.Name, err)
3232
}
33+
// TODO: temporary fix to append an empty properties object (some client have trouble parsing a schema without properties)
34+
// As opposed, Gemini had trouble for a while when properties was present but empty.
35+
// https://github.com/containers/kubernetes-mcp-server/issues/340
36+
if string(schema) == `{"type":"object"}` {
37+
schema = []byte(`{"type":"object","properties":{}}`)
38+
}
3339
m3labTool.RawInputSchema = schema
3440
}
3541
m3labHandler := func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {

pkg/mcp/toolsets_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ func (s *ToolsetsSuite) TestGranularToolsetsTools() {
125125
}
126126
}
127127

128+
func (s *ToolsetsSuite) TestInputSchemaEdgeCases() {
129+
//https://github.com/containers/kubernetes-mcp-server/issues/340
130+
s.Run("InputSchema for no-arg tool is object with empty properties", func() {
131+
s.InitMcpClient()
132+
tools, err := s.ListTools(s.T().Context(), mcp.ListToolsRequest{})
133+
s.Run("ListTools returns tools", func() {
134+
s.NotNil(tools, "Expected tools from ListTools")
135+
s.NoError(err, "Expected no error from ListTools")
136+
})
137+
var namespacesList *mcp.Tool
138+
for _, tool := range tools.Tools {
139+
if tool.Name == "namespaces_list" {
140+
namespacesList = &tool
141+
break
142+
}
143+
}
144+
s.Require().NotNil(namespacesList, "Expected namespaces_list from ListTools")
145+
s.NotNil(namespacesList.InputSchema.Properties, "Expected namespaces_list.InputSchema.Properties not to be nil")
146+
s.Empty(namespacesList.InputSchema.Properties, "Expected namespaces_list.InputSchema.Properties to be empty")
147+
})
148+
}
149+
128150
func (s *ToolsetsSuite) InitMcpClient() {
129151
var err error
130152
s.mcpServer, err = NewServer(Configuration{StaticConfig: s.Cfg})

0 commit comments

Comments
 (0)