Documentation
¶
Overview ¶
Package mcp implements the Model, Channel, Prompt (MCP) protocol services
Package mcp implements the Model, Channel, Prompt (MCP) protocol services
Index ¶
- func BoolPtr(b bool) *bool
- func NewApplyResourceTool() mcp.Tool
- func NewClusteredResourceTemplate() mcp.ResourceTemplate
- func NewDeleteResourceTool() mcp.Tool
- func NewGetResourceTool() mcp.Tool
- func NewListResourcesTool() mcp.Tool
- func NewNamespacedResourceTemplate() mcp.ResourceTemplate
- func NewPostResourceTool() mcp.Tool
- func WithTimeoutContext(timeout time.Duration) server.ServerOption
- type Config
- type Implementation
- func (m *Implementation) HandleApplyResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (m *Implementation) HandleClusteredResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
- func (m *Implementation) HandleDeleteResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (m *Implementation) HandleGetResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (m *Implementation) HandleListAllResources(ctx context.Context) ([]mcp.Resource, error)
- func (m *Implementation) HandleListResources(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (m *Implementation) HandleNamespacedResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
- func (m *Implementation) HandlePostResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- type ResourceURIComponents
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewApplyResourceTool ¶
NewApplyResourceTool creates a new apply_resource tool
func NewClusteredResourceTemplate ¶
func NewClusteredResourceTemplate() mcp.ResourceTemplate
NewClusteredResourceTemplate creates a new clustered resource template
func NewDeleteResourceTool ¶ added in v0.0.7
NewDeleteResourceTool creates a new delete_resource tool
func NewGetResourceTool ¶ added in v0.0.3
NewGetResourceTool creates a new get_resource tool
func NewListResourcesTool ¶
NewListResourcesTool creates a new list_resources tool
func NewNamespacedResourceTemplate ¶
func NewNamespacedResourceTemplate() mcp.ResourceTemplate
NewNamespacedResourceTemplate creates a new namespaced resource template
func NewPostResourceTool ¶ added in v0.0.8
NewPostResourceTool creates a new post_resource tool
func WithTimeoutContext ¶ added in v0.0.8
func WithTimeoutContext(timeout time.Duration) server.ServerOption
WithTimeoutContext adds a timeout context to all tool handlers This helps prevent context cancellation errors from the k8s client
Types ¶
type Config ¶ added in v0.0.4
type Config struct {
// ServeResources determines whether to serve cluster resources
// Setting this to false can reduce context size for LLMs when working with large clusters
ServeResources bool
// ReadWrite determines whether the MCP server can modify resources in the cluster
// When false, the server operates in read-only mode and does not serve the apply_resource tool
ReadWrite bool
// EnableRateLimiting determines whether to enable rate limiting for tool calls
// When true, a default rate limiter will be used to prevent excessive API calls
EnableRateLimiting bool
// EnableImpersonation determines whether to enable Kubernetes API impersonation
// based on authenticated user identity from the Authorization header JWT.
// When true, each K8s API call will impersonate the authenticated user.
// When false, all requests use the server's own identity (backward compatible).
EnableImpersonation bool
// ImpersonationUserClaim is the JWT claim to use for the Impersonate-User header.
// Defaults to "email" if empty.
ImpersonationUserClaim string
// ImpersonationGroupsClaim is the JWT claim to use for the Impersonate-Group headers.
// Defaults to "groups" if empty.
ImpersonationGroupsClaim string
// ImpersonationJWKSURL is an optional URL to a JWKS endpoint for JWT
// signature validation. When set, JWTs are validated against the keys
// from this endpoint (signature + expiration). When empty, JWTs are
// parsed without validation (trusted proxy mode).
ImpersonationJWKSURL string
// ImpersonationJWTIssuer is the expected JWT issuer (iss claim).
// Only used when ImpersonationJWKSURL is set. Prevents token replay
// from different issuers sharing the same IdP keys.
ImpersonationJWTIssuer string
// ImpersonationJWTAudience is the expected JWT audience (aud claim).
// Only used when ImpersonationJWKSURL is set. Per OIDC Core Section
// 3.1.3.7, relying parties must validate the audience.
ImpersonationJWTAudience string
}
Config holds configuration options for the MCP server
func DefaultConfig ¶ added in v0.0.4
func DefaultConfig() *Config
DefaultConfig returns a Config with default values
type Implementation ¶
type Implementation struct {
// contains filtered or unexported fields
}
Implementation implements the MCP protocol
func NewImplementation ¶
func NewImplementation(k8sClient *k8s.Client) *Implementation
NewImplementation creates a new MCP implementation
func NewImplementationWithImpersonation ¶ added in v0.4.0
func NewImplementationWithImpersonation(k8sClient *k8s.Client) *Implementation
NewImplementationWithImpersonation creates a new MCP implementation with Kubernetes impersonation enabled. When enabled, each request must carry an authenticated identity in its context; requests without identity are rejected.
func (*Implementation) HandleApplyResource ¶
func (m *Implementation) HandleApplyResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
HandleApplyResource handles the apply_resource tool
func (*Implementation) HandleClusteredResource ¶
func (m *Implementation) HandleClusteredResource( ctx context.Context, request mcp.ReadResourceRequest, ) ([]mcp.ResourceContents, error)
HandleClusteredResource handles the clustered resource template
func (*Implementation) HandleDeleteResource ¶ added in v0.0.7
func (m *Implementation) HandleDeleteResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
HandleDeleteResource handles the delete_resource tool
func (*Implementation) HandleGetResource ¶ added in v0.0.3
func (m *Implementation) HandleGetResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
HandleGetResource handles the get_resource tool
func (*Implementation) HandleListAllResources ¶
HandleListAllResources handles the listResources request. This always uses the base client (not impersonated) because it runs at server startup to populate MCP resource metadata, not in a per-user request context.
func (*Implementation) HandleListResources ¶
func (m *Implementation) HandleListResources(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
HandleListResources handles the list_resources tool Parameters:
- resource_type: Type of the resource ("clustered" or "namespaced")
- group: API group of the resource
- version: API version of the resource
- resource: Resource type (e.g., "pods", "services")
- namespace: Namespace for namespaced resources
- label_selector: Kubernetes label selector for filtering resources (optional) Label selector format: "key1=value1,key2=value2" for equality or "key1 in (value1, value2),!key3" for set-based
func (*Implementation) HandleNamespacedResource ¶
func (m *Implementation) HandleNamespacedResource( ctx context.Context, request mcp.ReadResourceRequest, ) ([]mcp.ResourceContents, error)
HandleNamespacedResource handles the namespaced resource template
func (*Implementation) HandlePostResource ¶ added in v0.0.8
func (m *Implementation) HandlePostResource(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
HandlePostResource handles the post_resource tool
type ResourceURIComponents ¶
type ResourceURIComponents struct {
Group string
Version string
Resource string
Name string
Namespace string // Only for namespaced resources
}
ResourceURIComponents represents the components of a Kubernetes resource URI
type Server ¶ added in v0.4.0
type Server struct {
// contains filtered or unexported fields
}
Server wraps the MCP server and owns all resources that need cleanup. Use Stop() to release background goroutines and other resources.
func CreateServer ¶
CreateServer creates a new MCP server for Kubernetes and returns a Server handle that owns all associated resources. Call Stop() on the returned Server to clean up.
func (*Server) CreateSSEServer ¶ added in v0.4.0
CreateSSEServer creates a new SSE server for the MCP server. When impersonation is enabled, it registers an HTTP context function that extracts identity from the Authorization header JWT.
func (*Server) CreateStreamableHTTPServer ¶ added in v0.4.0
func (s *Server) CreateStreamableHTTPServer( ctx context.Context, ) (*server.StreamableHTTPServer, error)
CreateStreamableHTTPServer creates a new StreamableHTTP server for the MCP server. When impersonation is enabled, it registers an HTTP context function that extracts identity from the Authorization header JWT.