Documentation
¶
Overview ¶
Package mcphub manages multiple MCP server connections and provides unified tool discovery and dispatch for the dscli tool framework.
Architecture ¶
Agent tool call toolcall.HandleToolCall
│ │
▼ ▼
┌──────────────────────────────────────┐
│ mcphub.Dispatch │
│ │
│ "lightpanda_markdown" → parse │
│ server="lightpanda" │
│ tool="markdown" │
│ │ │
│ ▼ │
│ lightpanda MCPClient.CallTool │
└──────────────────────────────────────┘
Configuration ¶
MCP server definitions are in the `mcp-servers` block of config.dscli:
mcp-servers {
server-id {
name = lightpanda
type = local
command = lightpanda
args = [mcp]
enabled = true
}
}
Built-in servers:
- lightpanda: web page interaction via LightPanda MCP
User-defined servers are defined in the mcp-servers config block.
Package mcphub manages multiple MCP server connections and provides unified tool discovery and dispatch for the dscli tool framework.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
Dispatch routes a tool call to the correct MCP server based on the tool name prefix. The tool name format is "serverName_toolName".
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages multiple MCP server connections.
func (*Hub) SwitchServerTransport ¶
SwitchServerTransport replaces a server's connection with a new one that matches the specified target transport type ("local" or "cloud"). This allows switching between stdio and SSE transports at runtime without restarting the application.
The new connection is validated by listing tools before replacing the old one. If validation fails, the old connection is preserved.
type MCPClient ¶
type MCPClient struct {
// contains filtered or unexported fields
}
MCPClient wraps an MCP session. It manages the lifecycle of an MCP server subprocess, providing a simple interface for tool calls.
The client is safe for concurrent use (calls are serialized through an internal mutex because stdio transport cannot safely multiplex writes).
func NewMCPClient ¶
NewMCPClient starts an MCP server subprocess and connects to it. command is the executable path, args are the command-line arguments. The caller must call Close when done.
func NewSSEMCPClient ¶
NewSSEMCPClient connects to an MCP server over SSE. The caller must call Close when done.
func (*MCPClient) CallTool ¶
CallTool calls a tool by name with the given arguments. The caller is responsible for calling Close after finishing.
type MCPToolError ¶
type MCPToolError struct {
Tool string // name of the tool that failed
Content []mcp.Content // original response content, preserved for debugging
}
MCPToolError is returned when an MCP tool call completes with IsError=true. Unlike a transport-level error (which would be returned as a Go error directly), this indicates the tool ran but its operation failed (e.g., URL unreachable).
func (*MCPToolError) Error ¶
func (e *MCPToolError) Error() string
type ServerConfig ¶
type ServerConfig struct {
Name string // logical server name; set from map key if empty
Type string // "local" (stdio) or "cloud" (SSE); default "local"
Command string // executable (stdio) or URL (http/https)
Args []string // command-line args (stdio) or query key=value pairs (SSE)
Enabled bool
}
ServerConfig defines an MCP server connection.
func (ServerConfig) IsSSE ¶
func (s ServerConfig) IsSSE() bool
IsSSE reports whether this server uses SSE transport. Transport type is determined by the Type field:
- "cloud" → SSE transport
- otherwise → stdio transport (subprocess)