MCP Integration
This guide explains how to use Model Context Protocol (MCP) haystacks in Terraphim via the middleware MCP indexer.
Features
- Transports:
- SSE (localhost) with optional OAuth bearer
- stdio (optional; behind
mcp-rust-sdkfeature) β uses rust-sdkStdioTransportto spawnnpx -y @modelcontextprotocol/server-everything stdio- HTTP fallback invoking
searchthenlist
- HTTP fallback invoking
- Result mapping to
terraphim_types::Document(id, url, title, body, description)
Enable Features
- Default: no MCP
- SSE/HTTP client only:
- Full rust-sdk client (optional):
Start a local Everything Server (SSE)
# Server is running on port 3001Role Config Haystack
Add a haystack with service Mcp and extra parameters:
base_url: e.g.http://127.0.0.1:3001transport:sse|oauth|stdiooauth_token: (optional) whentransport = oauth
Example (Rust test snippet):
new
.with_extra_parameter
.with_extra_parameterLive Test
Behavior
- The indexer probes
/{base}/ssefor reachability when usingtransport = sse. - It then calls
/{base}/searchwith{ query: needle }, falling back to/{base}/list. - JSON arrays or
{ items: [...] }payloads are supported. - Each item is mapped best-effort to
Document.
Rust SDK (optional)
If you enable mcp-rust-sdk, the indexer includes gated functions to:
- Connect via SSE transport using the SDK (
SseTransport+McpService+McpClient) - Connect via stdio to a spawned
server-everything(StdioTransport+McpService+McpClient)
Note: SDK imports may vary by version; code is feature-gated to avoid impacting default builds.