# MCP Servers Pi connects to [Model Context Protocol](https://modelcontextprotocol.io) servers over stdio or streamable HTTP and makes their tools and resources available to the model. ## Quick setup Add a local stdio server, check the connection, then start Pi: ```bash pi mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem . pi mcp list pi ``` For a remote server: ```bash pi mcp add docs --url https://example.com/mcp --bearer-token-env-var DOCS_TOKEN pi mcp list ``` These commands add user-level servers by default. Add `--local` or `-l` to write the project configuration instead: ```bash pi mcp add -l tools --env API_KEY='${TOOLS_KEY}' -- uvx tools-mcp ``` Use `/mcp` inside an interactive session to inspect connections, sign in, reconnect, change exposure, or enable and disable servers. Run `/reload` after adding, removing, or changing a server outside the session. ## Configure servers Pi reads user-level servers from `~/.pi/agent/mcp.json` and project servers from `.pi/mcp.json`. Project configuration is read only after [project trust](security.md#understand-project-trust) is granted. A project entry replaces a user-level entry with the same name. The format matches other MCP clients: ```json { "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] }, "docs": { "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer ${DOCS_TOKEN}" }, "description": "Search and read the product documentation" } } } ``` Stdio servers use `command`, `args`, `env`, and `cwd`. Relative `cwd` values resolve against the session directory. A leading `~/` in `command`, an argument, or `cwd` names the home directory. HTTP servers use `url`, `headers`, and `oauth` (see [Authenticate with OAuth](#authenticate-with-oauth)). The legacy SSE transport is not supported. Both server types support: - `timeout`: per-request timeout in seconds (default 60). Progress notifications reset it. - `enabled: false`: keep the entry without connecting to it. - `exposure` and `toolExposure`: control how tools reach the model (see [Control tool exposure](#control-tool-exposure)). - `description`: what the server offers, in a sentence. It lists the server in the system prompt (see [Control tool exposure](#control-tool-exposure)), tool search ranks the server's tools by it, and codemode's `describeNamespace()` returns it. Without it, the first line of the server instructions is used once the server connects. Keep personal servers and servers with credentials in the user-level file. Use the project file only for servers the project requires, and only in trusted projects. ### Configuration rules - Server names may contain only letters, digits, `_`, and `-`. Tools are named `mcp____`, with every character other than letters, digits, and `_` replaced by `_`; tools of a server whose names then collide all get a hash suffix. Server names that differ only in `-` and `_` count as the same server: a second one is rejected, and a `mcp.json` server overrides a registered one. - `type` is optional. A `command` selects stdio and a `url` selects streamable HTTP. When present, `type` must be `stdio`, `http`, or `streamable-http`. - `sse` is rejected. Servers that document an SSE endpoint often also provide streamable HTTP, commonly at `/mcp` instead of `/sse`. - `command` is one executable and `args` contains its arguments. It is not a shell command string. - `env` and `headers` values can use environment variables such as `${GITHUB_TOKEN}`. They can also run a command with `!command`, but the command must make up the whole value, for example `"Authorization": "!echo Bearer $(gh auth token)"`. - Invalid entries are reported and skipped without preventing other servers from connecting. `pi mcp add` and `pi mcp remove` cover common changes from a shell. See [MCP commands](cli.md#mcp-commands) for their options. ### Inspect or change a server `/mcp` lists configured servers with their state, tool count, exposure, and configuration source. Servers that need attention appear first. Select a server to inspect its tools and connection details, reconnect, sign in or out, change exposure, or enable and disable it. Exposure and enabled-state changes are saved to the file that defines the server without replacing unrelated content. Disabled servers remain listed. Outside the interactive TUI, `/mcp` prints server status; `/mcp login `, `/mcp logout `, and `/mcp reconnect ` perform those actions directly. Shell commands work without a session: `pi mcp add`, `pi mcp remove`, `pi mcp list`, `pi mcp login`, and `pi mcp logout`. Shell commands do not load extensions. ### Diagnose connection problems Run `pi mcp list` to connect to every enabled server and print its state, tools, and errors. It exits with status 1 when an entry is invalid or an enabled server is not connected. `/mcp` shows the full connection error and the tail of stderr from a failed stdio server. Pi reports configuration errors, failed connections, and required sign-ins once after startup. Server logging notifications are appended to `~/.pi/agent/mcp.log` as `