MCP and A2A Protocols

LibreFang supports MCP (Model Context Protocol) and A2A (Agent to Agent) protocols.


MCP (Model Context Protocol)

MCP is a standardized protocol for connecting LLMs to external tools and services.

Overview

┌─────────────┐      MCP       ┌─────────────┐
   LibreFang ◄─────────────►  MCP Server
   (Client)  │   JSON-RPC 2.0  │  (Server)   │
└─────────────┘                  └─────────────┘

MCP Server Configuration

[[mcp_servers]]
name = "filesystem"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

[[mcp_servers]]
name = "github"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_TOKEN = "your-token" }

MCP Tool Naming

MCP tool naming format:

mcp_{server}_{tool}

For example:

  • mcp_filesystem_read_file
  • mcp_github_create_issue

Built-in MCP Servers

LibreFang includes built-in MCP servers:

ServerTools
filesystemread_file, write_file, list_directory
githubcreate_issue, get_pr, search_repos
postgresquery, execute, list_tables

MCP Client

Connect to external servers as an MCP client:

[[mcp_servers]]
name = "custom"
command = "python"
args = ["./mcp_server.py"]

Developing MCP Servers

from mcp.server import Server
from mcp.types import Tool, TextContent

app = Server("my-server")

@app.list_tools()
async def list_tools():
    return [
        Tool(
            name="my_tool",
            description="My custom tool",
            inputSchema={"type": "object", "properties": {}}
        )
    ]

@app.call_tool()
async def call_tool(name: str, arguments: dict):
    return [TextContent(type="text", text="result")]

A2A (Agent to Agent)

The A2A protocol enables communication between LibreFang agents.

Overview

┌─────────────┐      A2A       ┌─────────────┐
   Agent A ◄─────────────►   Agent B
└─────────────┘   JSON over    └─────────────┘
                  HTTP/WebSocket

Agent Card

Each Agent publishes an Agent Card:

{
  "name": "researcher",
  "description": "Deep research agent",
  "url": "http://localhost:4545/api/a2a",
  "version": "1.0.0",
  "capabilities": {
    "streaming": true,
    "pushNotifications": false
  },
  "skills": [
    { "id": "research", "name": "Research" }
  ]
}

Client Endpoints (Send Tasks to External A2A Agents)

These endpoints allow LibreFang to act as a client, delegating tasks to external A2A agents:

EndpointMethodDescription
/api/a2a/agentsGETList discovered external A2A agents
/api/a2a/discoverPOSTDiscover an external A2A agent at a URL
/api/a2a/sendPOSTSend a task to an external A2A agent
/api/a2a/tasks/{id}/statusGETCheck the status of a sent task

Server Endpoints (Accept External Tasks)

These endpoints are exposed by LibreFang, allowing other A2A agents to send tasks to this instance:

EndpointMethodDescription
/.well-known/agent.jsonGETAgent Card (capability declaration)
/api/a2a/tasksPOSTAccept tasks from external agents
/api/a2a/tasks/{id}GETGet task status
/api/a2a/tasks/{id}/messagesGETGet task message history

Discover and Send Tasks to External Agents

# Discover an external agent
curl -X POST http://localhost:4545/api/a2a/discover \
  -H "Content-Type: application/json" \
  -d '{"url": "http://other-agent:4545"}'

# Send a task to an external agent
curl -X POST http://localhost:4545/api/a2a/send \
  -H "Content-Type: application/json" \
  -d '{
    "agent_url": "http://other-agent:4545",
    "message": "Research AI trends and summarize"
  }'

# Check task status
curl http://localhost:4545/api/a2a/tasks/task-123/status

Accept Tasks from External Agents

# External agent sends a task to this instance
curl -X POST http://localhost:4545/api/a2a/tasks \
  -H "Content-Type: application/json" \
  -d '{
    "id": "task-456",
    "message": {
      "role": "user",
      "parts": [{ "type": "text", "text": "Research AI trends" }]
    }
  }'

# Poll for results
curl http://localhost:4545/api/a2a/tasks/task-456

# Or use SSE for streaming
curl -N http://localhost:4545/api/a2a/tasks/task-456/events

Comparison

FeatureMCPA2A
PurposeLLM to ToolsAgent to Agent
ProtocolJSON-RPC 2.0HTTP/WebSocket
DirectionUnidirectionalBidirectional
ExamplesFilesystem, GitHubAgent collaboration

Use Cases

MCP Use Cases

  • Filesystem operations
  • Database queries
  • GitHub API calls
  • Custom tool integration

A2A Use Cases

  • Multi-agent collaboration
  • Task delegation
  • Cross-instance communication

Configuration Example

Complete MCP Configuration

# MCP Servers
[[mcp_servers]]
name = "filesystem"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/workspace"]

[[mcp_servers]]
name = "github"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]

# A2A Configuration
[a2a]
enabled = true
listen_path = "/a2a"

CLI Commands

# List MCP servers
librefang mcp list

# Test an MCP server
librefang mcp test filesystem

# Start MCP mode
librefang mcp