mcps

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package mcps contains the logic for managing MCP clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPrompt added in v0.2.6

func GetPrompt(name string) (string, bool)

GetPrompt gets the prompt with the given name.

func IsOpenAPIProxyConfig added in v0.2.8

func IsOpenAPIProxyConfig(name string) bool

IsOpenAPIProxyConfig checks if the given name is an openapi proxy MCP configuration file.

func IsProxyMCPConfig added in v0.2.7

func IsProxyMCPConfig(name string) bool

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

func New(providers ...string) (*MCPs, error)

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

CallToolOpenAI calls a tool with the given name and arguments. It is a wrapper around CallTool that takes an openai.ChatCompletionChunkChoiceDeltaToolCall.

func (*MCPs) Shutdown

func (m *MCPs) Shutdown()

Shutdown closes all the MCP clients.

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

func NewClient(provider string) (*McpClient, error)

NewClient creates a new McpClient based on the provider string. It can create either a local or a remote client.

func NewLocalClient

func NewLocalClient(provider string) (*McpClient, error)

NewLocalClient creates a new local McpClient. It can be either a proxy client or a stdio client.

func NewRemoteClient

func NewRemoteClient(provider string) (*McpClient, error)

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

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

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.

Jump to

Keyboard shortcuts

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