Documentation
¶
Overview ¶
Package mcps contains the logic for managing MCP clients.
Index ¶
- func GetPrompt(name string) (string, bool)
- func IsOpenAPIProxyConfig(name string) bool
- func IsProxyMCPConfig(name string) bool
- type MCPs
- func (m *MCPs) CallTool(ctx context.Context, callID string, toolName string, args map[string]any) (openai.ChatCompletionMessageParamUnion, error)
- func (m *MCPs) CallToolOpenAI(ctx context.Context, toolCall openai.ChatCompletionChunkChoiceDeltaToolCall) (openai.ChatCompletionMessageParamUnion, error)
- func (m *MCPs) Shutdown()
- type McpClient
- type OpenApiMcpClient
- func (p *OpenApiMcpClient) CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (p *OpenApiMcpClient) Close() error
- func (p *OpenApiMcpClient) Complete(ctx context.Context, request mcp.CompleteRequest) (*mcp.CompleteResult, error)
- func (p *OpenApiMcpClient) GetPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (p *OpenApiMcpClient) Initialize(ctx context.Context, request mcp.InitializeRequest) (*mcp.InitializeResult, error)
- func (p *OpenApiMcpClient) ListPrompts(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (p *OpenApiMcpClient) ListPromptsByPage(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (p *OpenApiMcpClient) ListResourceTemplates(ctx context.Context, request mcp.ListResourceTemplatesRequest) (*mcp.ListResourceTemplatesResult, error)
- func (p *OpenApiMcpClient) ListResourceTemplatesByPage(ctx context.Context, request mcp.ListResourceTemplatesRequest) (*mcp.ListResourceTemplatesResult, error)
- func (p *OpenApiMcpClient) ListResources(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (p *OpenApiMcpClient) ListResourcesByPage(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (p *OpenApiMcpClient) ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
- func (p *OpenApiMcpClient) ListToolsByPage(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
- func (p *OpenApiMcpClient) OnNotification(handler func(notification mcp.JSONRPCNotification))
- func (p *OpenApiMcpClient) Ping(ctx context.Context) error
- func (p *OpenApiMcpClient) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- func (p *OpenApiMcpClient) SetLevel(ctx context.Context, request mcp.SetLevelRequest) error
- func (p *OpenApiMcpClient) Subscribe(ctx context.Context, request mcp.SubscribeRequest) error
- func (p *OpenApiMcpClient) Unsubscribe(ctx context.Context, request mcp.UnsubscribeRequest) error
- type PromptDef
- type ProxyMCPClient
- func (p *ProxyMCPClient) CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (p *ProxyMCPClient) Close() error
- func (p *ProxyMCPClient) Complete(ctx context.Context, request mcp.CompleteRequest) (*mcp.CompleteResult, error)
- func (p *ProxyMCPClient) GetPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (p *ProxyMCPClient) Initialize(ctx context.Context, request mcp.InitializeRequest) (*mcp.InitializeResult, error)
- func (p *ProxyMCPClient) ListPrompts(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (p *ProxyMCPClient) ListPromptsByPage(ctx context.Context, request mcp.ListPromptsRequest) (*mcp.ListPromptsResult, error)
- func (p *ProxyMCPClient) ListResourceTemplates(ctx context.Context, request mcp.ListResourceTemplatesRequest) (*mcp.ListResourceTemplatesResult, error)
- func (p *ProxyMCPClient) ListResourceTemplatesByPage(ctx context.Context, request mcp.ListResourceTemplatesRequest) (*mcp.ListResourceTemplatesResult, error)
- func (p *ProxyMCPClient) ListResources(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (p *ProxyMCPClient) ListResourcesByPage(ctx context.Context, request mcp.ListResourcesRequest) (*mcp.ListResourcesResult, error)
- func (p *ProxyMCPClient) ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
- func (p *ProxyMCPClient) ListToolsByPage(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
- func (p *ProxyMCPClient) OnNotification(handler func(notification mcp.JSONRPCNotification))
- func (p *ProxyMCPClient) Ping(ctx context.Context) error
- func (p *ProxyMCPClient) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- func (p *ProxyMCPClient) SetLevel(ctx context.Context, request mcp.SetLevelRequest) error
- func (p *ProxyMCPClient) Subscribe(ctx context.Context, request mcp.SubscribeRequest) error
- func (p *ProxyMCPClient) Unsubscribe(ctx context.Context, request mcp.UnsubscribeRequest) error
- type ToolDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsOpenAPIProxyConfig ¶ added in v0.2.8
IsOpenAPIProxyConfig checks if the given name is an openapi proxy MCP configuration file.
func IsProxyMCPConfig ¶ added in v0.2.7
IsProxyMCPConfig checks if the given name is a proxy MCP configuration file.
Types ¶
type MCPs ¶
type MCPs struct {
Tools []openai.ChatCompletionToolUnionParam
// contains filtered or unexported fields
}
MCPs is a collection of MCP clients. It manages the lifecycle of the clients and provides a single entry point for calling tools.
func New ¶
New creates a new MCPs instance. It initializes the clients and lists the available tools.
func (*MCPs) CallTool ¶
func (m *MCPs) CallTool(ctx context.Context, callID string, toolName string, args map[string]any) (openai.ChatCompletionMessageParamUnion, error)
CallTool calls a tool with the given name and arguments. It returns the result of the tool call as a ChatCompletionMessageParamUnion.
func (*MCPs) CallToolOpenAI ¶
func (m *MCPs) CallToolOpenAI(ctx context.Context, toolCall openai.ChatCompletionChunkChoiceDeltaToolCall) (openai.ChatCompletionMessageParamUnion, error)
CallToolOpenAI calls a tool with the given name and arguments. It is a wrapper around CallTool that takes an openai.ChatCompletionChunkChoiceDeltaToolCall.
type McpClient ¶
type McpClient struct {
// contains filtered or unexported fields
}
McpClient is a wrapper around the mcpc.MCPClient. It holds the client and the provider string.
func NewClient ¶
NewClient creates a new McpClient based on the provider string. It can create either a local or a remote client.
func NewLocalClient ¶
NewLocalClient creates a new local McpClient. It can be either a proxy client or a stdio client.
func NewRemoteClient ¶
NewRemoteClient creates a new remote McpClient. It can be either a http client or a sse client.
type OpenApiMcpClient ¶ added in v0.2.8
type OpenApiMcpClient struct {
// contains filtered or unexported fields
}
OpenApiMcpClient implements the MCPClient interface and proxies OpenAPI services as MCP services.
func NewOpenApiMcpClient ¶ added in v0.2.8
func NewOpenApiMcpClient(configPath string) (*OpenApiMcpClient, error)
NewOpenApiMcpClient creates a new OpenApiMcpClient from a configuration file.
func (*OpenApiMcpClient) CallTool ¶ added in v0.2.8
func (p *OpenApiMcpClient) CallTool( ctx context.Context, request mcp.CallToolRequest, ) (*mcp.CallToolResult, error)
CallTool implements the MCPClient.CallTool method.
func (*OpenApiMcpClient) Close ¶ added in v0.2.8
func (p *OpenApiMcpClient) Close() error
Close implements the MCPClient.Close method.
func (*OpenApiMcpClient) Complete ¶ added in v0.2.8
func (p *OpenApiMcpClient) Complete( ctx context.Context, request mcp.CompleteRequest, ) (*mcp.CompleteResult, error)
Complete implements the MCPClient.Complete method.
func (*OpenApiMcpClient) GetPrompt ¶ added in v0.2.8
func (p *OpenApiMcpClient) GetPrompt( ctx context.Context, request mcp.GetPromptRequest, ) (*mcp.GetPromptResult, error)
GetPrompt implements the MCPClient.GetPrompt method.
func (*OpenApiMcpClient) Initialize ¶ added in v0.2.8
func (p *OpenApiMcpClient) Initialize( ctx context.Context, request mcp.InitializeRequest, ) (*mcp.InitializeResult, error)
Initialize implements the MCPClient.Initialize method.
func (*OpenApiMcpClient) ListPrompts ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListPrompts( ctx context.Context, request mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPrompts implements the MCPClient.ListPrompts method.
func (*OpenApiMcpClient) ListPromptsByPage ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListPromptsByPage( ctx context.Context, request mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPromptsByPage implements the MCPClient.ListPromptsByPage method.
func (*OpenApiMcpClient) ListResourceTemplates ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListResourceTemplates( ctx context.Context, request mcp.ListResourceTemplatesRequest, ) (*mcp.ListResourceTemplatesResult, error)
ListResourceTemplates implements the MCPClient.ListResourceTemplates method.
func (*OpenApiMcpClient) ListResourceTemplatesByPage ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListResourceTemplatesByPage( ctx context.Context, request mcp.ListResourceTemplatesRequest, ) (*mcp.ListResourceTemplatesResult, error)
ListResourceTemplatesByPage implements the MCPClient.ListResourceTemplatesByPage method.
func (*OpenApiMcpClient) ListResources ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListResources( ctx context.Context, request mcp.ListResourcesRequest, ) (*mcp.ListResourcesResult, error)
ListResources implements the MCPClient.ListResources method.
func (*OpenApiMcpClient) ListResourcesByPage ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListResourcesByPage( ctx context.Context, request mcp.ListResourcesRequest, ) (*mcp.ListResourcesResult, error)
ListResourcesByPage implements the MCPClient.ListResourcesByPage method.
func (*OpenApiMcpClient) ListTools ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListTools( ctx context.Context, request mcp.ListToolsRequest, ) (*mcp.ListToolsResult, error)
ListTools implements the MCPClient.ListTools method.
func (*OpenApiMcpClient) ListToolsByPage ¶ added in v0.2.8
func (p *OpenApiMcpClient) ListToolsByPage( ctx context.Context, request mcp.ListToolsRequest, ) (*mcp.ListToolsResult, error)
ListToolsByPage implements the MCPClient.ListToolsByPage method.
func (*OpenApiMcpClient) OnNotification ¶ added in v0.2.8
func (p *OpenApiMcpClient) OnNotification(handler func(notification mcp.JSONRPCNotification))
OnNotification implements the MCPClient.OnNotification method.
func (*OpenApiMcpClient) Ping ¶ added in v0.2.8
func (p *OpenApiMcpClient) Ping(ctx context.Context) error
Ping implements the MCPClient.Ping method.
func (*OpenApiMcpClient) ReadResource ¶ added in v0.2.8
func (p *OpenApiMcpClient) ReadResource( ctx context.Context, request mcp.ReadResourceRequest, ) (*mcp.ReadResourceResult, error)
ReadResource implements the MCPClient.ReadResource method.
func (*OpenApiMcpClient) SetLevel ¶ added in v0.2.8
func (p *OpenApiMcpClient) SetLevel(ctx context.Context, request mcp.SetLevelRequest) error
SetLevel implements the MCPClient.SetLevel method.
func (*OpenApiMcpClient) Subscribe ¶ added in v0.2.8
func (p *OpenApiMcpClient) Subscribe(ctx context.Context, request mcp.SubscribeRequest) error
Subscribe implements the MCPClient.Subscribe method.
func (*OpenApiMcpClient) Unsubscribe ¶ added in v0.2.8
func (p *OpenApiMcpClient) Unsubscribe(ctx context.Context, request mcp.UnsubscribeRequest) error
Unsubscribe implements the MCPClient.Unsubscribe method.
type PromptDef ¶ added in v0.2.7
type PromptDef struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Messages []mcp.PromptMessage `json:"messages" yaml:"messages"`
}
PromptDef defines the structure of a prompt in the proxy configuration.
type ProxyMCPClient ¶ added in v0.2.7
type ProxyMCPClient struct {
Tools []ToolDef `json:"tools" yaml:"tools"`
Prompts []PromptDef `json:"prompts" yaml:"prompts"`
// contains filtered or unexported fields
}
ProxyMCPClient implements the MCPClient interface and proxies HTTP services as MCP services.
func NewProxyMCPClient ¶ added in v0.2.7
func NewProxyMCPClient(configPath string) (*ProxyMCPClient, error)
NewProxyMCPClient creates a new ProxyMCPClient from a configuration file.
func (*ProxyMCPClient) CallTool ¶ added in v0.2.7
func (p *ProxyMCPClient) CallTool( ctx context.Context, request mcp.CallToolRequest, ) (*mcp.CallToolResult, error)
CallTool implements the MCPClient.CallTool method.
func (*ProxyMCPClient) Close ¶ added in v0.2.7
func (p *ProxyMCPClient) Close() error
Close implements the MCPClient.Close method.
func (*ProxyMCPClient) Complete ¶ added in v0.2.7
func (p *ProxyMCPClient) Complete( ctx context.Context, request mcp.CompleteRequest, ) (*mcp.CompleteResult, error)
Complete implements the MCPClient.Complete method.
func (*ProxyMCPClient) GetPrompt ¶ added in v0.2.7
func (p *ProxyMCPClient) GetPrompt( ctx context.Context, request mcp.GetPromptRequest, ) (*mcp.GetPromptResult, error)
GetPrompt implements the MCPClient.GetPrompt method.
func (*ProxyMCPClient) Initialize ¶ added in v0.2.7
func (p *ProxyMCPClient) Initialize( ctx context.Context, request mcp.InitializeRequest, ) (*mcp.InitializeResult, error)
Initialize implements the MCPClient.Initialize method.
func (*ProxyMCPClient) ListPrompts ¶ added in v0.2.7
func (p *ProxyMCPClient) ListPrompts( ctx context.Context, request mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPrompts implements the MCPClient.ListPrompts method.
func (*ProxyMCPClient) ListPromptsByPage ¶ added in v0.2.7
func (p *ProxyMCPClient) ListPromptsByPage( ctx context.Context, request mcp.ListPromptsRequest, ) (*mcp.ListPromptsResult, error)
ListPromptsByPage implements the MCPClient.ListPromptsByPage method.
func (*ProxyMCPClient) ListResourceTemplates ¶ added in v0.2.7
func (p *ProxyMCPClient) ListResourceTemplates( ctx context.Context, request mcp.ListResourceTemplatesRequest, ) (*mcp.ListResourceTemplatesResult, error)
ListResourceTemplates implements the MCPClient.ListResourceTemplates method.
func (*ProxyMCPClient) ListResourceTemplatesByPage ¶ added in v0.2.7
func (p *ProxyMCPClient) ListResourceTemplatesByPage( ctx context.Context, request mcp.ListResourceTemplatesRequest, ) (*mcp.ListResourceTemplatesResult, error)
ListResourceTemplatesByPage implements the MCPClient.ListResourceTemplatesByPage method.
func (*ProxyMCPClient) ListResources ¶ added in v0.2.7
func (p *ProxyMCPClient) ListResources( ctx context.Context, request mcp.ListResourcesRequest, ) (*mcp.ListResourcesResult, error)
ListResources implements the MCPClient.ListResources method.
func (*ProxyMCPClient) ListResourcesByPage ¶ added in v0.2.7
func (p *ProxyMCPClient) ListResourcesByPage( ctx context.Context, request mcp.ListResourcesRequest, ) (*mcp.ListResourcesResult, error)
ListResourcesByPage implements the MCPClient.ListResourcesByPage method.
func (*ProxyMCPClient) ListTools ¶ added in v0.2.7
func (p *ProxyMCPClient) ListTools( ctx context.Context, request mcp.ListToolsRequest, ) (*mcp.ListToolsResult, error)
ListTools implements the MCPClient.ListTools method.
func (*ProxyMCPClient) ListToolsByPage ¶ added in v0.2.7
func (p *ProxyMCPClient) ListToolsByPage( ctx context.Context, request mcp.ListToolsRequest, ) (*mcp.ListToolsResult, error)
ListToolsByPage implements the MCPClient.ListToolsByPage method.
func (*ProxyMCPClient) OnNotification ¶ added in v0.2.7
func (p *ProxyMCPClient) OnNotification(handler func(notification mcp.JSONRPCNotification))
OnNotification implements the MCPClient.OnNotification method.
func (*ProxyMCPClient) Ping ¶ added in v0.2.7
func (p *ProxyMCPClient) Ping(ctx context.Context) error
Ping implements the MCPClient.Ping method.
func (*ProxyMCPClient) ReadResource ¶ added in v0.2.7
func (p *ProxyMCPClient) ReadResource( ctx context.Context, request mcp.ReadResourceRequest, ) (*mcp.ReadResourceResult, error)
ReadResource implements the MCPClient.ReadResource method.
func (*ProxyMCPClient) SetLevel ¶ added in v0.2.7
func (p *ProxyMCPClient) SetLevel(ctx context.Context, request mcp.SetLevelRequest) error
SetLevel implements the MCPClient.SetLevel method.
func (*ProxyMCPClient) Subscribe ¶ added in v0.2.7
func (p *ProxyMCPClient) Subscribe(ctx context.Context, request mcp.SubscribeRequest) error
Subscribe implements the MCPClient.Subscribe method.
func (*ProxyMCPClient) Unsubscribe ¶ added in v0.2.7
func (p *ProxyMCPClient) Unsubscribe(ctx context.Context, request mcp.UnsubscribeRequest) error
Unsubscribe implements the MCPClient.Unsubscribe method.
type ToolDef ¶ added in v0.2.7
type ToolDef struct {
Name string `json:"name" yaml:"name"`
URL string `json:"url" yaml:"url"`
Method string `json:"method,omitempty" yaml:"method,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
InputSchema mcp.ToolInputSchema `json:"inputSchema,omitempty" yaml:"inputSchema,omitempty"`
}
ToolDef defines the structure of a tool in the proxy configuration.