Documentation
¶
Overview ¶
Package mcpserver implements the MCP server functionality.
Index ¶
- Variables
- func RegisterSkillResources(rm resource.ManagerInterface, sm *skill.Manager) error
- type LazyLogResult
- type LazyRedact
- type MCPSession
- type MethodHandler
- type NoOpPromptManager
- func (m *NoOpPromptManager) AddPrompt(_ prompt.Prompt)
- func (m *NoOpPromptManager) ClearPromptsForService(_ string)
- func (m *NoOpPromptManager) GetPrompt(_ string) (prompt.Prompt, bool)
- func (m *NoOpPromptManager) ListPrompts() []prompt.Prompt
- func (m *NoOpPromptManager) SetMCPServer(_ prompt.MCPServerProvider)
- func (m *NoOpPromptManager) UpdatePrompt(_ prompt.Prompt)
- type NoOpResourceManager
- func (m *NoOpResourceManager) AddResource(_ resource.Resource)
- func (m *NoOpResourceManager) ClearResourcesForService(_ string)
- func (m *NoOpResourceManager) GetResource(_ string) (resource.Resource, bool)
- func (m *NoOpResourceManager) ListResources() []resource.Resource
- func (m *NoOpResourceManager) OnListChanged(_ func())
- func (m *NoOpResourceManager) RemoveResource(_ string)
- type NoOpToolManager
- func (m *NoOpToolManager) AddMiddleware(_ tool.ExecutionMiddleware)
- func (m *NoOpToolManager) AddServiceInfo(_ string, _ *tool.ServiceInfo)
- func (m *NoOpToolManager) AddTool(_ tool.Tool) error
- func (m *NoOpToolManager) ClearToolsForService(_ string)
- func (m *NoOpToolManager) ExecuteTool(_ context.Context, _ *tool.ExecutionRequest) (any, error)
- func (m *NoOpToolManager) GetAllowedServiceIDs(_ string) (map[string]bool, bool)
- func (m *NoOpToolManager) GetServiceInfo(_ string) (*tool.ServiceInfo, bool)
- func (m *NoOpToolManager) GetTool(_ string) (tool.Tool, bool)
- func (m *NoOpToolManager) GetToolCountForService(_ string) int
- func (m *NoOpToolManager) IsServiceAllowed(_, _ string) bool
- func (m *NoOpToolManager) ListMCPTools() []*mcp.Tool
- func (m *NoOpToolManager) ListServices() []*tool.ServiceInfo
- func (m *NoOpToolManager) ListTools() []tool.Tool
- func (m *NoOpToolManager) SetMCPServer(_ tool.MCPServerProvider)
- func (m *NoOpToolManager) SetProfiles(_ []string, _ []*configv1.ProfileDefinition)
- func (m *NoOpToolManager) ToolMatchesProfile(_ tool.Tool, _ string) bool
- type RegistrationServer
- func (s *RegistrationServer) GetService(ctx context.Context, req *v1.GetServiceRequest) (*v1.GetServiceResponse, error)
- func (s *RegistrationServer) GetServiceStatus(_ context.Context, _ *v1.GetServiceStatusRequest) (*v1.GetServiceStatusResponse, error)
- func (s *RegistrationServer) InitiateOAuth2Flow(ctx context.Context, req *v1.InitiateOAuth2FlowRequest) (*v1.InitiateOAuth2FlowResponse, error)
- func (s *RegistrationServer) ListServices(ctx context.Context, _ *v1.ListServicesRequest) (*v1.ListServicesResponse, error)
- func (s *RegistrationServer) RegisterService(ctx context.Context, req *v1.RegisterServiceRequest) (*v1.RegisterServiceResponse, error)
- func (s *RegistrationServer) RegisterTools(_ context.Context, _ *v1.RegisterToolsRequest) (*v1.RegisterToolsResponse, error)
- func (s *RegistrationServer) UnregisterService(_ context.Context, _ *v1.UnregisterServiceRequest) (*v1.UnregisterServiceResponse, error)
- func (s *RegistrationServer) ValidateService(ctx context.Context, req *v1.ValidateServiceRequest) (*v1.ValidateServiceResponse, error)
- type RootsTool
- type Router
- type Server
- func (s *Server) AddServiceInfo(serviceID string, info *tool.ServiceInfo)
- func (s *Server) AddTool(t tool.Tool) error
- func (s *Server) AuthManager() *auth.Manager
- func (s *Server) CallTool(ctx context.Context, req *tool.ExecutionRequest) (any, error)
- func (s *Server) ClearToolsForService(serviceKey string)
- func (s *Server) CreateMessage(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
- func (s *Server) GetPrompt(ctx context.Context, req *mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (s *Server) GetServiceInfo(serviceID string) (*tool.ServiceInfo, bool)
- func (s *Server) GetTool(toolName string) (tool.Tool, bool)
- func (s *Server) ListPrompts(_ context.Context, _ *mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (s *Server) ListResources(_ context.Context, _ *mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (s *Server) ListTools() []tool.Tool
- func (s *Server) PromptManager() prompt.ManagerInterface
- func (s *Server) ReadResource(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- func (s *Server) Reload(ctx context.Context) error
- func (s *Server) ResourceManager() resource.ManagerInterface
- func (s *Server) Server() *mcp.Server
- func (s *Server) ServiceRegistry() *serviceregistry.ServiceRegistry
- func (s *Server) SetMCPServer(mcpServer tool.MCPServerProvider)
- func (s *Server) SetReloadFunc(f func(context.Context) error)
- func (s *Server) ToolManager() tool.ManagerInterface
- type SkillResource
- func (r *SkillResource) Name() string
- func (r *SkillResource) Read(_ context.Context) (*mcp.ReadResourceResult, error)
- func (r *SkillResource) Resource() *mcp.Resource
- func (r *SkillResource) Service() string
- func (r *SkillResource) Subscribe(_ context.Context) error
- func (r *SkillResource) URI() string
- type TemporaryToolManager
Constants ¶
This section is empty.
Variables ¶
var AddReceivingMiddlewareHook func(name string)
AddReceivingMiddlewareHook is a testing hook that allows inspection of the middleware chain. It is invoked when the Server method is called, allowing tests to verify which middlewares are present.
Side Effects:
- When set, this function is called synchronously during Server() access.
var NewRegistrationServerHook func(bus interface{}, authManager interface{}) (*RegistrationServer, error)
NewRegistrationServerHook is a test hook for overriding the creation of a RegistrationServer.
Summary: Test hook to override RegistrationServer creation.
Side Effects:
- If set, this hook is called instead of the standard constructor logic.
Functions ¶
func RegisterSkillResources ¶
func RegisterSkillResources(rm resource.ManagerInterface, sm *skill.Manager) error
RegisterSkillResources registers all skills from the manager into the resource manager.
It iterates through all available skills and registers their documentation (SKILL.md) and associated assets as resources in the provided Resource Manager.
Parameters:
- rm: resource.ManagerInterface. The resource manager to register resources with.
- sm: *skill.Manager. The skill manager to retrieve skills from.
Returns:
- error: An error if listing skills fails.
Types ¶
type LazyLogResult ¶
type LazyLogResult struct {
Value any
}
LazyLogResult wraps a tool execution result for efficient logging. It avoids expensive serialization of large payloads (e.g. images, huge text) and lazily computes the string representation only when logging is enabled.
func (LazyLogResult) LogValue ¶
func (r LazyLogResult) LogValue() slog.Value
LogValue implements slog.LogValuer.
type LazyRedact ¶
type LazyRedact []byte
LazyRedact is a byte slice that implements slog.LogValuer to lazily redact its JSON content only when logged.
func (LazyRedact) LogValue ¶
func (l LazyRedact) LogValue() slog.Value
LogValue implements slog.LogValuer.
type MCPSession ¶
type MCPSession struct {
// contains filtered or unexported fields
}
MCPSession wraps an MCP session to provide client interaction capabilities like sampling and roots.
Summary: Provides a wrapper around the MCP server session to facilitate client interactions.
func NewMCPSampler ¶
func NewMCPSampler(session *mcp.ServerSession) *MCPSession
NewMCPSampler is a deprecated alias for NewMCPSession.
Summary: Creates a new MCPSession (deprecated alias).
Parameters:
- session: *mcp.ServerSession. The underlying MCP server session.
Returns:
- *MCPSession: A new instance of MCPSession.
Side Effects:
- This function is deprecated and should be replaced by NewMCPSession.
func NewMCPSession ¶
func NewMCPSession(session *mcp.ServerSession) *MCPSession
NewMCPSession creates a new MCPSession.
Summary: Initializes a new MCPSession instance.
Parameters:
- session: *mcp.ServerSession. The underlying MCP server session.
Returns:
- *MCPSession: A new instance of MCPSession.
func (*MCPSession) CreateMessage ¶
func (s *MCPSession) CreateMessage(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
CreateMessage requests a message creation from the client (sampling).
Summary: Requests the client to create a message, effectively sampling the LLM.
Parameters:
- ctx: context.Context. The context for the request.
- params: *mcp.CreateMessageParams. The parameters for the message creation request.
Returns:
- *mcp.CreateMessageResult: The result of the message creation from the client.
- error: An error if no active session is available or if the request fails.
Throws/Errors:
- Returns an error if the session is nil.
func (*MCPSession) ListRoots ¶
func (s *MCPSession) ListRoots(ctx context.Context) (*mcp.ListRootsResult, error)
ListRoots requests the list of roots from the client.
Summary: Requests the list of root directories from the client.
Parameters:
- ctx: context.Context. The context for the request.
Returns:
- *mcp.ListRootsResult: The list of roots returned by the client.
- error: An error if no active session is available or if the request fails.
Throws/Errors:
- Returns an error if the session is nil.
type MethodHandler ¶
MethodHandler defines the signature for a function that handles an MCP method call.
Parameters:
- ctx: context.Context. The context for the request.
- req: mcp.Request. The request object.
Returns:
- mcp.Result: The result of the operation.
- error: An error if the operation fails.
type NoOpPromptManager ¶
type NoOpPromptManager struct{}
NoOpPromptManager is a no-op implementation of prompt.ManagerInterface.
func (*NoOpPromptManager) AddPrompt ¶
func (m *NoOpPromptManager) AddPrompt(_ prompt.Prompt)
AddPrompt implements prompt.ManagerInterface.
_ is an unused parameter.
func (*NoOpPromptManager) ClearPromptsForService ¶
func (m *NoOpPromptManager) ClearPromptsForService(_ string)
ClearPromptsForService implements prompt.ManagerInterface.
_ is an unused parameter.
func (*NoOpPromptManager) GetPrompt ¶
func (m *NoOpPromptManager) GetPrompt(_ string) (prompt.Prompt, bool)
GetPrompt implements prompt.ManagerInterface.
_ is an unused parameter.
Returns the result. Returns true if successful.
func (*NoOpPromptManager) ListPrompts ¶
func (m *NoOpPromptManager) ListPrompts() []prompt.Prompt
ListPrompts implements prompt.ManagerInterface.
Returns the result.
func (*NoOpPromptManager) SetMCPServer ¶
func (m *NoOpPromptManager) SetMCPServer(_ prompt.MCPServerProvider)
SetMCPServer implements prompt.ManagerInterface.
_ is an unused parameter.
func (*NoOpPromptManager) UpdatePrompt ¶
func (m *NoOpPromptManager) UpdatePrompt(_ prompt.Prompt)
UpdatePrompt implements prompt.ManagerInterface.
_ is an unused parameter.
type NoOpResourceManager ¶
type NoOpResourceManager struct{}
NoOpResourceManager is a no-op implementation of resource.ManagerInterface.
func (*NoOpResourceManager) AddResource ¶
func (m *NoOpResourceManager) AddResource(_ resource.Resource)
AddResource implements resource.ManagerInterface.
_ is an unused parameter.
func (*NoOpResourceManager) ClearResourcesForService ¶
func (m *NoOpResourceManager) ClearResourcesForService(_ string)
ClearResourcesForService implements resource.ManagerInterface.
_ is an unused parameter.
func (*NoOpResourceManager) GetResource ¶
func (m *NoOpResourceManager) GetResource(_ string) (resource.Resource, bool)
GetResource implements resource.ManagerInterface.
_ is an unused parameter.
Returns the result. Returns true if successful.
func (*NoOpResourceManager) ListResources ¶
func (m *NoOpResourceManager) ListResources() []resource.Resource
ListResources implements resource.ManagerInterface.
Returns the result.
func (*NoOpResourceManager) OnListChanged ¶
func (m *NoOpResourceManager) OnListChanged(_ func())
OnListChanged implements resource.ManagerInterface.
_ is an unused parameter.
func (*NoOpResourceManager) RemoveResource ¶
func (m *NoOpResourceManager) RemoveResource(_ string)
RemoveResource implements resource.ManagerInterface.
_ is an unused parameter.
type NoOpToolManager ¶
type NoOpToolManager struct{}
NoOpToolManager is a no-op implementation of tool.ManagerInterface.
func (*NoOpToolManager) AddMiddleware ¶
func (m *NoOpToolManager) AddMiddleware(_ tool.ExecutionMiddleware)
AddMiddleware implements tool.ManagerInterface.
_ is an unused parameter.
func (*NoOpToolManager) AddServiceInfo ¶
func (m *NoOpToolManager) AddServiceInfo(_ string, _ *tool.ServiceInfo)
AddServiceInfo implements tool.ManagerInterface.
_ is an unused parameter. _ is an unused parameter.
func (*NoOpToolManager) AddTool ¶
func (m *NoOpToolManager) AddTool(_ tool.Tool) error
AddTool implements tool.ManagerInterface.
_ is an unused parameter.
Returns an error if the operation fails.
func (*NoOpToolManager) ClearToolsForService ¶
func (m *NoOpToolManager) ClearToolsForService(_ string)
ClearToolsForService implements tool.ManagerInterface.
_ is an unused parameter.
func (*NoOpToolManager) ExecuteTool ¶
func (m *NoOpToolManager) ExecuteTool(_ context.Context, _ *tool.ExecutionRequest) (any, error)
ExecuteTool implements tool.ManagerInterface.
_ is an unused parameter. _ is an unused parameter.
Returns the result. Returns an error if the operation fails.
func (*NoOpToolManager) GetAllowedServiceIDs ¶
func (m *NoOpToolManager) GetAllowedServiceIDs(_ string) (map[string]bool, bool)
GetAllowedServiceIDs implements tool.ManagerInterface.
_ is an unused parameter.
Returns the result. Returns true if successful.
func (*NoOpToolManager) GetServiceInfo ¶
func (m *NoOpToolManager) GetServiceInfo(_ string) (*tool.ServiceInfo, bool)
GetServiceInfo implements tool.ManagerInterface.
_ is an unused parameter.
Returns the result. Returns true if successful.
func (*NoOpToolManager) GetTool ¶
func (m *NoOpToolManager) GetTool(_ string) (tool.Tool, bool)
GetTool implements tool.ManagerInterface.
_ is an unused parameter.
Returns the result. Returns true if successful.
func (*NoOpToolManager) GetToolCountForService ¶
func (m *NoOpToolManager) GetToolCountForService(_ string) int
GetToolCountForService implements tool.ManagerInterface.
_ is an unused parameter.
Returns the result.
func (*NoOpToolManager) IsServiceAllowed ¶
func (m *NoOpToolManager) IsServiceAllowed(_, _ string) bool
IsServiceAllowed implements tool.ManagerInterface.
_ is an unused parameter. _ is an unused parameter.
Returns true if successful.
func (*NoOpToolManager) ListMCPTools ¶
func (m *NoOpToolManager) ListMCPTools() []*mcp.Tool
ListMCPTools implements tool.ManagerInterface.
Returns the result.
func (*NoOpToolManager) ListServices ¶
func (m *NoOpToolManager) ListServices() []*tool.ServiceInfo
ListServices implements tool.ManagerInterface.
Returns the result.
func (*NoOpToolManager) ListTools ¶
func (m *NoOpToolManager) ListTools() []tool.Tool
ListTools implements tool.ManagerInterface.
Returns the result.
func (*NoOpToolManager) SetMCPServer ¶
func (m *NoOpToolManager) SetMCPServer(_ tool.MCPServerProvider)
SetMCPServer implements tool.ManagerInterface.
_ is an unused parameter.
func (*NoOpToolManager) SetProfiles ¶
func (m *NoOpToolManager) SetProfiles(_ []string, _ []*configv1.ProfileDefinition)
SetProfiles implements tool.ManagerInterface.
_ is an unused parameter. _ is an unused parameter.
func (*NoOpToolManager) ToolMatchesProfile ¶
func (m *NoOpToolManager) ToolMatchesProfile(_ tool.Tool, _ string) bool
ToolMatchesProfile implements tool.ManagerInterface.
_ is an unused parameter. _ is an unused parameter.
Returns true if successful.
type RegistrationServer ¶
type RegistrationServer struct {
v1.UnimplementedRegistrationServiceServer
// contains filtered or unexported fields
}
RegistrationServer implements the gRPC server for service registration.
Summary: Handles gRPC requests for registering and managing upstream services.
Side Effects:
- Publishes messages to the event bus.
- Interacts with the authentication manager.
func NewRegistrationServer ¶
func NewRegistrationServer(bus *bus.Provider, authManager *auth.Manager) (*RegistrationServer, error)
NewRegistrationServer creates a new RegistrationServer initialized with the event bus and auth manager.
Summary: Initializes a new RegistrationServer instance.
Parameters:
- bus: *bus.Provider. The event bus used for communication with workers.
- authManager: *auth.Manager. Manager for handling authentication and OAuth flows.
Returns:
- *RegistrationServer: A new instance of the RegistrationServer.
- error: An error if the bus is nil.
Throws/Errors:
- Returns an error if the bus is nil.
func (*RegistrationServer) GetService ¶
func (s *RegistrationServer) GetService(ctx context.Context, req *v1.GetServiceRequest) (*v1.GetServiceResponse, error)
GetService retrieves a service by its name.
Summary: Retrieves the configuration of a registered service.
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.GetServiceRequest. The request containing the service name.
Returns:
- *v1.GetServiceResponse: The response containing the service configuration.
- error: An error if the service is not found or other error.
Throws/Errors:
- codes.InvalidArgument: If the service name is missing.
- codes.NotFound: If the service is not found.
- codes.DeadlineExceeded: If the request times out.
func (*RegistrationServer) GetServiceStatus ¶
func (s *RegistrationServer) GetServiceStatus(_ context.Context, _ *v1.GetServiceStatusRequest) (*v1.GetServiceStatusResponse, error)
GetServiceStatus is not yet implemented.
Summary: Retrieves the status of a service (Not Implemented).
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.GetServiceStatusRequest. The request containing the service name or ID.
Returns:
- *v1.GetServiceStatusResponse: The response with the service status.
- error: Always returns an Unimplemented error.
func (*RegistrationServer) InitiateOAuth2Flow ¶
func (s *RegistrationServer) InitiateOAuth2Flow(ctx context.Context, req *v1.InitiateOAuth2FlowRequest) (*v1.InitiateOAuth2FlowResponse, error)
InitiateOAuth2Flow initiates an OAuth2 flow for a service or credential.
Summary: Initiates the OAuth2 flow by generating an authorization URL.
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.InitiateOAuth2FlowRequest. The request containing OAuth2 flow details.
Returns:
- *v1.InitiateOAuth2FlowResponse: The response containing the authorization URL and state.
- error: An error if validation fails or flow initiation errors.
Throws/Errors:
- codes.InvalidArgument: If required parameters are missing.
- codes.Unauthenticated: If the user is not authenticated.
- codes.Internal: If an internal error occurs.
func (*RegistrationServer) ListServices ¶
func (s *RegistrationServer) ListServices(ctx context.Context, _ *v1.ListServicesRequest) (*v1.ListServicesResponse, error)
ListServices lists all registered services by querying the service registry via the event bus.
Summary: Lists all currently registered services.
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.ListServicesRequest. The request object (empty for now).
Returns:
- *v1.ListServicesResponse: The response containing a list of registered services.
- error: An error if the operation fails or times out.
Throws/Errors:
- codes.DeadlineExceeded: If the request times out.
- codes.Internal: If an internal error occurs.
func (*RegistrationServer) RegisterService ¶
func (s *RegistrationServer) RegisterService(ctx context.Context, req *v1.RegisterServiceRequest) (*v1.RegisterServiceResponse, error)
RegisterService handles a gRPC request to register a new upstream service.
Summary: Asynchronously registers a new upstream service via the event bus.
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.RegisterServiceRequest. The request containing the configuration of the service to be registered.
Returns:
- *v1.RegisterServiceResponse: The response containing the registration status, service key, and discovered tools.
- error: An error if the registration fails, times out, or arguments are invalid.
Side Effects:
- Publishes a registration request to the event bus.
- Waits for a response on a dedicated result channel.
func (*RegistrationServer) RegisterTools ¶
func (s *RegistrationServer) RegisterTools(_ context.Context, _ *v1.RegisterToolsRequest) (*v1.RegisterToolsResponse, error)
RegisterTools is not yet implemented.
Summary: Registers tools for a service (Not Implemented).
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.RegisterToolsRequest. The request containing the tools to register.
Returns:
- *v1.RegisterToolsResponse: A response indicating success or failure.
- error: Always returns an Unimplemented error.
func (*RegistrationServer) UnregisterService ¶
func (s *RegistrationServer) UnregisterService(_ context.Context, _ *v1.UnregisterServiceRequest) (*v1.UnregisterServiceResponse, error)
UnregisterService is not yet implemented.
Summary: Handles the unregistration of a service (Not Implemented).
Parameters:
- ctx: context.Context. The context for the gRPC call.
- req: *v1.UnregisterServiceRequest. The request containing the service ID to unregister.
Returns:
- *v1.UnregisterServiceResponse: The response indicating success or failure.
- error: Always returns an Unimplemented error.
func (*RegistrationServer) ValidateService ¶
func (s *RegistrationServer) ValidateService(ctx context.Context, req *v1.ValidateServiceRequest) (*v1.ValidateServiceResponse, error)
ValidateService validates a service configuration by attempting to connect and discover tools.
Summary: Validates the provided service configuration by connecting to the upstream service.
Parameters:
- ctx: context.Context. The context for the request.
- req: *v1.ValidateServiceRequest. The validation request containing the service configuration.
Returns:
- *v1.ValidateServiceResponse: The response containing validation results, discovered tools, and resources.
- error: An error if the validation request itself is invalid (e.g. missing config).
Side Effects:
- Temporarily creates an upstream connection and then closes it.
type RootsTool ¶
type RootsTool struct {
// contains filtered or unexported fields
}
RootsTool implements the Tool interface for listing roots.
It provides a built-in tool ("mcp:list_roots") that allows the server to query the client for available filesystem roots.
func NewRootsTool ¶
func NewRootsTool() *RootsTool
NewRootsTool creates a new instance of the RootsTool.
It initializes the tool definition including its schema and service ID.
Returns:
- *RootsTool: A pointer to the initialized RootsTool.
func (*RootsTool) Execute ¶
Execute executes the "mcp:list_roots" tool.
It retrieves the current MCP session from the context and requests the client to list its roots.
Parameters:
- ctx: context.Context. The request context, must contain an active MCP session.
- _: *tool.ExecutionRequest. The execution request parameters (unused as this tool takes no inputs).
Returns:
- any: The result of the roots list operation (typically a list of roots).
- error: An error if the session is missing or the list operation fails.
func (*RootsTool) GetCacheConfig ¶
func (t *RootsTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the caching configuration for this tool.
Returns:
- *configv1.CacheConfig: Always nil, as this tool depends on client state and should not be cached.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is responsible for mapping MCP method names to their corresponding handler functions.
Side Effects:
- Stores handlers in an internal map.
func NewRouter ¶
func NewRouter() *Router
NewRouter creates and returns a new, empty Router.
Returns:
- *Router: A pointer to a new, initialized Router.
func (*Router) GetHandler ¶
func (r *Router) GetHandler(method string) (MethodHandler, bool)
GetHandler retrieves the handler function for a given MCP method name.
Parameters:
- method: string. The name of the MCP method.
Returns:
- MethodHandler: The handler function if found.
- bool: A boolean indicating whether a handler was found (true) or not (false).
func (*Router) Register ¶
func (r *Router) Register(method string, handler MethodHandler)
Register associates a handler function with a specific MCP method name.
Parameters:
- method: string. The name of the MCP method (e.g., "tools/call").
- handler: MethodHandler. The function that will handle the method call.
Side Effects:
- If a handler for the method already exists, it will be overwritten.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the core of the MCP Any application.
It orchestrates the handling of MCP (Model Context Protocol) requests by managing various components such as tools, prompts, resources, and services. It uses an internal router to delegate requests to the appropriate handlers and communicates with backend workers via an event bus.
func NewServer ¶
func NewServer( _ context.Context, toolManager tool.ManagerInterface, promptManager prompt.ManagerInterface, resourceManager resource.ManagerInterface, authManager *auth.Manager, serviceRegistry *serviceregistry.ServiceRegistry, catalogManager *catalog.Manager, bus *bus.Provider, debug bool, ) (*Server, error)
NewServer creates and initializes a new MCP Any Server.
It sets up the necessary managers for tools, prompts, and resources, configures the router with handlers for standard MCP methods, and establishes middleware for request processing, such as routing and tool list filtering.
Parameters:
- ctx: context.Context. The application's root context.
- toolManager: tool.ManagerInterface. Manages the lifecycle and access to tools.
- promptManager: prompt.ManagerInterface. Manages the lifecycle and access to prompts.
- resourceManager: resource.ManagerInterface. Manages the lifecycle and access to resources.
- authManager: *auth.Manager. Handles authentication for incoming requests.
- serviceRegistry: *serviceregistry.ServiceRegistry. Keeps track of all registered upstream services.
- catalogManager: *catalog.Manager. Manages the dynamic service catalog.
- bus: *bus.Provider. The event bus used for asynchronous communication between components.
- debug: bool. Whether to enable debug mode.
Returns:
- *Server: A new instance of the Server.
- error: An error if initialization fails.
func (*Server) AddServiceInfo ¶
func (s *Server) AddServiceInfo(serviceID string, info *tool.ServiceInfo)
AddServiceInfo adds information about a service to the tool manager.
Parameters:
- serviceID: string. The unique identifier of the service.
- info: *tool.ServiceInfo. The service information to add.
Returns:
None.
func (*Server) AddTool ¶
AddTool registers a new tool with the tool manager.
Parameters:
- t: tool.Tool. The tool instance to register.
Returns:
- error: An error if the tool cannot be added (e.g., if it already exists).
func (*Server) AuthManager ¶
AuthManager returns the server's authentication manager.
It provides access to the authentication manager, which is responsible for handling authentication for incoming requests.
Returns:
- *auth.Manager: The authentication manager instance.
func (*Server) CallTool ¶
CallTool executes a tool with the provided request.
It handles the execution of the tool, including logging, metrics collection, and profile-based access control.
Parameters:
- ctx: context.Context. The context for the execution.
- req: *tool.ExecutionRequest. The execution request containing tool name and arguments.
Returns:
- any: The result of the tool execution.
- error: An error if the tool execution fails or access is denied.
func (*Server) ClearToolsForService ¶
ClearToolsForService removes all tools associated with a specific service.
Parameters:
- serviceKey: string. The identifier of the service whose tools should be cleared.
Returns:
None.
func (*Server) CreateMessage ¶
func (s *Server) CreateMessage(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
CreateMessage requests a message creation from the client (sampling).
This method exposes sampling to the Server instance if a session is available.
Parameters:
- ctx: context.Context. The context for the request.
- params: *mcp.CreateMessageParams. The parameters for the message creation.
Returns:
- *mcp.CreateMessageResult: The result of the message creation.
- error: An error if no active session is found in context or if the operation fails.
func (*Server) GetPrompt ¶
func (s *Server) GetPrompt( ctx context.Context, req *mcp.GetPromptRequest, ) (*mcp.GetPromptResult, error)
GetPrompt handles the "prompts/get" MCP request.
It retrieves a specific prompt by name from the PromptManager and executes it with the provided arguments, returning the result.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.GetPromptRequest. The "prompts/get" request from the client, containing the prompt name and arguments.
Returns:
- *mcp.GetPromptResult: The result of the prompt execution.
- error: An error if the prompt is not found or execution fails.
Throws/Errors:
- prompt.ErrPromptNotFound: If the requested prompt does not exist.
func (*Server) GetServiceInfo ¶
func (s *Server) GetServiceInfo(serviceID string) (*tool.ServiceInfo, bool)
GetServiceInfo retrieves information about a service by its ID.
Parameters:
- serviceID: string. The unique identifier of the service.
Returns:
- *tool.ServiceInfo: A pointer to the ServiceInfo if found.
- bool: A boolean indicating whether the service was found.
func (*Server) GetTool ¶
GetTool retrieves a tool by its name.
Parameters:
- toolName: string. The name of the tool to retrieve.
Returns:
- tool.Tool: The tool instance if found.
- bool: A boolean indicating whether the tool was found.
func (*Server) ListPrompts ¶
func (s *Server) ListPrompts( _ context.Context, _ *mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPrompts handles the "prompts/list" MCP request.
It retrieves the list of available prompts from the PromptManager, converts them to the MCP format, and returns them to the client.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.ListPromptsRequest. The "prompts/list" request from the client.
Returns:
- *mcp.ListPromptsResult: A list of available prompts.
- error: An error if the retrieval fails.
func (*Server) ListResources ¶
func (s *Server) ListResources( _ context.Context, _ *mcp.ListResourcesRequest, ) (*mcp.ListResourcesResult, error)
ListResources handles the "resources/list" MCP request.
It fetches the list of available resources from the ResourceManager, converts them to the MCP format, and returns them to the client.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.ListResourcesRequest. The "resources/list" request from the client.
Returns:
- *mcp.ListResourcesResult: A list of available resources.
- error: An error if the retrieval fails.
func (*Server) ListTools ¶
ListTools returns a list of all available tools.
Returns:
- []tool.Tool: A slice of all available tools.
func (*Server) PromptManager ¶
func (s *Server) PromptManager() prompt.ManagerInterface
PromptManager returns the server's prompt manager.
It provides access to the prompt manager, which is responsible for managing the lifecycle and access to prompts.
Returns:
- prompt.ManagerInterface: The prompt manager interface.
func (*Server) ReadResource ¶
func (s *Server) ReadResource( ctx context.Context, req *mcp.ReadResourceRequest, ) (*mcp.ReadResourceResult, error)
ReadResource handles the "resources/read" MCP request.
It retrieves a specific resource by its URI from the ResourceManager and returns its content.
Parameters:
- ctx: context.Context. The context for the request.
- req: *mcp.ReadResourceRequest. The "resources/read" request from the client, containing the URI of the resource.
Returns:
- *mcp.ReadResourceResult: The content of the resource.
- error: An error if the resource is not found or reading fails.
Throws/Errors:
- resource.ErrResourceNotFound: If the requested resource does not exist.
func (*Server) Reload ¶
Reload reloads the server's configuration and updates its state.
Parameters:
- ctx: context.Context. The context for the reload operation.
Returns:
- error: An error if the reload function fails.
func (*Server) ResourceManager ¶
func (s *Server) ResourceManager() resource.ManagerInterface
ResourceManager returns the server's resource manager.
It provides access to the resource manager, which is responsible for managing the lifecycle and access to resources.
Returns:
- resource.ManagerInterface: The resource manager interface.
func (*Server) Server ¶
Server returns the underlying *mcp.Server instance.
It provides access to the core MCP server functionality, which can be used for advanced configurations or direct interaction with the MCP server.
Returns:
- *mcp.Server: The underlying server instance.
func (*Server) ServiceRegistry ¶
func (s *Server) ServiceRegistry() *serviceregistry.ServiceRegistry
ServiceRegistry returns the server's service registry.
It provides access to the service registry, which keeps track of all registered upstream services.
Returns:
- *serviceregistry.ServiceRegistry: The service registry instance.
func (*Server) SetMCPServer ¶
func (s *Server) SetMCPServer(mcpServer tool.MCPServerProvider)
SetMCPServer sets the MCP server provider for the tool manager.
Parameters:
- mcpServer: tool.MCPServerProvider. The MCP server provider to set.
Returns:
None.
func (*Server) SetReloadFunc ¶
SetReloadFunc sets the function to be called when a configuration reload is triggered.
Parameters:
- f: func(context.Context) error. The function to execute on reload.
Returns:
None.
func (*Server) ToolManager ¶
func (s *Server) ToolManager() tool.ManagerInterface
ToolManager returns the server's tool manager.
It provides access to the tool manager, which is responsible for managing the lifecycle and access to tools.
Returns:
- tool.ManagerInterface: The tool manager interface.
type SkillResource ¶
type SkillResource struct {
// contains filtered or unexported fields
}
SkillResource adapts a Skill (or its asset) to the Resource interface.
It provides a way to expose skill documentation and associated assets (like images or text files) as MCP resources, making them accessible to clients.
func NewSkillAssetResource ¶
func NewSkillAssetResource(s *skill.Skill, assetPath string) *SkillResource
NewSkillAssetResource creates a new resource for a skill asset.
It wraps a specific asset associated with a skill into a Resource.
Parameters:
- s: *skill.Skill. The skill definition the asset belongs to.
- assetPath: string. The relative path to the asset file within the skill's directory.
Returns:
- *SkillResource: A new instance of SkillResource pointing to the specified asset.
func NewSkillResource ¶
func NewSkillResource(s *skill.Skill) *SkillResource
NewSkillResource creates a new resource for the main SKILL.md.
It wraps the provided Skill definition into a Resource that serves the skill's documentation file (SKILL.md).
Parameters:
- s: *skill.Skill. The skill definition to expose as a resource.
Returns:
- *SkillResource: A new instance of SkillResource pointing to the skill's documentation.
func (*SkillResource) Name ¶
func (r *SkillResource) Name() string
Name returns the human-readable name of the resource.
Returns:
- string: The name of the resource, including the skill name and asset path if applicable.
func (*SkillResource) Read ¶
func (r *SkillResource) Read(_ context.Context) (*mcp.ReadResourceResult, error)
Read returns the contents of the resource.
It reads the file content from disk, verifying that the path is secure and within the allowed skill directory to prevent path traversal attacks.
Parameters:
- _ : context.Context. Unused in this implementation.
Returns:
- *mcp.ReadResourceResult: The result containing the resource content (text or blob).
- error: An error if the file cannot be read or if the path is invalid.
func (*SkillResource) Resource ¶
func (r *SkillResource) Resource() *mcp.Resource
Resource returns the underlying MCP resource definition.
It constructs the mcp.Resource object, determining the MIME type based on the file extension.
Returns:
- *mcp.Resource: The MCP resource definition.
func (*SkillResource) Service ¶
func (r *SkillResource) Service() string
Service returns the service identifier associated with the resource.
All skill resources belong to the "skills" service.
Returns:
- string: The fixed string "skills".
func (*SkillResource) Subscribe ¶
func (r *SkillResource) Subscribe(_ context.Context) error
Subscribe subscribes to changes on the resource.
Currently, this implementation is a no-op as dynamic updates to skill resources are not yet supported.
Parameters:
- _ : context.Context. Unused.
Returns:
- error: Always returns nil.
func (*SkillResource) URI ¶
func (r *SkillResource) URI() string
URI returns the URI of the resource.
Constructs a unique URI for the resource using the scheme "skills://". For the main skill documentation, the URI is "skills://<skill_name>/SKILL.md". For assets, the URI is "skills://<skill_name>/<asset_path>".
Returns:
- string: The unique URI of the resource.
type TemporaryToolManager ¶
type TemporaryToolManager struct {
NoOpToolManager
// contains filtered or unexported fields
}
TemporaryToolManager is a tool manager that stores service info temporarily. It is intended for use in ValidateService where we need to store service info for the duration of the validation request but discard it afterwards.
func NewTemporaryToolManager ¶
func NewTemporaryToolManager() *TemporaryToolManager
NewTemporaryToolManager creates a new TemporaryToolManager.
func (*TemporaryToolManager) AddServiceInfo ¶
func (m *TemporaryToolManager) AddServiceInfo(serviceID string, info *tool.ServiceInfo)
AddServiceInfo implements tool.ManagerInterface.
func (*TemporaryToolManager) GetServiceInfo ¶
func (m *TemporaryToolManager) GetServiceInfo(serviceID string) (*tool.ServiceInfo, bool)
GetServiceInfo implements tool.ManagerInterface.
func (*TemporaryToolManager) GetToolCountForService ¶
func (m *TemporaryToolManager) GetToolCountForService(_ string) int
GetToolCountForService implements tool.ManagerInterface.