Documentation
¶
Index ¶
- func EncodeToolID(server, tool string) string
- func FilterAllowedTools(logger slog.Logger, tools map[string]*Tool, allowlist *regexp.Regexp, ...) map[string]*Tool
- func GetClientInfo() mcp.Implementation
- type ServerProxier
- type ServerProxyManager
- func (s *ServerProxyManager) CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
- func (s *ServerProxyManager) GetTool(name string) *Tool
- func (s *ServerProxyManager) Init(ctx context.Context) error
- func (s *ServerProxyManager) ListTools() []*Tool
- func (s *ServerProxyManager) Shutdown(ctx context.Context) error
- type StreamableHTTPServerProxy
- func (p *StreamableHTTPServerProxy) CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
- func (p *StreamableHTTPServerProxy) GetTool(name string) *Tool
- func (p *StreamableHTTPServerProxy) Init(ctx context.Context) error
- func (p *StreamableHTTPServerProxy) ListTools() []*Tool
- func (p *StreamableHTTPServerProxy) Name() string
- func (p *StreamableHTTPServerProxy) Shutdown(ctx context.Context) error
- type Tool
- type ToolCaller
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeToolID ¶
EncodeToolID namespaces the given tool name with a prefix to identify tools injected by this library. Claude Code, for example, prefixes the tools it includes from defined MCP servers with the "mcp__" prefix. We have to namespace the tools we inject to prevent clashes.
We stick to 5 prefix chars ("bmcp_") like "mcp__" since names can only be up to 64 chars:
See: - https://community.openai.com/t/function-call-description-max-length/529902 - https://github.com/anthropics/claude-code/issues/2326
func FilterAllowedTools ¶
func FilterAllowedTools(logger slog.Logger, tools map[string]*Tool, allowlist *regexp.Regexp, denylist *regexp.Regexp) map[string]*Tool
FilterAllowedTools filters tools based on the given allow/denylists. Filtering acts on tool names, and uses tool IDs for tracking. The denylist supersedes the allowlist in the case of any conflicts. If an allowlist is provided, tools must match it to be allowed. If only a denylist is provided, tools are allowed unless explicitly denied.
func GetClientInfo ¶
func GetClientInfo() mcp.Implementation
GetClientInfo returns the MCP client information to use when initializing MCP connections. This provides a consistent way for all proxy implementations to report client information.
Types ¶
type ServerProxier ¶
type ServerProxier interface {
// Init initializes the proxier, establishing a connection with the upstream server and fetching resources.
Init(context.Context) error
// Gracefully shut down connections to the MCP server. Session management will vary per transport.
// See https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management.
Shutdown(ctx context.Context) error
// ListTools lists all known tools.
ListTools() []*Tool
// GetTool returns a given tool, if known, or returns nil.
GetTool(id string) *Tool
// CallTool invokes an injected MCP tool
CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
}
ServerProxier provides an abstraction to communicate with MCP Servers regardless of their transport. The ServerProxier is expected to, at least, fetch any available MCP tools.
type ServerProxyManager ¶
type ServerProxyManager struct {
// contains filtered or unexported fields
}
ServerProxyManager can act on behalf of multiple [ServerProxier]s. It aggregates all server resources (currently just tools) across all MCP servers for the purpose of injection into bridged requests and invocation.
func NewServerProxyManager ¶
func NewServerProxyManager(proxiers map[string]ServerProxier) *ServerProxyManager
func (*ServerProxyManager) CallTool ¶
func (s *ServerProxyManager) CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
CallTool locates the proxier to which the requested tool is associated and delegates the tool call to it.
func (*ServerProxyManager) GetTool ¶
func (s *ServerProxyManager) GetTool(name string) *Tool
func (*ServerProxyManager) Init ¶
func (s *ServerProxyManager) Init(ctx context.Context) error
Init concurrently initializes all of its [ServerProxier]s.
func (*ServerProxyManager) ListTools ¶
func (s *ServerProxyManager) ListTools() []*Tool
type StreamableHTTPServerProxy ¶
type StreamableHTTPServerProxy struct {
// contains filtered or unexported fields
}
func (*StreamableHTTPServerProxy) CallTool ¶
func (p *StreamableHTTPServerProxy) CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
func (*StreamableHTTPServerProxy) GetTool ¶
func (p *StreamableHTTPServerProxy) GetTool(name string) *Tool
func (*StreamableHTTPServerProxy) Init ¶
func (p *StreamableHTTPServerProxy) Init(ctx context.Context) error
func (*StreamableHTTPServerProxy) ListTools ¶
func (p *StreamableHTTPServerProxy) ListTools() []*Tool
func (*StreamableHTTPServerProxy) Name ¶
func (p *StreamableHTTPServerProxy) Name() string
type Tool ¶
type ToolCaller ¶
type ToolCaller interface {
CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
}
ToolCaller is the narrowest interface which describes the behaviour required from mcp.Client, which will normally be passed into Tool for interaction with an MCP server. TODO: don't expose github.com/mark3labs/mcp-go outside this package.