Connecting tools with MCP
Follow a documentation lookup from a profile grant to an HTTP tool server, then see what the chat keeps if the call is interrupted.
You ask your assistant to look up a page in your team’s manual. A documentation service already knows how to find the page if you give it a topic. The Model Context Protocol (MCP)A protocol through which a client such as Pipal can discover the tools a service offers and ask the service to run one with supplied arguments. gives Pipal a way to ask that service what it can do and then request the lookup. Pipal’s own tests use a small server that offers exactly this tool. mcp-fixture.ts
In this chapter
- Follow a lookup from the model to the service that runs it and back into the chat.
- Connect a tool server and give one profile access to its catalog.
- Tell a missing grant, a failed lookup and an interrupted call apart.
From a question to a page
- Model
- Harness
- Host mcp.ts
- Docs MCP
Host → Docs · Initialize
At startup, Pipal introduces itself
The host connects to the configured URL. The docs server advertises support for tools.
Host → Docs · tools/list
Pipal asks what the server can do
The test server returns an empty first page with a cursor. The client follows that cursor to get the next page.
Docs → Host · lookup-page
The next page describes a lookup
Its input schema requires a string called
topic. Pipal builds a tool definition and closes the discovery client.Host → Harness · Register tool
The lookup becomes part of mcp.docs
Pipal core installs the host’s tool definition in the registry with a check on the conversation’s profile.
Harness → Model · Offer tool
A granted chat gets the declaration
The model sees the name
mcp__docs__lookup_page_0a944487, a description of the lookup, and its input schema.Model → Harness · Request lookup
The model supplies a topic
The test model asks for
reference 1. Pi records the call and checks its arguments.Harness → Host · Execute
Core checks the grant before dispatch
With
mcp.docsgranted, the handler starts a fresh MCP session with the docs server.Host → Docs · tools/call
The server gets its own tool name
The request names
lookup-pageand supplies{"topic":"reference 1"}. The host attaches the headers configured for this endpoint.Docs → Host · Page text
The docs server answers the call
Here it sends a text block containing
Documentation: reference 1in an HTTP event-stream response.Host → Harness · Tool result
Pi gets a result for the transcript
The host converts the returned content for the model, applies the text limit and closes the client.
Harness → Model · Next turn
The model can use what the service found
The lookup result is part of the conversation. The model can answer from it or request another tool.
Host → Docs
At startup, Pipal introduces itself
The host connects to the configured URL. The docs server advertises support for tools.
The MCP server is the service that owns the tool. In this example it knows what to do with a topic, which pages exist and what to return when a page is missing. The MCP client is part of the Pipal host. It uses Pi’s McpClient to send named requests over HTTP and match each reply to its request. You can connect a service that speaks this protocol without writing a Pipal module for its lookup function. README.md mcp.ts
At startup the host checks which capabilities each selected server offers. If the server advertises tools, Pipal asks for its catalog. A catalog entry describes an operation and the arguments it accepts. In the test, lookup-page takes an object with one required text field, topic. That description gives the model enough information to ask for a lookup before it has seen a single page of the manual. mcp.ts mcp-fixture.ts
Later, in a chat with the right profile grant, the model can supply a topic. The Pipal host sends the request, even for a chat with no project workspace. The docs service receives the tool name and arguments, including any information the model puts in topic. Its reply goes back to the harness and into the next model turn. mcp.ts mcp.test.ts
Connect a server and grant its tools to Chat
Give the server an address. The JSON below comes from Pipal’s server guide. Use your service’s Streamable HTTP endpoint in place of the example URL. Streamable HTTP is the transport the two programs use to exchange MCP messages. A lookup can get its reply as JSON or as an event in the HTTP response. Save the file as mcp.json beside your config.toml. mcp-config.ts mcp-fixture.ts
{
"mcpServers": {
"docs": {
"url":
"https://docs.example.com/mcp",
"headers": {
"Authorization":
"Bearer ${DOCS_TOKEN}"
},
"timeout": 30
}
}
} - Server name
You choose this name. It ties the endpoint to the
mcp.docsextension used in the configuration and profile. - Tool endpoint
Use the address of a service that speaks Streamable HTTP. It must be reachable from the machine running Pipal.
- Service credential
At startup Pipal reads
DOCS_TOKENfrom its own environment. The host uses the expanded header when connecting to this service. - Call deadline
The unit is seconds. The deadline includes the time it takes to connect. This is also the default if you omit the field.
{
"mcpServers": {
: {
"url":
,
"headers": {
"Authorization":
},
"timeout":
}
}
} 1 Server name
You choose this name. It ties the endpoint to the mcp.docs extension used in the configuration and profile.
If your service requires this bearer token, set DOCS_TOKEN in the environment of the process that runs Pipal. A missing or empty variable stops configuration loading. If your endpoint accepts requests without credentials, omit headers. The credential goes in the host’s HTTP request. The model’s declaration contains the tool name, description and argument schema. mcp-config.ts mcp.ts
Select the server on the host. Point [mcp] at the JSON file and add mcp.docs to extensions.enabled. Relative paths start beside the TOML file. An explicit enabled list replaces the defaults, so the example keeps the five default extensions. If you already have a list, add the new entry to yours. config.ts
[mcp]config = "mcp.json"
[extensions]enabled = [ "pipal.delegate", "pipal.system-diagnostics", "pipal.web-artifacts", "pipal.coding", "pipal.bash", "mcp.docs",]Choose who can call it. To give the bundled Chat profile access, edit its existing optional_extensions line in agents/chat.md. Keep its other grants and instructions. Restart Pipal, select Chat and a tool-capable model, and ask for a topic your service knows. A saved top-level chat picks up its profile’s current grants on the next accepted message. chat.md index.ts
optional_extensions: [pipal.web-artifacts, pipal.web-search, mcp.docs]Deep diveWhich entries the loader accepts
loadConfig() collects the mcp. names from extensions.enabled when [mcp] is configured. It opens the JSON file only if that selection is nonempty. loadMcpConfig() looks up those names in mcpServers. An unselected entry can describe a command-line server used by another application. Pipal skips it. A selected entry with enabled: false drops out of the enabled list as well. An enabled name missing from the file is a configuration error. config.ts mcp-config.ts
Use letters, digits, underscores or hyphens in a server name. Selected servers support Streamable HTTP and direct exposure to the model. Leave exposure unset or use "direct" on the server entry. Stdio launch commands, OAuth settings, toolExposure and command-valued headers such as !command fail validation. The host expands environment references in header values and rejects them in URLs, along with embedded URL credentials and fragments. It reserves protocol headers including Mcp-Session-Id and MCP-Protocol-Version for the client. mcp-config.ts
With [mcp] present, local modules in extensions.modules cannot use the mcp. prefix. When at least one MCP server is active in the configuration, startup checks the other loaded tool definitions for the reserved mcp__ prefix. An ordinary module named mcp.custom can still load under its explicitly configured path in a setup without [mcp]. main.ts mcp.test.ts
The name in the transcript and the name on the wire
| Where you look | What the lookup is called |
|---|---|
| Host configuration and profile | mcp.docs names the extension for the whole service. |
| Model request and transcript | mcp__docs__lookup_page_0a944487 names one tool from that service. |
| Request received by the service | tools/call carries the original name lookup-page and the topic argument. |
A service can also receive a valid call and report that it failed. In the example, the topic reference 1 returns page text. The topic missing returns No matching documentation page. and sets isError: true. Pipal preserves that flag, so the model can explain that the lookup failed even though the HTTP exchange completed. mcp-fixture.ts mcp.test.ts
Deep diveHow Pipal translates tool definitions and results
discover() follows the catalog through listTools(), normalizes each input schema to the object form used for tool arguments, and checks the resulting properties. The provider-facing name includes both the server and tool. Pi’s createMcpToolName() keeps it within 64 characters. Pipal asks for a hash suffix when converting a name would lose information or leave an ambiguous separator. That is why the hyphen in lookup-page becomes an underscore and the example gets a suffix even when it is the only tool. A change in catalog order must leave a saved name pointing to the same operation. A final check rejects duplicate provider-facing names across the registrations. mcp.ts README.md
Each invocation opens a fresh client. Pipal refuses HTTP redirects, disables the background GET stream and sets stream reconnection attempts to zero. The transport’s message limit is 2 MiB. The answer goes through toMcpModelContent() and limitMcpContent() before Pi records the result. Long model-facing text keeps its beginning and end, cutting the middle to fit Pi’s 20 KB text limit. Pipal passes no file saver to either helper, so the adapter supplies no path to a full copy of the cut text. mcp.ts README.md
When the service is unavailable
During discovery. Read the host’s startup log first. Successful discovery logs a tool count for that server. A bad JSON configuration for a selected server stops startup. A valid address whose service is down produces a discovery warning and leaves that extension with zero tools. Pipal can still start and use the tools from other healthy servers. Once the service is available, restart Pipal to discover its catalog again. mcp-config.ts mcp.ts
During a lookup. The host has to connect again for the call, so a tool discovered at startup can still time out when you use it. The default call budget is 30 seconds including connection setup. If you press Stop while the request is in flight, the client tries to notify the server which request was canceled. That notice can arrive after the service has already acted. mcp.ts mcp.test.ts
After a crash. Imagine the service accepted a request and Pipal stopped before it could record the reply. Repeating a lookup might spend quota twice. Repeating a write might make the change twice. Pipal marks every MCP tool replay: 'unsafe'. On recovery, Pi records that the interrupted call may have partially run and gives that result to the model. The recovery test holds the lookup open, kills Pipal and reopens the chat. The service sees the accepted call exactly once. mcp.ts recovery.test.ts
An MCP lookup gets its answer from a service that already knows how to do the work. Sometimes Chat needs a specialist to take an assignment and work out the answer in a conversation of its own. Delegation follows that handoff.
Recap
- Startup discovers tools at the endpoints you select. A profile grant makes one server’s tools available to that profile.
- The model supplies arguments. The Pipal host opens a fresh MCP session, calls the service by its original tool name and returns the result to the conversation.
- A discovery failure leaves one catalog empty until restart. A crash during an accepted call leaves an interrupted result.
- The host discovered a tool from docs. Chat can use it, but another profile has no mcp.docs grant. What happens if that model guesses the tool name?
- The docs server receives the request and chooses a profile
- The call fails before a request reaches the docs server
- The server grants access for that call only
Answer and explanation
The call fails before a request reaches the docs server
Discovery installs the tool on the host. The profile controls who may call it, and the execution path enforces that grant.
- Pipal started while the docs service was offline. The service is healthy again. How do you make its tools available?
- Refresh the browser
- Open another chat with the same profile
- Restart Pipal so it reads the catalog again
Answer and explanation
Restart Pipal so it reads the catalog again
The catalog is built at host startup. A failed discovery leaves this server with zero registered tools for that process.
- The service accepted a call, but Pipal crashed before recording its reply. What does the recovered conversation know?
- The call was interrupted and may have acted
- The server rolled back the operation
- A second request will return the original reply
Answer and explanation
The call was interrupted and may have acted
The host lost the reply. Pi records an interrupted result and leaves the remote operation alone, since repeating it could duplicate its effects.
The host discovered a tool from docs. Chat can use it, but another profile has no mcp.docs grant. What happens if that model guesses the tool name?
Pipal started while the docs service was offline. The service is healthy again. How do you make its tools available?
The service accepted a call, but Pipal crashed before recording its reply. What does the recovered conversation know?