# MCP servers
pic connects to [Model Context Protocol](https://modelcontextprotocol.io) servers and offers their
tools to the model beside its own.
## Add a server
`pic mcp add` takes the line a server's README gives for Pi or for Claude Code (the second line
below), so a pasted line works:
```sh
pic mcp add docs --url https://example.com/mcp --bearer-token-env-var DOCS_TOKEN # Pi's
pic mcp add --transport http docs https://example.com/mcp -H "Authorization: Bearer ..."
pic mcp add docs https://example.com/mcp # a URL means HTTP
pic mcp add '{"mcpServers":{"docs":{"url":"https://example.com/mcp"}}}' # a pasted snippet
pic mcp add-json docs '{"type":"http","url":"https://example.com/mcp"}' # Claude Code's
pic mcp add files -- npx -y @modelcontextprotocol/server-filesystem . # a program (stdio)
pic mcp add -e API_KEY=... tools uvx tools-mcp # Claude Code's stdio
```
`add` connects once and prints how many tools the server has, so a wrong URL or a missing token
shows at once; a server that cannot be reached is kept, and `pic mcp list` tries again. Adding a
name again replaces that server. Names are letters, digits, `_` and `-`; two names that differ only
in `-` and `_` count as one.
Headers (`-H "Name: value"` or `--header Name=value`) and environment values (`--env NAME=value`)
are sealed in the [credential store](credentials.md), bound to the server and its address, and are
never printed: `pic mcp list` and `pic mcp get` name them and say they are sealed. A value may name
a variable as `${NAME}`, read when the server is called; `--bearer-token-env-var NAME` is
`Authorization: Bearer ${NAME}`. `--timeout SECONDS` (default 60) is how long a call may go without
an answer, and `--description` keeps a line about the server. A program's arguments are kept as
given, not sealed: give its secrets with `--env`.
pic keeps servers for you, not per project: `-s user` and `-s local` are accepted, and `-s project`
and Pi's `-l` are refused, since pic does not write a project's files.
## What pic speaks
Streamable HTTP, answered with JSON or with an event stream: an address is `https://`, or `http://`
to this machine only. And stdio: a program pic starts, given after `--` (or, in Claude Code's shape,
after the name) with its arguments, `--env NAME=value` and `--cwd DIR` (a relative one is the
workspace's; with none it starts in the workspace). A leading `~/` names your home directory. pic
speaks the current MCP revision (2026-07-28) first and the 2025 handshake when the server does
not, and remembers which one the server spoke. The old HTTP+SSE transport is refused (`--transport
sse`); most servers that document it also offer streamable HTTP, often at `/mcp` instead of `/sse`.
A stdio server is started when a request first calls one of its tools and stopped when the request
ends: its stdin is closed, then its process group is sent SIGTERM and SIGKILL, so a server started
through `npx` or `uvx` goes too. While it runs, `pic ps` lists it. The calls of one reply to a stdio
server run one after another, since they share its pipe. A build of pic that cannot start programs
refuses stdio servers.
pic does not sign in to servers (OAuth) itself yet. A server that answers 401 needs a token given
as a header; the message says so.
## Tools
Each server's tools are offered as `mcp__SERVER__TOOL`, as Pi and Claude Code name them, so hooks
written for Claude Code and `--tools 'mcp__docs__*'` match them. Characters other than letters,
digits and `_` become `_`, and a name that would be longer than 64 characters, or that two of a
server's tools would share, ends in a short hash. They are on by default and the tool flags and
`defaultTools` choose among them as among any tools; `--exposure hidden` leaves a server's tools
out. pic uses the tool list the server gave when it was added or last listed, so starting a request
connects to nothing; a call connects to its server.
A call is journaled like any tool call, and PreToolUse and PostToolUse hooks, required ones
included, run on it ([hooks](hooks.md)). A tool the server marks read-only runs again if pic
crashes while it runs; any other tool's call becomes "outcome unknown" and is never run again,
because the server may already have acted on it. A server's error, a tool's own error and a call
that gets no answer in time all reach the model as the tool's error. A result longer than 20 KB
reaches the model with its middle cut out, and the whole text is kept: the notice names it, and the
`read` tool reads it.
Under the `offline` setting MCP servers are still called: a server is something you added, not a
request pic makes on its own.
## Commands
- `pic mcp list` connects to each server, lists its tools again and prints its state; it exits 1
when a server is not connected.
- `pic mcp get NAME` shows a server: its address, the names of its sealed headers, its revision and
its tools, with what happens to each after a crash.
- `pic mcp remove NAME` forgets a server and its sealed values.
- `pic mcp call SERVER TOOL '{"arg":...}'` calls a tool directly and prints its result, to try a
server out. It is not journaled.