# Plan: MCP (Model Context Protocol) Integration

**Goal:** Maven acts as an MCP host — she can connect to external MCP servers (tools, data sources, file systems) via the Model Context Protocol, and expose those capabilities as tool verbs in her allowlist, or use them as context sources for routing/phrasing.

**Done when:**
- `internal/mcp/` package implements an MCP client — connects to MCP servers over stdio or TCP, negotiates protocol version, discovers tools/resources
- MCP-discovered tools are registered as proposed tools (`ProposeTool`) in the store
- User enables them on mavweb (existing `EnableTool` flow)
- MCP resource contents are available as context for the router's `LLMRouter` or the phraser's prompts
- Multiple MCP servers can be configured in `deploy/mavend.json`
- MCP connections are managed (reconnect on drop, timeout, graceful shutdown)

**Scope:**
- New `internal/mcp/` package — protocol client (`github.com/mark3labs/mcp-go` or raw JSON-RPC over stdio/TCP)
- New `cmd/mcphost/` or built into `cmd/mavend/` — MCP server manager goroutine
- Config extension: `mcp_servers` array in `config.Config` — `{name, command, args, env, enabled}`
- IPC extension: `MethodListMCPTools`, `MethodListMCPResources`, `MethodCallMCPTool`
- Reuses `internal/tool/Executor` and `internal/router` seams

**Steps:**
1. Research MCP protocol spec and pick a Go client library (`github.com/mark3labs/mcp-go` exists as of 2025, or implement raw JSON-RPC 2.0 over stdio/TCP)
2. Create `internal/mcp/client.go` — `Client` struct handling stdio subprocess lifecycle: spawn, negotiate protocol version (`initialize` handshake), `ListTools`, `CallTool`
3. Create `internal/mcp/manager.go` — `Manager` that reads `mcp_servers` config, starts/stops per-server clients, exposes a consolidated tool list
4. Wire MCP-discovered tools into `ProposeTool` (same flow as `cmd/mavend/voice.go:proposeGap`)
5. Add resource content fetching — `ReadResource` returns text content that can be injected into LLM prompts
6. Add IPC methods `MethodListMCPTools`, `MethodListMCPResources`, `MethodCallMCPTool` to `internal/ipc/api.go`
7. Expose MCP tools in mavweb UI — new `/tools/mcp` page
8. Add `mcp_servers` block to `config.Config` and `deploy/mavend.json`
9. Test with a local MCP demo server (e.g., `mcp-server-sqlite` or a custom echo server)
