Skip to content
Draft
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
go.opentelemetry.io/otel/trace v1.40.0
golang.org/x/oauth2 v0.35.0
golang.org/x/sync v0.19.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.20.0
k8s.io/api v0.35.1
k8s.io/apiextensions-apiserver v0.35.1
Expand Down Expand Up @@ -148,7 +149,6 @@ require (
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.35.1 // indirect
k8s.io/component-base v0.35.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
Expand Down
1 change: 1 addition & 0 deletions internal/tools/update-readme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kcp"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kiali"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kubevirt"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/mustgather"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/observability"
)

Expand Down
11 changes: 10 additions & 1 deletion pkg/api/toolsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ func NewToolCallResultStructured(structured any, err error) *ToolCallResult {
}
}

// ResourceRegistrar allows tools to register MCP resources at runtime.
// For example, the mustgather_use tool registers a must-gather:// resource
// after loading an archive.
type ResourceRegistrar interface {
AddResource(uri, name, description, mimeType, content string)
RemoveResources(uris ...string)
}

type ToolHandlerParams struct {
context.Context
ExtendedConfigProvider
KubernetesClient
ToolCallRequest
ListOutput output.Output
ListOutput output.Output
ResourceRegistrar ResourceRegistrar
}

type ToolHandlerFunc func(params ToolHandlerParams) (*ToolCallResult, error)
Expand Down
22 changes: 22 additions & 0 deletions pkg/mcp/gosdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ import (
"k8s.io/utils/ptr"
)

// resourceRegistrar adapts the MCP go-sdk Server for the api.ResourceRegistrar interface
type resourceRegistrar struct {
server *mcp.Server
}

func (r *resourceRegistrar) AddResource(uri, name, description, mimeType, content string) {
resourceContent := content // capture for closure
r.server.AddResource(
&mcp.Resource{URI: uri, Name: name, Description: description, MIMEType: mimeType},
func(_ context.Context, _ *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
return &mcp.ReadResourceResult{
Contents: []*mcp.ResourceContents{{URI: uri, Text: resourceContent}},
}, nil
},
)
}

func (r *resourceRegistrar) RemoveResources(uris ...string) {
r.server.RemoveResources(uris...)
}

func ServerToolToGoSdkTool(s *Server, tool api.ServerTool) (*mcp.Tool, mcp.ToolHandler, error) {
// Ensure InputSchema.Properties is initialized for OpenAI API compatibility
// https://github.com/containers/kubernetes-mcp-server/issues/717
Expand Down Expand Up @@ -52,6 +73,7 @@ func ServerToolToGoSdkTool(s *Server, tool api.ServerTool) (*mcp.Tool, mcp.ToolH
KubernetesClient: k,
ToolCallRequest: toolCallRequest,
ListOutput: s.configuration.ListOutput(),
ResourceRegistrar: &resourceRegistrar{server: s.server},
})
if err != nil {
return nil, err
Expand Down
7 changes: 3 additions & 4 deletions pkg/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ func NewServer(configuration Configuration, targetProvider internalk8s.Provider)
},
&mcp.ServerOptions{
Capabilities: &mcp.ServerCapabilities{
Resources: nil,
Prompts: &mcp.PromptCapabilities{ListChanged: !configuration.Stateless},
Tools: &mcp.ToolCapabilities{ListChanged: !configuration.Stateless},
Logging: &mcp.LoggingCapabilities{},
Prompts: &mcp.PromptCapabilities{ListChanged: !configuration.Stateless},
Tools: &mcp.ToolCapabilities{ListChanged: !configuration.Stateless},
Logging: &mcp.LoggingCapabilities{},
},
Instructions: configuration.ServerInstructions,
}),
Expand Down
1 change: 1 addition & 0 deletions pkg/mcp/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kcp"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kiali"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kubevirt"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/mustgather"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/netedge"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/observability"
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/openshift"
Expand Down
Loading