Documentation
¶
Index ¶
- Constants
- func ParsePrefixedTool(prefixed string) (agentName, toolName string, err error)
- func PrefixTool(agentName, toolName string) string
- type AgentClient
- type Capabilities
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
- func (c *Client) Endpoint() string
- func (c *Client) Initialize(ctx context.Context) error
- func (c *Client) IsInitialized() bool
- func (c *Client) Name() string
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) RefreshTools(ctx context.Context) error
- func (c *Client) ServerInfo() ServerInfo
- func (c *Client) Tools() []Tool
- type ClientInfo
- type Content
- type Error
- type Gateway
- func (g *Gateway) GetAgentAllowedServers(agentName string) []string
- func (g *Gateway) HandleInitialize(params InitializeParams) (*InitializeResult, error)
- func (g *Gateway) HandleToolsCall(ctx context.Context, params ToolCallParams) (*ToolCallResult, error)
- func (g *Gateway) HandleToolsCallForAgent(ctx context.Context, agentName string, params ToolCallParams) (*ToolCallResult, error)
- func (g *Gateway) HandleToolsList() (*ToolsListResult, error)
- func (g *Gateway) HandleToolsListForAgent(agentName string) (*ToolsListResult, error)
- func (g *Gateway) RefreshAllTools(ctx context.Context) error
- func (g *Gateway) RegisterAgent(name string, uses []string)
- func (g *Gateway) RegisterMCPServer(ctx context.Context, cfg MCPServerConfig) error
- func (g *Gateway) Router() *Router
- func (g *Gateway) ServerInfo() ServerInfo
- func (g *Gateway) Sessions() *SessionManager
- func (g *Gateway) SetDockerClient(cli dockerclient.DockerClient)
- func (g *Gateway) SetLogger(logger *slog.Logger)
- func (g *Gateway) Status() []MCPServerStatus
- func (g *Gateway) UnregisterAgent(name string)
- func (g *Gateway) UnregisterMCPServer(name string)
- type Handler
- type InitializeParams
- type InitializeResult
- type InputSchemaObject
- type MCPServerConfig
- type MCPServerStatus
- type ProcessClient
- func (c *ProcessClient) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
- func (c *ProcessClient) Close() error
- func (c *ProcessClient) Connect(ctx context.Context) error
- func (c *ProcessClient) Initialize(ctx context.Context) error
- func (c *ProcessClient) IsInitialized() bool
- func (c *ProcessClient) Name() string
- func (c *ProcessClient) RefreshTools(ctx context.Context) error
- func (c *ProcessClient) ServerInfo() ServerInfo
- func (c *ProcessClient) Tools() []Tool
- type PromptsCapability
- type Property
- type Request
- type ResourcesCapability
- type Response
- type Router
- func (r *Router) AddClient(client AgentClient)
- func (r *Router) AggregatedTools() []Tool
- func (r *Router) Clients() []AgentClient
- func (r *Router) GetClient(name string) AgentClient
- func (r *Router) RefreshTools()
- func (r *Router) RemoveClient(name string)
- func (r *Router) RouteToolCall(prefixedName string) (AgentClient, string, error)
- type SSEServer
- type SSESession
- type ServerInfo
- type Session
- type SessionManager
- type StdioClient
- func (c *StdioClient) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
- func (c *StdioClient) Close() error
- func (c *StdioClient) Connect(ctx context.Context) error
- func (c *StdioClient) Initialize(ctx context.Context) error
- func (c *StdioClient) IsInitialized() bool
- func (c *StdioClient) Name() string
- func (c *StdioClient) RefreshTools(ctx context.Context) error
- func (c *StdioClient) ServerInfo() ServerInfo
- func (c *StdioClient) Tools() []Tool
- type Tool
- type ToolCallParams
- type ToolCallResult
- type ToolsCapability
- type ToolsListResult
- type Transport
Constants ¶
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
Standard JSON-RPC error codes
const ToolNameDelimiter = "__"
ToolNameDelimiter is the separator between agent name and tool name in prefixed tool names. Format: "agentname__toolname" Uses double underscore to be compatible with Claude Desktop's tool name validation: ^[a-zA-Z0-9_-]{1,64}$
Variables ¶
This section is empty.
Functions ¶
func ParsePrefixedTool ¶
ParsePrefixedTool parses a prefixed tool name into agent and tool names.
func PrefixTool ¶
PrefixTool creates a prefixed tool name: "agent__tool"
Types ¶
type AgentClient ¶
type AgentClient interface {
Name() string
Initialize(ctx context.Context) error
RefreshTools(ctx context.Context) error
Tools() []Tool
CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
IsInitialized() bool
ServerInfo() ServerInfo
}
AgentClient is the interface for communicating with MCP agents.
type Capabilities ¶
type Capabilities struct {
Tools *ToolsCapability `json:"tools,omitempty"`
Resources *ResourcesCapability `json:"resources,omitempty"`
Prompts *PromptsCapability `json:"prompts,omitempty"`
}
Capabilities describes what the server/client can do.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with a downstream MCP server.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
CallTool invokes a tool on the downstream agent.
func (*Client) Initialize ¶
Initialize performs the MCP initialize handshake.
func (*Client) IsInitialized ¶
IsInitialized returns whether the client has been initialized.
func (*Client) RefreshTools ¶
RefreshTools fetches the current tool list from the agent.
func (*Client) ServerInfo ¶
func (c *Client) ServerInfo() ServerInfo
ServerInfo returns the server information.
type ClientInfo ¶
ClientInfo contains information about the MCP client.
type Content ¶
Content represents content in a tool response.
func NewTextContent ¶
NewTextContent creates a text content item.
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error represents a JSON-RPC 2.0 error.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway aggregates multiple MCP servers into a single endpoint.
func (*Gateway) GetAgentAllowedServers ¶
GetAgentAllowedServers returns the MCP servers an agent can access. Returns nil if the agent is not registered (allows all for backward compatibility).
func (*Gateway) HandleInitialize ¶
func (g *Gateway) HandleInitialize(params InitializeParams) (*InitializeResult, error)
HandleInitialize handles the initialize request.
func (*Gateway) HandleToolsCall ¶
func (g *Gateway) HandleToolsCall(ctx context.Context, params ToolCallParams) (*ToolCallResult, error)
HandleToolsCall routes a tool call to the appropriate MCP server.
func (*Gateway) HandleToolsCallForAgent ¶
func (g *Gateway) HandleToolsCallForAgent(ctx context.Context, agentName string, params ToolCallParams) (*ToolCallResult, error)
HandleToolsCallForAgent routes a tool call with agent access validation.
func (*Gateway) HandleToolsList ¶
func (g *Gateway) HandleToolsList() (*ToolsListResult, error)
HandleToolsList returns all aggregated tools.
func (*Gateway) HandleToolsListForAgent ¶
func (g *Gateway) HandleToolsListForAgent(agentName string) (*ToolsListResult, error)
HandleToolsListForAgent returns tools filtered by agent access permissions.
func (*Gateway) RefreshAllTools ¶
RefreshAllTools refreshes tools from all registered MCP servers.
func (*Gateway) RegisterAgent ¶
RegisterAgent registers an agent and its allowed MCP servers.
func (*Gateway) RegisterMCPServer ¶
func (g *Gateway) RegisterMCPServer(ctx context.Context, cfg MCPServerConfig) error
RegisterMCPServer registers and initializes an MCP server.
func (*Gateway) ServerInfo ¶
func (g *Gateway) ServerInfo() ServerInfo
ServerInfo returns the gateway server info.
func (*Gateway) Sessions ¶
func (g *Gateway) Sessions() *SessionManager
Sessions returns the session manager.
func (*Gateway) SetDockerClient ¶
func (g *Gateway) SetDockerClient(cli dockerclient.DockerClient)
SetDockerClient sets the Docker client for stdio transport.
func (*Gateway) SetLogger ¶
SetLogger sets the logger for gateway operations. If nil is passed, logging is disabled (default).
func (*Gateway) Status ¶
func (g *Gateway) Status() []MCPServerStatus
Status returns status of all registered MCP servers. Note: This only returns actual MCP servers, not A2A adapters or other clients added directly to the router.
func (*Gateway) UnregisterAgent ¶
UnregisterAgent removes an agent's access configuration.
func (*Gateway) UnregisterMCPServer ¶
UnregisterMCPServer removes an MCP server from the gateway.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP handlers for the MCP gateway.
func NewHandler ¶
NewHandler creates a new MCP HTTP handler.
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion string `json:"protocolVersion"`
ClientInfo ClientInfo `json:"clientInfo"`
Capabilities Capabilities `json:"capabilities"`
}
InitializeParams contains parameters for the initialize request.
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
ServerInfo ServerInfo `json:"serverInfo"`
Capabilities Capabilities `json:"capabilities"`
}
InitializeResult is the response to initialize.
type InputSchemaObject ¶
type InputSchemaObject struct {
Type string `json:"type"`
Properties map[string]Property `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
}
InputSchemaObject is a helper for building simple input schemas. Use this when creating tools programmatically (e.g., A2A skill adapters). For MCP tools received from servers, use json.RawMessage directly to preserve the full JSON Schema without loss.
type MCPServerConfig ¶
type MCPServerConfig struct {
Name string
Transport Transport
Endpoint string // For HTTP/SSE transport
ContainerID string // For Docker Stdio transport
External bool // True for external URL servers (no container)
LocalProcess bool // True for local process servers (no container)
SSH bool // True for SSH servers (remote process over SSH)
Command []string // For local process or SSH transport
WorkDir string // For local process transport
Env map[string]string // For local process or SSH transport
SSHHost string // SSH hostname (for SSH servers)
SSHUser string // SSH username (for SSH servers)
SSHPort int // SSH port (for SSH servers, 0 = default 22)
SSHIdentityFile string // SSH identity file path (for SSH servers)
}
MCPServerConfig contains configuration for connecting to an MCP server.
type MCPServerStatus ¶
type MCPServerStatus struct {
Name string `json:"name"`
Transport Transport `json:"transport"`
Endpoint string `json:"endpoint,omitempty"`
ContainerID string `json:"containerId,omitempty"`
Initialized bool `json:"initialized"`
ToolCount int `json:"toolCount"`
Tools []string `json:"tools"`
External bool `json:"external"` // True for external URL servers
LocalProcess bool `json:"localProcess"` // True for local process servers
SSH bool `json:"ssh"` // True for SSH servers
SSHHost string `json:"sshHost,omitempty"` // SSH hostname
}
MCPServerStatus returns status information about registered MCP servers.
type ProcessClient ¶
type ProcessClient struct {
// contains filtered or unexported fields
}
ProcessClient communicates with an MCP server via a local process stdin/stdout.
func NewProcessClient ¶
func NewProcessClient(name string, command []string, workDir string, env map[string]string) *ProcessClient
NewProcessClient creates a new process-based MCP client. The command is executed with the given working directory and environment. Environment variables are merged with the current process environment.
func (*ProcessClient) CallTool ¶
func (c *ProcessClient) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
CallTool invokes a tool on the agent.
func (*ProcessClient) Close ¶
func (c *ProcessClient) Close() error
Close terminates the process gracefully. Sends SIGTERM, waits up to 5 seconds, then sends SIGKILL if still running.
func (*ProcessClient) Connect ¶
func (c *ProcessClient) Connect(ctx context.Context) error
Connect starts the process and attaches to its stdin/stdout.
func (*ProcessClient) Initialize ¶
func (c *ProcessClient) Initialize(ctx context.Context) error
Initialize performs the MCP initialize handshake.
func (*ProcessClient) IsInitialized ¶
func (c *ProcessClient) IsInitialized() bool
IsInitialized returns whether the client has been initialized.
func (*ProcessClient) RefreshTools ¶
func (c *ProcessClient) RefreshTools(ctx context.Context) error
RefreshTools fetches the current tool list from the agent.
func (*ProcessClient) ServerInfo ¶
func (c *ProcessClient) ServerInfo() ServerInfo
ServerInfo returns the server information.
func (*ProcessClient) Tools ¶
func (c *ProcessClient) Tools() []Tool
Tools returns the cached tools for this agent.
type PromptsCapability ¶
type PromptsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
PromptsCapability indicates prompts support.
type Property ¶
type Property struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
}
Property describes a single property in an input schema.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID *json.RawMessage `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request.
type ResourcesCapability ¶
type ResourcesCapability struct {
Subscribe bool `json:"subscribe,omitempty"`
ListChanged bool `json:"listChanged,omitempty"`
}
ResourcesCapability indicates resources support.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID *json.RawMessage `json:"id,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response.
func NewErrorResponse ¶
func NewErrorResponse(id *json.RawMessage, code int, message string) Response
NewErrorResponse creates a JSON-RPC error response.
func NewSuccessResponse ¶
func NewSuccessResponse(id *json.RawMessage, result any) Response
NewSuccessResponse creates a JSON-RPC success response.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router routes tool calls to the appropriate agent.
func (*Router) AddClient ¶
func (r *Router) AddClient(client AgentClient)
AddClient adds an agent client to the router.
func (*Router) AggregatedTools ¶
AggregatedTools returns all tools from all agents with prefixed names.
func (*Router) Clients ¶
func (r *Router) Clients() []AgentClient
Clients returns all registered clients.
func (*Router) GetClient ¶
func (r *Router) GetClient(name string) AgentClient
GetClient returns a client by agent name.
func (*Router) RefreshTools ¶
func (r *Router) RefreshTools()
RefreshTools updates the tool registry from all agents.
func (*Router) RemoveClient ¶
RemoveClient removes an agent client from the router.
func (*Router) RouteToolCall ¶
func (r *Router) RouteToolCall(prefixedName string) (AgentClient, string, error)
RouteToolCall routes a tool call to the appropriate agent.
type SSEServer ¶
type SSEServer struct {
// contains filtered or unexported fields
}
SSEServer handles Server-Sent Events connections for MCP.
func NewSSEServer ¶
NewSSEServer creates a new SSE server.
func (*SSEServer) HandleMessage ¶
func (s *SSEServer) HandleMessage(w http.ResponseWriter, r *http.Request)
HandleMessage handles POST requests to /message for a specific session.
func (*SSEServer) ServeHTTP ¶
func (s *SSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles SSE connections at /sse.
func (*SSEServer) SessionCount ¶
SessionCount returns the number of active sessions.
type SSESession ¶
type SSESession struct {
ID string
Writer http.ResponseWriter
Flusher http.Flusher
Done chan struct{}
MessageID atomic.Int64
}
SSESession represents a connected SSE client.
type ServerInfo ¶
ServerInfo contains information about the MCP server.
type Session ¶
type Session struct {
ID string
ClientInfo ClientInfo
Initialized bool
CreatedAt time.Time
LastSeen time.Time
}
Session represents an MCP client session.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages client sessions.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager.
func (*SessionManager) Cleanup ¶
func (m *SessionManager) Cleanup(maxAge time.Duration) int
Cleanup removes stale sessions older than the given duration.
func (*SessionManager) Create ¶
func (m *SessionManager) Create(clientInfo ClientInfo) *Session
Create creates a new session.
func (*SessionManager) Delete ¶
func (m *SessionManager) Delete(id string)
Delete removes a session.
func (*SessionManager) Get ¶
func (m *SessionManager) Get(id string) *Session
Get retrieves a session by ID.
func (*SessionManager) Touch ¶
func (m *SessionManager) Touch(id string)
Touch updates the last seen time for a session.
type StdioClient ¶
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient communicates with an MCP server via container stdin/stdout.
func NewStdioClient ¶
func NewStdioClient(name, containerID string, cli dockerclient.DockerClient) *StdioClient
NewStdioClient creates a new stdio-based MCP client.
func (*StdioClient) CallTool ¶
func (c *StdioClient) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolCallResult, error)
CallTool invokes a tool on the agent.
func (*StdioClient) Connect ¶
func (c *StdioClient) Connect(ctx context.Context) error
Connect attaches to the container's stdin/stdout.
func (*StdioClient) Initialize ¶
func (c *StdioClient) Initialize(ctx context.Context) error
Initialize performs the MCP initialize handshake.
func (*StdioClient) IsInitialized ¶
func (c *StdioClient) IsInitialized() bool
IsInitialized returns whether the client has been initialized.
func (*StdioClient) RefreshTools ¶
func (c *StdioClient) RefreshTools(ctx context.Context) error
RefreshTools fetches the current tool list from the agent.
func (*StdioClient) ServerInfo ¶
func (c *StdioClient) ServerInfo() ServerInfo
ServerInfo returns the server information.
func (*StdioClient) Tools ¶
func (c *StdioClient) Tools() []Tool
Tools returns the cached tools for this agent.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema"`
}
Tool represents an MCP tool definition.
type ToolCallParams ¶
type ToolCallParams struct {
Name string `json:"name"`
Arguments map[string]any `json:"arguments,omitempty"`
}
ToolCallParams contains parameters for tools/call.
type ToolCallResult ¶
type ToolCallResult struct {
Content []Content `json:"content"`
IsError bool `json:"isError,omitempty"`
}
ToolCallResult is the response to tools/call.
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
ToolsCapability indicates tools support.
type ToolsListResult ¶
type ToolsListResult struct {
Tools []Tool `json:"tools"`
NextCursor *string `json:"nextCursor,omitempty"`
}
ToolsListResult is the response to tools/list.