MCP¶
Pegg is an MCP (Model Context Protocol) client. It connects to MCP servers at startup, discovers their tools, and exposes them to agents alongside the built-in tools.
Configuration¶
Add servers to the mcp_servers map in ~/.pegg/pegg.json:
{
"mcp_servers": {
"db": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": { "DEBUG": "true" }
},
"remote": {
"type": "streamable-http",
"url": "https://example.com/mcp",
"headers": { "Authorization": "Bearer token" }
},
"legacy": {
"type": "sse",
"url": "https://example.com/sse"
}
}
}
Project entries override global entries with the same name.
Server options¶
| Key | Type | Description |
|---|---|---|
type |
string | Transport: stdio, sse, or streamable-http. When omitted, url selects legacy SSE and command selects stdio |
command |
string | Executable to spawn (stdio transport) |
args |
string[] | Command arguments |
env |
object | Extra environment variables, merged over the inherited environment |
url |
string | Remote endpoint (SSE or Streamable HTTP) |
headers |
object | HTTP headers sent with SSE and Streamable HTTP requests |
A stdio server must define command; a remote server must define url. The
type aliases local (stdio), http (legacy SSE), and streamable
(streamable-http) are accepted for compatibility, but new configurations should
use the canonical names.
Transports¶
stdio¶
Pegg spawns command args... as a child process:
- The child inherits Pegg's full environment;
enventries override individual variables. - The child's stderr is forwarded to Pegg's stderr.
- Messages are newline-delimited JSON (with optional
Content-Lengthframing), max 16 MiB per frame. - The child is terminated with SIGTERM when Pegg shuts down.
SSE (legacy)¶
Pegg opens a GET request with Accept: text/event-stream and the configured
headers. The server must first emit an endpoint event telling Pegg where to
POST messages. Subsequent requests include the Mcp-Session-Id header when the
server provides one. Responses arrive as message events.
Set "type": "sse" explicitly, or omit type on a server that only has a url.
The http CLI/type alias also selects this legacy transport.
Streamable HTTP¶
Set "type": "streamable-http" for MCP servers implementing the
Streamable HTTP
transport. Pegg uses protocol version 2025-06-18 for this transport and:
POSTs each JSON-RPC message tourlwithAccept: application/json, text/event-stream. A response may be a single JSON object, a batch array, an SSE stream, or empty (202/204) for notifications.- Captures
Mcp-Session-Idfrom responses and sends it on every subsequent request and on stream reconnects. - Sends
MCP-Protocol-Versionafter initialization. - Opens an optional
GETSSE stream for server-initiated notifications, resuming withLast-Event-IDafter a reconnect. Servers that reject the stream with405are supported; POST remains the request path. - Re-initializes once and retries when the server reports an expired session
(
404). - Sends a best-effort
DELETEon shutdown to end the session.
Lifecycle¶
- At startup, one goroutine per configured server connects with a 15 second
timeout: transport connect →
initialize→tools/list. - Every discovered tool is registered in the global tool registry as
<server>__<tool>(double underscore). Names are guaranteed not to collide between servers. - A server that fails to connect is logged as a warning and skipped; the rest of Pegg continues normally.
- Before resolving tools, an agent run waits up to 10 seconds for in-flight server connections, so tools from slow servers are included in the first request. The agent also re-syncs discovered tools before every model turn, so a server that finishes connecting mid-run becomes available on the next turn.
- Adding, changing, or removing a server through the settings API reconnects the affected server immediately; no restart is required.
- On shutdown, every MCP tool is unregistered and every connection is closed.
Streamable HTTP servers use MCP protocol version 2025-06-18; stdio and legacy
SSE servers use 2024-11-05. Pegg accepts the version returned by the server
during initialize.
Managing servers¶
pegg mcp list # all servers, global and project
pegg mcp list --project # project only
pegg mcp tools # live tools from connected servers
pegg mcp tools --server db # filter by server
Adding a server¶
Interactive:
Fully specified:
# Local stdio server
pegg mcp add --project --name db --transport stdio \
--command npx --arg -y --arg @modelcontextprotocol/server-postgres \
--env DEBUG=true
# Remote Streamable HTTP server
pegg mcp add --global --name remote --transport streamable-http \
--url https://example.com/mcp \
--header Authorization="Bearer token"
# Legacy remote SSE server
pegg mcp add --global --name legacy --transport sse \
--url https://example.com/sse \
--header Authorization="Bearer token"
| Flag | Description |
|---|---|
--global / --project |
Where to write the server |
--name |
Server name |
--transport |
stdio, sse (legacy), or streamable-http (aliases: local, http) |
--command |
Executable for stdio servers |
--arg |
Argument (repeatable) |
--env |
KEY=VALUE environment variable (repeatable) |
--url |
Endpoint for SSE or Streamable HTTP servers |
--header |
KEY=VALUE request header (repeatable) |
The interactive flow offers common header presets: Authorization, X-API-Key,
Cookie, and User-Agent.
Installing from the catalog¶
The Pegg catalog lists vetted MCP servers. Search, inspect, and install them without assembling the command by hand:
pegg mcp search github
pegg mcp search github --official --limit 5
pegg mcp info github
# Global config (default)
pegg mcp install github --env GITHUB_TOKEN=ghp_...
# Project .mcp.json
pegg mcp install github --project --name gh --env GITHUB_TOKEN=ghp_...
| Flag | Description |
|---|---|
--global |
Write to ~/.pegg/pegg.json (default) |
--project |
Write to .mcp.json in the current directory |
--name |
Server name; defaults to the catalog id |
--env KEY=VALUE |
Value for a ${KEY} placeholder (repeatable) |
--header KEY=VALUE |
Override a header on a remote server (repeatable) |
--dry-run |
Print the config JSON without writing |
--yes |
Skip the interactive confirmation |
Catalog entries may use ${VAR} placeholders in the command, arguments,
environment values, URL, and headers. mcp install resolves them in this order:
--env KEY=VALUE- The process environment
- A masked prompt when stdin is a terminal
On a non-interactive terminal, missing values produce an error listing the exact
keys and the flags to use. Values are never printed; --dry-run redacts resolved
secrets back to their ${VAR} placeholders.
Set PEGG_CATALOG_API to use a different catalog endpoint (for example a local hub
API). PEGG_SKILLS_API is still honored as a fallback.
Removing a server¶
If the server exists in both scopes, Pegg asks which one to remove. If it exists in only one, that scope is used automatically.
Using MCP tools¶
MCP tools behave like built-in tools. The model sees them under their
server__tool names, and they are subject to the permission middleware's
permission.default mode unless overridden by a rule.
Tool results are returned as text; image content is summarized as [image data].
A tool result flagged isError is surfaced as a tool error.
TUI¶
Open Settings with Ctrl+P and switch to the MCP tab. Each server shows its
tool count and connection state (connected / not connected). Selecting a server
opens a sub-list of its tools.
Troubleshooting¶
Common issues:
- Command not found — the executable must be on
PATHfor the Pegg process. - SSE server never becomes ready — the server must emit the
endpointevent. - Tools missing — the server connected but
tools/listreturned nothing, or the connection failed duringinitialize. Check the logs for a warning line.