XSAF alpha uses the official MCP server and Hono packages as its MCP backbone. It supports protocol version 2026-07-28 only and rejects legacy MCP traffic.
Serve agent tools
const builder = xsaf.agent(config).sandbox(sandbox).tool(tool).serve({
transport: "http",
path: "/mcp",
name: "support_agent",
version: "0.1.0-alpha.0",
});
const agent = await builder.start();XSAF mounts the endpoint on agent.app; it does not open a socket. Model-visible tools appear through tools/list with their generated draft-07 input schema. tools/call uses the same validation, approval, timeout, retry, and sandbox pipeline as model calls.
Tool results become MCP text content. Failures become MCP error results rather than exposing an internal stack.
Connect to an MCP server
import mcp from "@xsaf/agent/mcp";
const remote = mcp({
name: "catalog",
transport: "http",
url: "https://mcp.example.com/",
auth: {
type: "bearer",
token: process.env.MCP_TOKEN!,
},
trust: "untrusted",
});
const builder = xsaf.agent(config).sandbox(sandbox).mcp(remote);At connection time the client calls tools/list. Discovered tools call tools/call. The connection also supports exact resource reads through resources/read and prompt retrieval through prompts/get.
Use agent.prompt(name, args) to retrieve a prompt from connected MCP prompt providers. It searches connections in registration order and uses the first prompt provider.
Trust policy
trust defaults to "untrusted"; discovered tools then require human approval by default. trust: "trusted" changes the default to automatic approval. An explicit tool approval policy takes precedence.
Request protocol
The built-in client sends JSON-RPC 2.0 POST requests with:
MCP-Protocol-Version: 2026-07-28- per-request method metadata
- client name and alpha version metadata
- optional bearer authorization
An optional fetch function provides a runtime or test seam.
Start order
Integration resources initialize in builder declaration order and stop in reverse order. MCP tool discovery happens when its driver connects. .serve() snapshots the currently model-visible tools when its resource starts.
const builder = xsaf
.agent(config)
.sandbox(sandbox)
.mcp(remoteServer) // Discover first.
.serve({ transport: "http", path: "/mcp" }); // Then expose the snapshot.Current limitations
- HTTP is the only built-in MCP client and serve transport.
- The client parses JSON responses; it does not decode SSE-formatted MCP responses despite advertising the media type.
- Tools are discovered once at connect time.
- No built-in MCP client close operation is required by the stateless HTTP driver.
- Prompt results are returned as a JSON string of the MCP messages payload.
- Register
.mcp()before.serve()if discovered tools must be served onward.