MCP
This page settles D10 and defines how Robi hosts MCP servers so their tools join the agent registry. It is the design for the MCP client in M8. Modes are in agent-modes.md. The approval bar is in chat-ui.md. Child agents are in subagents.md.
What this page does not cover
| Topic | Where it belongs |
|---|---|
| Built-in read, edit, and shell tools | read-tools.md, editing-tools.md, shell-tool.md |
| How a large MCP result is crushed | mcp-output.md |
| Robi as an MCP server | Later. This page is the host: Robi connects to servers other people run |
| A skill file | skills.md. A server prompt template is not a skill |
Problem
The model can already read the workspace, edit it, and run a command. It cannot open Linear, query a database, or call a service the user already runs as an MCP server for another agent. Those servers speak one protocol and publish a tool list. Rebuilding each of them as a Robi tool does not scale, and it puts every integration in this repository.
A server is also a process the user did not write, started with the user’s credentials, free to talk to the network. Its tool descriptions and its results are text from outside the workspace. Treating that text as instructions, or starting a server because a repository committed a config file, is how a project takes over the session.
Decision
Robi is an MCP host. rmcp speaks the protocol. It lives in crates/robi.
robi-core does not spawn a process, open a socket, or name the protocol.
The client is crates/robi/src/agent/mcp/. Each remote tool is a Tool in the
existing registry.
D10: MCP stays out of the loop
MCP ships in M8. The Tool trait does not grow a dynamic-registration
method. The registry already accepts a tool after the agent is built, and
it gains remove so a server’s tools can leave when the server disconnects
or its list changes. A duplicate name is still refused. The loop looks
tools up by name at execution time, which is what makes a late add visible
on the next model call and invisible to a request already sent.
The trait stays fixed. A server that wants sampling, elicitation, or a
long-running task does not get a new method on Tool.
What the first cut speaks
rmcp negotiates the protocol version. The client accepts 2026-07-28
and the earlier versions that crate still speaks, including 2025-11-25
and 2025-03-26.
The client advertises roots and tools. It lists tools, calls a tool,
and honours notifications/cancelled and notifications/tools/list_changed.
tools/list is followed to the end of its cursor.
The client does not advertise sampling, elicitation, resources, prompts,
tasks, or completions. A server that offers only those still connects and
contributes no tools. A tools/call result that is a task handle, rather
than content, is a tool error. The client does not poll it.
Server instructions from initialize are logged and left out of the
system prompt. The tool list is the channel the model sees.
Configuration
Two JSON files, same shape. The user file is ~/.robi/mcp.json. The
project file is <workspace>/.robi/mcp.json. A missing file is an empty
server list. The files are read when an agent-mode actor starts. Editing
one during a turn applies on the next user message.
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": { "secret": "github_token" }
}
},
"linear": {
"url": "https://mcp.linear.app/mcp",
"headers": {
"Authorization": { "secret": "linear_token" }
}
}
}
}
A server id matches ^[A-Za-z0-9_-]{1,32}$. Any other key is skipped and
logged. A server has command or url, and not both. enabled: false
skips that server. Other unknown fields are ignored so a config copied
from another host still parses.
| Field | Stdio | HTTP |
|---|---|---|
command | Executable name, or an absolute path. A relative path is a config error | Absent |
args | Array of strings. Default [] | Absent |
env | Map overlaid on the scrubbed environment | Absent |
url | Absent | https, or http on 127.0.0.1 or localhost |
headers | Absent | Map of header values |
timeout_seconds | Whole call budget. Default 60. Above 300 is a config error | Same |
tools | Array of glob or re: patterns naming the tools to keep. Absent or null keeps every tool | Same |
An env or header value is either a string or { "secret": "<name>" }.
A string is passed through, which is how an existing config pastes in.
A secret object is read from secrets.toml and never written back. A
missing secret, or any other shape, skips that server and is logged.
Resolved values are not logged.
The same id in both files: the project entry replaces the user entry, and only after the project file is trusted. Until then the user entry stays.
Tool filter
A server that publishes 40 tools spends context on 40 schemas and 40
descriptions on every request. tools limits which of them reach the
session. Absent or null keeps every tool, which is what an entry without
the field did before. An array keeps only the tools that match, and []
keeps none.
{
"mcpServers": {
"linear": {
"url": "https://mcp.linear.app/mcp",
"tools": ["get_*", "create_issue", "re:^search_[a-z]+$"]
}
}
}
Each entry is a glob, or a regex when it starts with re:. A glob matches
the whole name and uses globset syntax: *, ?, [abc], {a,b}. A
re: entry is unanchored, so it matches a substring; anchor it with ^
and $ to pin the whole name. Matching is case-sensitive. Each pattern is
tried against the name the server lists (create_issue) and against the
registered name (mcp_linear_create_issue), so a name copied from a tool
card and a name copied from the server’s docs both work.
The filter runs at registration, not at connect. The connection still
lists every tool, and the status count and the omission log read that same
list. attach re-reads both files before every model call, so an edited
tools array applies on the next user message. A tool that stops passing
fails as an unknown tool, the same as one from a server that dropped.
The filter runs before the 64-tool cap, so it picks which 64 a server may contribute.
A pattern that does not compile skips that server and is logged, the same
as a relative command. A pattern that compiles and matches nothing is
logged once per connection and changes nothing else; a typo loads fewer
tools without an error.
Listing tools from a shell
mcp-tools is the diagnostic binary. It takes a server id, reads the same two
JSON files, the same secrets, and the same path_entries setting, connects
through RmcpOpener, and prints tools/list. It opens no database, so it runs
while the app does.
config::load is the one read path: the hub starts servers from it, reports
status from it, and the binary lists from it. The project hash rule holds in all
three. The binary has no workspace row to compare against, so its --trust flag
is the user saying yes to the bytes in front of them, which is what the Enable
control will do. Without the flag the project file is read, reported, and
contributes nothing.
The binary prints every tool a server lists, and says on stderr how many the
entry’s tools filter keeps. --kept prints that subset instead, which is the
shortest way to check a filter. It does not call a tool: execute needs an
approval decision, and that needs a session.
Trust
The user file starts when the workspace is focused. The user wrote it.
The project file does not start until this workspace has stored the
SHA-256 of that file. The hash lives on the workspace row, mcp_project_sha256,
null until the user enables the current contents. A missing file, a hash
mismatch, or a null column means the project servers are off. Changing
the file clears the match, so a newly committed server does not start on
the next message.
Two surfaces write that column, and both go through
agent::mcp::set_project_trust, which reads the file, hashes it, and calls
WorkspaceService::set_mcp_project_sha256. The service stays free of I/O; the
hash is computed by the caller.
PUT /api/v1/workspaces/{id}/mcp/truststores the hash and answers with the config as it now stands.400when the workspace has no project file. The shell’s Settings → MCP page renders this as a switch, with the ids and targets from the file beside it, so the reader approves what starts rather than a path. Env and header values are left out of the list.DELETEon the same path clears the column and closes that workspace’s servers, so a distrust takes effect without waiting for the next message. Leaving them running would mean a config the user just turned off kept answering.
The terminal app raises Confirm::mcp_trust from the Enter on its Project
config row and queues Action::SetMcpProjectTrust. A landed write re-focuses
the hub and re-reads both status lists.
Trust is a stored hash, not a stored yes: one edited byte stops the servers and the surface shows the file as untrusted again. There is no timer and no “remember this repository” — the bytes are the subject.
Process and HTTP
Stdio uses rmcp’s child-process transport. HTTP uses the streamable
HTTP client. One connection per enabled server per workspace, shared by
the sessions of that workspace. The shell starts them when that workspace
becomes the open one (POST /api/v1/workspaces/{id}/mcp). Switching to
another workspace closes the previous servers. Deleting the workspace
closes them too. An agent-mode turn reuses the open connections and
registers their tools; if the shell has not focused a workspace yet, that
turn starts them. Process exit kills any children still running.
The child does not inherit the parent environment. The scrub is the one
in shell-tool.md: no DYLD_*, LD_PRELOAD,
LD_LIBRARY_PATH, or any name containing KEY, TOKEN, SECRET,
PASSWORD, or CREDENTIAL. PATH is the user’s login-shell PATH,
read once with $SHELL -ilc 'printf %s "$PATH"' and falling back to
this process’s PATH, with the path_entries setting appended. That is
what lets a uvx or npm server resolve when Robi is launched from
Finder, where the process PATH is the minimal system one. HOME,
USER, LOGNAME, and LANG are set. The config env map is
applied after that scrub, so a token the user named is present and a
token they did not name is not. The working directory is the workspace
root. There is no cwd field.
The child is not put in the shell sandbox. An MCP server is an
integration the user enabled, and it needs the network and the
credentials its config names. The sandbox that wraps npm test would
make that server fail closed on the first call. Enabling the server is
the consent. stderr goes to that server’s log, and stays out of the
transcript.
command is resolved on that constructed PATH. An absolute path is
used as written. A name that does not resolve skips the server.
HTTP redirects are followed only when the next URL still matches the
url rule. A redirect to any other host or scheme fails the connection.
The client does not run the MCP OAuth flow. A 401 fails the server.
Static headers are how a remote server authenticates in this cut.
Initialize has 15 seconds. A process that exits is restarted at 1s, 2s,
4s, then 8s, and then 30s, and at most five times in ten minutes. After
that the server is failed until the user retries or the config changes.
A crashing server does not respawn forever.
The actor waits up to that initialize budget, in parallel, before its first model call. A server that is still down is omitted from that call. Tools that arrive later are registered before the next model call.
Logging
Every connection writes a log under ~/.robi/logs/mcp/<server_id>/, one
file per connection named mcp-<timestamp>.log. The directory is the
server id from the config, so two servers never share a file. The file is
mode 0600: its protocol lines can carry tool arguments and results.
Each line is the JSON-RPC message in one direction (-> sent, <-
received), one line of the child’s stderr, or a lifecycle note. Both
transports pass through the same point, so the streamable HTTP client and
the stdio child log initialize, tools/list, tools/call, the
notifications, and the errors the same way. The first line of a
connection names the target: the resolved command and args for stdio, the
URL and whether an authorization header is present for HTTP. Header and
env values never reach the file, so a token stays out.
The policy matches the rest of ~/.robi/logs/: the newest prior file is
kept, a file older than seven days is deleted, and a directory keeps at
most eight. It runs when a server opens and once at process start, which
sweeps every server directory and removes one left empty after its server
was taken out of the config. No line exceeds 32 KiB; a longer protocol
message is cut with a note.
The process log still carries the summary — mcp server starting, mcp server connected, mcp server failed, and the config errors — so the
per-server file is where one server is debugged.
Tools in the registry
tools/list becomes one Tool per entry that passed the server’s tools
filter. The registered name is
mcp_<server>_<tool>, with every character outside [A-Za-z0-9_-]
replaced by _. A name longer than 64 characters keeps the mcp_<server>_
prefix, cuts the tool portion, and appends _ plus six hex characters of
the SHA-256 of the original tool name. Two entries that sanitize to the
same name: the first in the server’s list is kept, the rest are logged
and skipped. A name that collides with a built-in is skipped. Built-ins
are registered first.
Each server may contribute 64 tools. The rest are logged and omitted.
list_changed removes that server’s previous names and registers the new
list. The swap is remove then register. A call already running finishes
on the connection it started on. A call that has not started, whose name
was removed, fails as an unknown tool.
The description the model sees is the server’s description, trimmed, cut
at 1,024 characters, prefixed with MCP server <id>. The description and the result are untrusted data. A missing inputSchema becomes
{ "type": "object", "additionalProperties": true }. A schema whose
JSON exceeds 16 KiB skips that tool.
Every MCP tool declares Concurrent. The client runs one tools/call
at a time per server and queues the rest on that server. A call to
read_file still overlaps. Exclusive would stall the whole turn on
one remote call, which is the wrong grain.
requires_approval is side-effect free. It returns NeedsApproval
unless this session’s allow list contains that server id and tool name.
The allow list is mcp_allows on chat_sessions, a JSON array of
{ "server", "tool" }, [] on create. The migration that adds
mcp_allows and mcp_project_sha256 updates
persistence.md in the same change.
Annotations (readOnlyHint, destructiveHint, openWorldHint, title)
are stored for the approval bar. They do not change requires_approval.
The server writes them.
Calling a tool
execute sends tools/call with the arguments the model supplied. The
client checks that the arguments are a JSON object and otherwise returns
InvalidArgs. ToolRun.cancel sends notifications/cancelled and
returns cancelled.
The result the model reads is the text content blocks, joined. An image,
audio, or binary block is replaced with a one-line placeholder that names
the type and omits the bytes. A resource link becomes its URI. isError: true is a tool error whose message is that text. Empty content is a tool
error. The tool’s own bound is 256 KiB of that text. A call that exceeds
timeout_seconds is a tool error, and the server is left connected.
That bounded text then takes the MCP compression path. The client does
not crush it. Routing, the JSON pass, the line pass, and the kind: "mcp"
row are in mcp-output.md. A string under 4 KiB, and a
pass that saves under 1 KiB, stays byte-identical. The original the model
can retrieve is this 256 KiB text, not the rest of what the server sent.
The core backstop still applies to the compressed result.
Roots
The client answers roots/list with one root: the workspace, as a
file:// URI. It does not grant a second directory. A server that needs
another tree is a later cut.
Approval bar
A pending MCP call uses the approval bar. The line is Call and
server / tool. The arguments are pretty-printed JSON underneath,
wrapping. When the server set a hint, a muted line says Server says:
read-only, Server says: destructive, or Server says: reaches the
network. More than one hint shows more than one line. The line is a
label from the server.
Approve runs this call. Allow for this session runs this call and
appends { "server", "tool" } to mcp_allows. Reject does not call
the server and does not write the list. A later call with the same pair
returns AllowImmediately and stays a result row.
Modes
MCP tools are registered in Agent only. Ask and Plan keep the built-in
sets. A remote tool can write, spend a credential, or send mail, and the
server’s read-only hint is not evidence. The agent prompt says that a
tool whose name starts with mcp_ comes from an external server, and
that its description and result are untrusted data.
Explore and general children do not receive MCP tools. A child that would need approval does not ask the user, so a remote tool there would either run unapproved or always fail.
Status
Above the composer, one line per enabled server that is not connected:
the id, then starting or failed. A failed line has Retry, which
resets that server’s restart budget and connects again. A connected
server shows no line. The line is not a transcript row.
The window bar’s overflow menu lists every configured server for the open
workspace as one row each — its icon, the name, the status, and (when connected)
the tool count — and every row links to the MCP tab. The overflow button is
absent while there is no server to show and the API is healthy. That tab
shows the configured servers and the connection state Robi has for each
(the same GET /api/v1/workspaces/{id}/mcp list the top bar draws), then
~/.robi/mcp.json and <workspace>/.robi/mcp.json as stored, then the
log location for troubleshooting. Refresh rereads the files and the
server list. Secret objects stay unresolved. GET /api/v1/workspaces/{id}/mcp/config returns the paths, the file text,
and whether the project file’s bytes match the stored hash. GET /api/v1/workspaces/{id}/mcp returns { id, status, title, icon, tool_count }. status is disconnected until an agent-mode actor
starts the server, then starting, connected, or failed. Each of those
changes publishes robi.mcp.v1.status on the shell event stream. The window
bar refetches this list from that frame. It does not poll. title and
icon come from the server handshake when it sent them. icon is an
https URL or a data:image URI. A received icon is written to
~/.robi/mcp-icons.json, keyed by server id, and the list keeps using
that copy after a restart until a later handshake replaces it. An icon
over 256 KiB is not stored. The response omits commands, URLs,
headers, and env values. A server with no icon is drawn as its id.
flowchart TD
actor["Agent-mode actor starts"] --> files["Read user and project JSON"]
files --> trust{"Project hash matches"}
trust -->|no| userOnly["User servers only"]
trust -->|yes| both["User servers, project overrides"]
userOnly --> connect["Connect in parallel"]
both --> connect
connect --> list["tools/list"]
list --> reg["Register mcp_server_tool"]
reg --> call["Model calls a tool"]
call --> allow{"Session allow list"}
allow -->|yes| rpc["tools/call"]
allow -->|no| bar["Approval bar"]
bar -->|approve once| rpc
bar -->|allow for session| remember["Append mcp_allows"]
remember --> rpc
bar -->|reject| stop["Rejection result"]
Rejected alternatives
- MCP in the M0 trait. The loop would know about servers, cursors, and
reconnects. Those are I/O.
removeon the registry is the whole core change. - One dispatcher tool,
mcp, with a server and a name argument. The model would not see each tool’s schema. The schema is the prompt. - Trusting
readOnlyHint. The server chooses the hint. A hint that skips approval is a server that skips approval. Hints are labels on the bar. - Allowing every tool once the server is enabled. Enabling starts the process. It does not review a particular call. The first call to each tool still asks. The session list is how the user stops being asked.
- Remembering an allow across sessions, or for the whole workspace.
A grant that outlives the chat is easy to forget. The list is a column
on this session, the same way
web_fetchremembers a host. - Putting the child in the shell sandbox. The profile hides
$HOMEand the network. Most servers would fail, and the user would learn to bypass it. The config is the explicit credential grant. The shell sandbox stays onshell. - Inheriting the parent environment. That copies the provider key into every server. The scrub runs first. The config map is the only way a secret name reaches the child.
- Loading project servers because the file exists. The file is in the repository. The hash on the workspace row is the user’s decision, and a changed file asks again.
- Injecting server
instructionsinto the system prompt. That text is untrusted and paid for on every turn. Tool descriptions already reach the model, attached to the tool they describe. - Sampling and elicitation. Sampling lets the server spend the model and read a prompt. Elicitation is a second question channel beside the approval bar. Neither is advertised.
- OAuth in the first cut. The browser flow, refresh, and storage are
a separate design. A header from
secrets.tomlcovers a server the user can mint a token for. - Resources and prompts in the first cut. Skills already load instruction files. A resource reader is a second read path with its own trust rules. Tools are the reason to connect.
Exclusivefor every MCP tool. One remote call would blockread_file. The per-server queue is inside the client.- A compressor inside the MCP client. The server’s text is the tool
result. Crushing it here would skip the session store, and a second
client would copy the line walker. The pipeline after
executeis the one pass. - A file watcher. The next actor rereads the JSON. A watcher duplicates that for the interval between messages.
- Robi as a server in the same cut. Exporting the built-in tools is a different trust boundary. This page only connects outward.
Failure modes
- The JSON does not parse, or a server has both
commandandurl, or neither. That server is skipped. Other servers still start. The turn starts. - The secret named in the file is absent. That server is skipped.
commandis not on the constructedPATH. The server isfailed. The model does not see its tools.- Initialize exceeds 15 seconds, or the restart budget is spent. The
server is
failed. The composer line says so. The turn starts with the servers that listed. - The project file changed. Its servers stop. The dialog asks again. User servers are unaffected.
tools/listreturns more than 64 tools, or a schema over 16 KiB, or two names that sanitize to one. The extras are logged and omitted.- A
toolspattern does not compile. That server is skipped and logged. A pattern that compiles and matches nothing is logged and the server contributes fewer tools than it publishes. - The model calls a name that was removed mid-turn. The tool error says the tool is gone. The turn continues.
- The server sets
isError, returns no content, or exceeds the timeout. The tool error is the text,empty tool result, ortimeout. The connection stays up on a timeout and onisError. - The process dies during a call. The call fails. The supervisor
restarts within the budget. The next model call sees tools only after
the new
tools/list. - Cancellation mid-call returns
cancelledand does not spend a restart. - A result over 256 KiB is cut by the tool’s own bound before compression.
retrievereturns that prefix, not the rest of the server’s payload. The core backstop still applies to the compressed result. - Ask, Plan, explore, and general never see the tools. A model that names one gets an unknown tool.
- Redirects off the allowed URL, and HTTP to a non-loopback host, fail the connection. No request is sent to the other host.
- stderr goes to the server’s own log, never the transcript, the approval bar, or the process log line. Header and env values reach no log.
- A server whose log file cannot be opened still starts; logging is disabled for that connection.
- A line longer than 32 KiB is cut in the log with a note. The tool result the model sees is unaffected.
Testing
cargo test -p robi-core stays free of sockets and processes. It covers
remove, and that a tool registered after the agent is built is the one
execute finds.
The trust path has its own tests: the hash stored for a file, the column cleared without reading anything, a workspace with no project file naming the path, one edited byte changing the hash, the terminal’s row raising the right question and queueing the write, and the route documented with both methods.
The mcp-tools tests live beside it. They cover the parser, a server entry with
no filter and one with a filter, --remote and --long, an unknown id naming
the configured ones, an untrusted project file reported and ignored, and
--trust reading it.
The client tests live in crates/robi and use an in-memory transport.
They cover: a scrubbed environment with the config secret overlaid and
the parent provider key absent; a project file ignored until the stored
hash matches and ignored again after a one-byte change; the 64-tool cap;
a tools filter that keeps one listed tool and drops another, and a
tools array that matches nothing; name sanitizing and a built-in
collision skipped; NeedsApproval before
the session list contains the pair and AllowImmediately after;
annotations present on the tool and absent from the decision; a
cancelled call sending notifications/cancelled; an isError result
becoming a tool error; initialize instructions absent from the assembled
prompt.