MCP Client
Connect to external MCP servers (GitHub, filesystem, databases) and use their tools in OpenFang agents
MCP Server
Expose OpenFang agents as MCP tools for IDEs like Cursor, VS Code, and Claude Desktop
A2A Server
Publish Agent Cards and accept task submissions from other agent frameworks
A2A Client
Discover and interact with external A2A agents
MCP (Model Context Protocol)
Overview
The Model Context Protocol (MCP) is a JSON-RPC 2.0 based protocol that standardizes how LLM applications discover and invoke tools. OpenFang supports MCP in both directions:- As a client: Connect to external MCP servers and make their tools available to all agents
- As a server: Expose agents as MCP tools for external clients
2024-11-05.
MCP Client — Connecting to External Servers
Configuration
MCP servers are configured inconfig.toml using the [[mcp_servers]] array:
Configuration Fields
Display name for this MCP server. Tools are namespaced as
mcp_{name}_{tool}.JSON-RPC request timeout in seconds.
Environment variable names to pass through to the subprocess (stdio transport only).
How to connect to the MCP server.
Transport Types
- stdio
- sse
Tool Namespacing
All tools discovered from MCP servers are namespaced using the patternmcp_{server}_{tool} to prevent collisions:
- Server
github, toolcreate_issuebecomesmcp_github_create_issue - Server
my-server, tooldo_thingbecomesmcp_my_server_do_thing
Names are normalized to lowercase with hyphens replaced by underscores.
Auto-Connection on Boot
When the kernel starts, it:- Iterates each
[[mcp_servers]]config entry - Spawns subprocesses (stdio) or creates HTTP clients (SSE)
- Sends the
initializehandshake - Calls
tools/listto discover available tools - Namespaces and caches discovered tools
- Stores live connections for tool execution
MCP Server — Exposing OpenFang via MCP
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.
For example, an agent named code-reviewer becomes the MCP tool openfang_agent_code_reviewer.
CLI: openfang mcp
- Checks if an OpenFang daemon is running
- If found, proxies tool calls to the daemon via HTTP
- If no daemon, boots an in-process kernel as fallback
- Reads Content-Length framed JSON-RPC from stdin
- Writes Content-Length framed JSON-RPC to stdout
HTTP MCP Endpoint
OpenFang also exposes an MCP endpoint over HTTP atPOST /mcp. Unlike the stdio server, the HTTP endpoint exposes the full tool set:
- All 23 built-in tools
- All installed skill tools
- All connected MCP server tools
Supported JSON-RPC Methods
| Method | Description |
|---|---|
initialize | Handshake; returns server capabilities |
notifications/initialized | Client confirmation |
tools/list | Returns all available tools |
tools/call | Executes a tool and returns result |
Protocol Example
Initialize Handshake:Connecting from IDEs
- Cursor / VS Code
- Claude Desktop
Add to your MCP configuration file (
.cursor/mcp.json or VS Code MCP settings):MCP API Endpoints
List configured and connected MCP servers with their toolsResponse:
Handle MCP JSON-RPC requests over HTTP (full tool execution)
A2A (Agent-to-Agent Protocol)
Overview
The Agent-to-Agent (A2A) protocol, originally specified by Google, enables cross-framework agent interoperability. OpenFang implements A2A in both directions:- As a server: Publishes Agent Cards, accepts task submissions, tracks task lifecycle
- As a client: Discovers external A2A agents, sends tasks, polls for results
Agent Card
An Agent Card is a JSON document describing an agent’s identity, capabilities, and supported interaction modes. Served at/.well-known/agent.json per A2A specification.
Structure
Agent name
Human-readable description
Endpoint URL (e.g.,
http://host/a2a)Protocol version
Agent capabilities
Supports streaming responses
Supports push notifications
Task status history available
Array of A2A skill descriptors (not OpenFang skills — these are capability descriptors)
A2A Configuration
Whether A2A endpoints are active
Base path for A2A endpoints
External agents to discover at boot
Display name for this external agent
Base URL where the agent’s card is published
Task Lifecycle
AnA2aTask tracks the full lifecycle of a cross-agent interaction:
Task States
| Status | Description |
|---|---|
Submitted | Task received but not yet started |
Working | Task is being actively processed |
InputRequired | Agent needs more information |
Completed | Task finished successfully |
Cancelled | Task was cancelled by caller |
Failed | Task encountered an error |
Message Format
A2A API Endpoints
Agent Card for the primary agent. Public endpoint.
List all agent cardsResponse:
Submit a task to an agentRequest:Response:
Get task status and messages. Returns
404 if not found or evicted.Cancel a running task. Returns
404 if not found.A2A Client — Discovering External Agents
When the kernel starts with A2A enabled and external agents configured, it:- Creates an
A2aClient - Iterates each configured
ExternalAgent - Fetches each agent’s card from
{url}/.well-known/agent.json - Logs successful discoveries (name, URL, skill count)
- Stores discovered agents for runtime interaction
Sending Tasks to External Agents
Security
MCP Security
Subprocess Sandboxing
Stdio MCP servers run with
env_clear() — subprocess environment completely cleared. Only whitelisted environment variables passed through.Path Traversal Prevention
Command paths validated to reject
.. sequences.SSRF Protection
SSE transport URLs checked against known metadata endpoints (169.254.169.254, metadata.google).
Request Timeout
All MCP requests have configurable timeout (default 30s) to prevent hung connections.
Message Size Limit
Stdio MCP server enforces 10 MB max message size to prevent out-of-memory attacks.
A2A Security
Rate Limiting
A2A endpoints use same GCRA rate limiter as all API endpoints.
API Authentication
When
api_key is set, all endpoints (including A2A) require Authorization: Bearer <key> header. Exception: /.well-known/agent.json and health endpoint.Task Store Bounds
A2aTaskStore is bounded (default 1000 tasks) with FIFO eviction of completed/failed/cancelled tasks.External Agent Discovery
A2aClient uses 30-second timeout and sends User-Agent: OpenFang/0.1 A2A header. Failed discoveries logged but don’t block boot.Kernel-Level Protection
Both MCP and A2A tool execution flows through the same security pipeline:- Capability-based access control
- Tool result truncation (50K character hard cap)
- Universal 60-second tool execution timeout
- Loop guard detection (blocks repetitive tool call patterns)
- Taint tracking on data flowing between tools
