Documentation
¶
Overview ¶
cmd/celeste/tools/mcp/adapter.go
cmd/celeste/tools/mcp/client.go
cmd/celeste/tools/mcp/config.go
cmd/celeste/tools/mcp/discovery.go
cmd/celeste/tools/mcp/jsonrpc.go
cmd/celeste/tools/mcp/manager.go
cmd/celeste/tools/mcp/sse.go
cmd/celeste/tools/mcp/stdio.go
cmd/celeste/tools/mcp/transport.go
Index ¶
- func DefaultConfigPath() string
- func DiscoverAndRegister(ctx context.Context, client *Client, registry *tools.Registry, ...) error
- type Client
- type ContentBlock
- type ErrorObject
- type MCPConfig
- type MCPTool
- func (m *MCPTool) Description() string
- func (m *MCPTool) Execute(ctx context.Context, input map[string]any, progress chan<- tools.ProgressEvent) (tools.ToolResult, error)
- func (m *MCPTool) InterruptBehavior() tools.InterruptBehavior
- func (m *MCPTool) IsConcurrencySafe(input map[string]any) bool
- func (m *MCPTool) IsReadOnly() bool
- func (m *MCPTool) Name() string
- func (m *MCPTool) Parameters() json.RawMessage
- func (m *MCPTool) ValidateInput(input map[string]any) error
- type MCPToolDef
- type Manager
- type Notification
- type Request
- type Response
- type SSETransport
- type ServerConfig
- type ServerInfo
- type StdioTransport
- type ToolCallResult
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
func DefaultConfigPath() string
DefaultConfigPath returns the default path for the MCP configuration file.
func DiscoverAndRegister ¶
func DiscoverAndRegister(ctx context.Context, client *Client, registry *tools.Registry, serverName string) error
DiscoverAndRegister queries the MCP server for available tools via tools/list, creates an MCPTool adapter for each, and registers them in the registry. The serverName is recorded in each tool's metadata for debugging and display.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a high-level MCP client that handles the protocol handshake, tool discovery, and tool execution over a Transport.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]any) (string, error)
CallTool executes a tool on the MCP server and returns the text result. Multiple text content blocks are joined with newlines.
func (*Client) Initialize ¶
Initialize performs the MCP initialize handshake. Sends initialize request, validates the server's protocol version, then sends notifications/initialized.
func (*Client) ListTools ¶
func (c *Client) ListTools(ctx context.Context) ([]MCPToolDef, error)
ListTools discovers available tools from the MCP server.
func (*Client) ServerName ¶
ServerName returns the server's name after initialization.
type ContentBlock ¶ added in v1.8.0
ContentBlock is a single content item in a tool call response.
type ErrorObject ¶
type ErrorObject struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
ErrorObject is the error payload in a JSON-RPC 2.0 response.
func (*ErrorObject) Error ¶
func (e *ErrorObject) Error() string
Error implements the error interface.
type MCPConfig ¶
type MCPConfig struct {
Servers map[string]ServerConfig `json:"mcpServers"`
}
MCPConfig is the top-level configuration for MCP servers. Loaded from ~/.celeste/mcp.json.
func LoadConfig ¶
LoadConfig reads and parses the MCP configuration from a JSON file. If the file does not exist, returns an empty config (not an error). This allows celeste to start without any MCP servers configured.
type MCPTool ¶
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool wraps an MCP tool definition and implements the tools.Tool interface. It delegates execution to the MCP Client, bridging external MCP servers into celeste's unified tool system.
func NewMCPTool ¶
func NewMCPTool(def MCPToolDef, client *Client, serverName string) *MCPTool
NewMCPTool creates a new MCPTool adapter for the given MCP tool definition.
func (*MCPTool) Description ¶
func (*MCPTool) Execute ¶
func (m *MCPTool) Execute(ctx context.Context, input map[string]any, progress chan<- tools.ProgressEvent) (tools.ToolResult, error)
Execute calls the MCP tool via the client and returns the result. Server-side errors are returned as ToolResult with Error=true so the LLM can see and react to the error message.
func (*MCPTool) InterruptBehavior ¶
func (m *MCPTool) InterruptBehavior() tools.InterruptBehavior
func (*MCPTool) IsConcurrencySafe ¶
IsConcurrencySafe returns false because MCP tool calls go over a shared transport and we cannot guarantee the server handles concurrent calls safely.
func (*MCPTool) IsReadOnly ¶
IsReadOnly returns false because we cannot know if an MCP tool mutates state.
func (*MCPTool) Parameters ¶
func (m *MCPTool) Parameters() json.RawMessage
type MCPToolDef ¶
type MCPToolDef struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"`
}
MCPToolDef is a tool definition returned by the MCP server.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the lifecycle of all MCP server connections. It loads configuration, connects to servers, discovers tools, and registers them in the tool registry.
func NewManager ¶
NewManager creates a new MCP Manager. configPath is the path to the MCP configuration file (e.g., ~/.celeste/mcp.json). registry is the tool registry where discovered MCP tools will be registered.
func (*Manager) ServerStatus ¶
func (m *Manager) ServerStatus() []ServerInfo
ServerStatus returns health information for all connected MCP servers.
func (*Manager) Start ¶
Start loads the MCP configuration, connects to all configured servers, discovers their tools, and registers them in the tool registry. If the config file does not exist, it returns nil (no MCP configured). If a server fails to connect, it logs a warning and continues with others.
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Notification is a JSON-RPC 2.0 notification (no ID, no response expected).
func NewNotification ¶
func NewNotification(method string) *Notification
NewNotification creates a JSON-RPC 2.0 notification (no ID).
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request is a JSON-RPC 2.0 request.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID json.Number `json:"id,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *ErrorObject `json:"error,omitempty"`
}
Response is a JSON-RPC 2.0 response.
type SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport communicates with an MCP server over HTTP Server-Sent Events. Requests are sent via POST to the server's endpoint URL. Responses are received via an SSE event stream from a GET connection.
func NewSSETransport ¶
func NewSSETransport(url string) (*SSETransport, error)
NewSSETransport connects to an MCP server's SSE endpoint. url is the base URL of the MCP server (e.g., "http://localhost:3000/sse").
func (*SSETransport) Close ¶
func (t *SSETransport) Close() error
Close shuts down the SSE connection.
func (*SSETransport) Receive ¶
func (t *SSETransport) Receive() (*Response, error)
Receive reads the next JSON-RPC response from the SSE event stream.
func (*SSETransport) Send ¶
func (t *SSETransport) Send(req *Request) error
Send sends a JSON-RPC request via HTTP POST to the server's endpoint.
func (*SSETransport) SendNotification ¶
func (t *SSETransport) SendNotification(notif *Notification) error
SendNotification sends a JSON-RPC notification via HTTP POST.
type ServerConfig ¶
type ServerConfig struct {
// Transport is "stdio" or "sse". Defaults to "stdio" if not set.
Transport string `json:"transport"`
// Command is the executable to spawn (stdio transport only).
Command string `json:"command,omitempty"`
// Args are command-line arguments (stdio transport only).
Args []string `json:"args,omitempty"`
// URL is the SSE endpoint URL (sse transport only).
URL string `json:"url,omitempty"`
// Env is a map of environment variables passed to the child process.
// Values support ${VAR} expansion from the host environment.
Env map[string]string `json:"env,omitempty"`
}
ServerConfig defines how to connect to a single MCP server.
type ServerInfo ¶
ServerInfo contains health/status information for a connected MCP server.
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport communicates with an MCP server via a child process's stdin and stdout. Each JSON-RPC message is a single line of JSON.
func NewStdioTransport ¶
func NewStdioTransport(command string, args []string, env map[string]string) (*StdioTransport, error)
NewStdioTransport spawns a child process and connects to its stdin/stdout. command is the executable to run (e.g., "npx", "python3"). args are the command-line arguments. env is an optional map of environment variables (supports ${VAR} expansion).
func (*StdioTransport) Close ¶
func (t *StdioTransport) Close() error
Close shuts down the child process and closes pipes.
func (*StdioTransport) Receive ¶
func (t *StdioTransport) Receive() (*Response, error)
Receive reads the next JSON line from stdout and parses it as a Response.
func (*StdioTransport) Send ¶
func (t *StdioTransport) Send(req *Request) error
Send sends a JSON-RPC request as a single JSON line to the child process stdin.
func (*StdioTransport) SendNotification ¶
func (t *StdioTransport) SendNotification(notif *Notification) error
SendNotification sends a JSON-RPC notification as a single JSON line.
type ToolCallResult ¶ added in v1.8.0
type ToolCallResult struct {
Content []ContentBlock `json:"content"`
}
ToolCallResult is the server's response to tools/call.
type Transport ¶
type Transport interface {
// Send sends a JSON-RPC request to the server.
// For requests, the caller should subsequently call Receive to get the response.
Send(req *Request) error
// SendNotification sends a JSON-RPC notification (no response expected).
SendNotification(notif *Notification) error
// Receive reads the next JSON-RPC response from the server.
// Blocks until a response is available or the transport is closed.
Receive() (*Response, error)
// Close shuts down the transport, releasing all resources.
Close() error
}
Transport is the abstraction over MCP communication channels. Implementations handle the physical sending and receiving of JSON-RPC messages over stdio (child process) or SSE (HTTP).