MCP Client
Connect to external MCP servers and use their tools
MCP Server
Expose OpenFang agents as MCP tools to IDEs
2024-11-05.
MCP Client
The MCP client allows OpenFang to connect to any MCP-compatible server and use its tools as if they were built-in.Configuration
MCP servers are configured inconfig.toml using the [[mcp_servers]] array:
Configuration Fields
| Field | Type | Default | Description |
|---|---|---|---|
name | String | required | Display name, used in tool namespacing |
transport | McpTransportEntry | required | How to connect (stdio or SSE) |
timeout_secs | u64 | 30 | JSON-RPC request timeout |
env | Vec<String> | [] | Env vars to pass through to subprocess |
Transport Types
Stdio Transport
Stdio Transport
Spawns a subprocess and communicates via stdin/stdout with newline-delimited JSON-RPC:The subprocess environment is cleared and only explicitly whitelisted variables (in
env field) plus PATH are passed through.SSE Transport
SSE Transport
Connects to a remote HTTP endpoint and sends JSON-RPC via POST:URLs are validated to prevent SSRF attacks against metadata endpoints.
Tool Namespacing
All tools discovered from MCP servers are namespaced using the patternmcp_{server}_{tool} to prevent collisions:
Example 1
Server:
Tool:
Result:
githubTool:
create_issueResult:
mcp_github_create_issueExample 2
Server:
Tool:
Result:
my-serverTool:
do_thingResult:
mcp_my_server_do_thingopenfang_runtime::mcp):
format_mcp_tool_name(server, tool)— builds the namespaced nameis_mcp_tool(name)— checks if a tool name starts withmcp_extract_mcp_server(tool_name)— extracts the server name from a namespaced tool
Auto-Connection on Kernel Boot
When the kernel starts, it automatically connects to configured MCP servers:Initialize handshake
Sends
initialize request with client info, followed by notifications/initializedConnection Lifecycle
TheMcpConnection struct manages the lifetime:
Configuration Examples
GitHub Server
GitHub Server
Provides file, issue, and PR tools:
Filesystem Server
Filesystem Server
Provides file read/write tools:
PostgreSQL Server
PostgreSQL Server
Provides database query tools:
Puppeteer (Browser Automation)
Puppeteer (Browser Automation)
Provides browser automation tools:
Remote SSE Server
Remote SSE Server
Connect to remote MCP server:
Multiple Servers
Multiple Servers
Configure multiple MCP servers simultaneously:
Tool Discovery and Execution
MCP tools are merged into the agent’s available tool set:MCP Server
OpenFang can act as an MCP server, exposing its agents as callable tools to external MCP clients.How It Works
Each OpenFang agent becomes an MCP tool namedopenfang_agent_{name} (with hyphens replaced by underscores). The tool accepts a single message string parameter and returns the agent’s response.
Example: An agent named
code-reviewer becomes the MCP tool openfang_agent_code_reviewer.CLI: openfang mcp
The primary way to run the MCP server:HTTP MCP Endpoint
OpenFang also exposes an MCP endpoint over HTTP atPOST /mcp.
Unlike the stdio server (which only exposes agents), the HTTP endpoint exposes the full tool set: built-in tools, skills, and MCP tools. This means the HTTP MCP endpoint supports all 23 built-in tools plus installed skill tools and connected MCP server tools.
Supported JSON-RPC Methods
| Method | Description |
|---|---|
initialize | Handshake; returns server capabilities and info |
notifications/initialized | Client confirmation; no response |
tools/list | Returns all available tools with names, descriptions, and input schemas |
tools/call | Executes a tool and returns the result |
-32601 (Method not found) error.
Protocol Details
Message Framing (stdio mode)
Initialize Handshake
Request:Tool Call
Request:Connecting from IDEs
Cursor / VS Code
Cursor / VS Code
Add to your MCP configuration file (
.cursor/mcp.json or VS Code MCP settings):Claude Desktop
Claude Desktop
Add to
claude_desktop_config.json:MCP API Endpoints
| Method | Path | Description |
|---|---|---|
GET | /api/mcp/servers | List configured and connected MCP servers with their tools |
POST | /mcp | Handle MCP JSON-RPC requests over HTTP (full tool execution) |
GET /api/mcp/servers
Response:Security
Subprocess Sandboxing
Stdio MCP servers run with
env_clear() — environment is completely cleared. Only whitelisted env vars plus PATH are passed through.Path Traversal Prevention
Command paths are validated to reject
.. sequences.SSRF Protection
SSE transport URLs are checked against metadata endpoints (169.254.169.254, metadata.google).
Request Timeout
All MCP requests have configurable timeout (default 30 seconds).
Message Size Limit
Stdio MCP server enforces 10 MB maximum message size.
Kernel-Level Protection
MCP tool execution flows through the same security pipeline: capability-based access control, tool result truncation (50K cap), 60-second timeout, loop guard detection, and taint tracking.
Source Files
- Client:
crates/openfang-runtime/src/mcp.rs - Server handler:
crates/openfang-runtime/src/mcp_server.rs - CLI server:
crates/openfang-cli/src/mcp.rs - Config types:
crates/openfang-types/src/config.rs