Skip to main content

Module mcp

Module mcp 

Source
Available on crate feature mcp only.
Expand description

MCP (Model Context Protocol) server surface for faucet (issue #420).

A transport-agnostic JSON-RPC 2.0 dispatcher (handle_message) plus the tool implementations (tools). Two front-ends drive it:

  • stdio — the faucet mcp subcommand (crate::commands::mcp), for local agents (Claude Desktop / Code).
  • Streamable HTTP — the /mcp route mounted by faucet serve --mcp, which inherits serve’s bearer-auth + RBAC + audit.

The dispatcher re-exposes existing faucet capabilities (list / schema / scaffold / validate / preview, and a gated run_pipeline) in the shape an LLM agent speaks; it re-implements no pipeline logic. Read-only tools are always available; the mutating run_pipeline tool appears only when the context is constructed with allow_mutations = true (the --allow-mutations flag, ANDed with the caller’s RBAC scope on the HTTP transport).

Modules§

protocol
JSON-RPC 2.0 + MCP protocol types (issue #420).
tools
MCP tool definitions + in-process dispatch (issue #420).

Structs§

McpContext
Everything a tool handler needs, independent of transport.

Functions§

handle_message
Handle one JSON-RPC message. Returns Some(response_json) for a request, or None for a notification (which gets no response). A malformed message yields a JSON-RPC parse/invalid-request error envelope.
install_stderr_tracing
Install a tracing subscriber that writes to stderr — stdout is reserved for the JSON-RPC message stream in faucet mcp (stdio) mode.
serve_stdio
Drive an MCP session over any byte streams: read newline-delimited JSON-RPC from reader, write each response (one JSON object per line) to writer. Blank lines are skipped; notifications produce no output. Returns when the reader hits EOF. The faucet mcp stdio command wraps stdin/stdout with this; tests drive it with in-memory buffers.