From c69e90c70dca03fee3b910c2a3580a1187a2e470 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 25 Sep 2025 11:54:07 +0200 Subject: [PATCH] fix(mcp): InputSchema schema with empty properties for no-arg tools (#341) Signed-off-by: Marc Nuri --- pkg/mcp/m3labs.go | 6 ++++++ pkg/mcp/toolsets_test.go | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/mcp/m3labs.go b/pkg/mcp/m3labs.go index 999d8e2..4531c54 100644 --- a/pkg/mcp/m3labs.go +++ b/pkg/mcp/m3labs.go @@ -30,6 +30,12 @@ func ServerToolToM3LabsServerTool(s *Server, tools []api.ServerTool) ([]server.S if err != nil { return nil, fmt.Errorf("failed to marshal tool input schema for tool %s: %v", tool.Tool.Name, err) } + // TODO: temporary fix to append an empty properties object (some client have trouble parsing a schema without properties) + // As opposed, Gemini had trouble for a while when properties was present but empty. + // https://github.com/containers/kubernetes-mcp-server/issues/340 + if string(schema) == `{"type":"object"}` { + schema = []byte(`{"type":"object","properties":{}}`) + } m3labTool.RawInputSchema = schema } m3labHandler := func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { diff --git a/pkg/mcp/toolsets_test.go b/pkg/mcp/toolsets_test.go index a8a1ef3..5f9668a 100644 --- a/pkg/mcp/toolsets_test.go +++ b/pkg/mcp/toolsets_test.go @@ -125,6 +125,28 @@ func (s *ToolsetsSuite) TestGranularToolsetsTools() { } } +func (s *ToolsetsSuite) TestInputSchemaEdgeCases() { + //https://github.com/containers/kubernetes-mcp-server/issues/340 + s.Run("InputSchema for no-arg tool is object with empty properties", func() { + s.InitMcpClient() + tools, err := s.ListTools(s.T().Context(), mcp.ListToolsRequest{}) + s.Run("ListTools returns tools", func() { + s.NotNil(tools, "Expected tools from ListTools") + s.NoError(err, "Expected no error from ListTools") + }) + var namespacesList *mcp.Tool + for _, tool := range tools.Tools { + if tool.Name == "namespaces_list" { + namespacesList = &tool + break + } + } + s.Require().NotNil(namespacesList, "Expected namespaces_list from ListTools") + s.NotNil(namespacesList.InputSchema.Properties, "Expected namespaces_list.InputSchema.Properties not to be nil") + s.Empty(namespacesList.InputSchema.Properties, "Expected namespaces_list.InputSchema.Properties to be empty") + }) +} + func (s *ToolsetsSuite) InitMcpClient() { var err error s.mcpServer, err = NewServer(Configuration{StaticConfig: s.Cfg})