mcp

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package mcp implements the Model, Channel, Prompt (MCP) protocol services

Package mcp implements the Model, Channel, Prompt (MCP) protocol services

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr added in v0.0.8

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given bool value

func CreateSSEServer

func CreateSSEServer(mcpServer *server.MCPServer) *server.SSEServer

CreateSSEServer creates a new SSE server for the MCP server

func CreateServer

func CreateServer(k8sClient *k8s.Client, config *Config) *server.MCPServer

CreateServer creates a new MCP server for Kubernetes

func NewApplyResourceTool

func NewApplyResourceTool() mcp.Tool

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

func NewDeleteResourceTool() mcp.Tool

NewDeleteResourceTool creates a new delete_resource tool

func NewGetResourceTool added in v0.0.3

func NewGetResourceTool() mcp.Tool

NewGetResourceTool creates a new get_resource tool

func NewListResourcesTool

func NewListResourcesTool() mcp.Tool

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

func NewPostResourceTool() mcp.Tool

NewPostResourceTool creates a new post_resource tool

func StopServer added in v0.0.8

func StopServer()

StopServer stops the MCP server and cleans up resources

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
}

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 (*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

func (m *Implementation) HandleListAllResources(ctx context.Context) ([]mcp.Resource, error)

HandleListAllResources handles the listResources request

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL