Skip to content

Fix tool schema compatibility with OpenAI models#847

Open
edcdavid wants to merge 1 commit intocontainers:mainfrom
edcdavid:openai-fix-upstream
Open

Fix tool schema compatibility with OpenAI models#847
edcdavid wants to merge 1 commit intocontainers:mainfrom
edcdavid:openai-fix-upstream

Conversation

@edcdavid
Copy link

OpenAI models require the "properties" field to be present in the JSON schema for tool input, even when a tool takes no parameters. Add an empty properties map to the configuration_contexts_list and targets_list tool schemas to ensure compatibility.

Assisted by: Cursor

OpenAI models require the "properties" field to be present in the JSON
schema for tool input, even when a tool takes no parameters. Add an
empty properties map to the configuration_contexts_list and targets_list
tool schemas to ensure compatibility.

Assisted by: Cursor
Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @edcdavid, thx for getting involved.
This is not a proper fix.
The toolset definition gets transformed in a latter stage at the MCP domain layer, so whatever you change here, doesn't mean that it will be sent to the MCP client and host.

This issue (#717) was already fixed, first in this repository, and later in the go-sdk directly.

We have specific tests to ensure that this is the case:

// https://github.com/containers/kubernetes-mcp-server/issues/717
// Verifies ALL tools have Properties initialized (not just cluster-aware ones)
// OpenAI API requires properties field even if empty
s.Run("InputSchema has properties for all tools regardless of cluster-awareness", func() {
// Register all toolsets including kcp to catch kcp_workspaces_list
toolsets.Clear()
toolsets.Register(&core.Toolset{})
toolsets.Register(&config.Toolset{})
toolsets.Register(&helm.Toolset{})
toolsets.Register(&kcp.Toolset{})
s.Cfg.Toolsets = []string{"core", "config", "helm", "kcp"}
// Enable multi-cluster mode to include configuration_contexts_list tool
kubeconfig := s.Kubeconfig()
kubeconfig.Contexts["extra-cluster"] = clientcmdapi.NewContext()
s.Cfg.KubeConfig = test.KubeconfigFile(s.T(), kubeconfig)
s.InitMcpClient()
tools, err := s.ListTools()
s.Require().NoError(err, "Expected no error from ListTools")
s.Require().NotNil(tools, "Expected tools from ListTools")
s.Require().NotEmpty(tools.Tools, "Expected at least one tool")
// Check each tool has InputSchema.properties initialized
for _, tool := range tools.Tools {
s.Run(tool.Name, func() {
schema, ok := tool.InputSchema.(map[string]any)
s.Require().True(ok, "Expected InputSchema to be map[string]any for tool %s", tool.Name)
s.Require().NotNil(schema["properties"],
"Expected InputSchema.properties not to be nil for tool %s (required by OpenAI API)",
tool.Name)
})
}
})

Are you using the latest version of the server.

If you are, and are still facing the issue, try to provide a reproducer first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants