agent-mesh MCP Server
Enables coordinating specialist agents through an event-driven backend, allowing submission of goals, retrieval of job status and results, and listing of jobs via MCP tools.
README
agent-mesh
Why It Exists
Most multi-agent demos are synchronous chains: one call waits for the next call, and one slow or failing agent stalls or voids the whole run. They often have no retry boundary, no isolation between specialist roles, and no reliable way to reconstruct what happened after a bad run.
agent-mesh is an event-driven backend for coordinating specialist agents through a small, explicit event contract. Work is submitted as a job, decomposed into role-specific tasks, processed by independent workers, and joined by an aggregator that can complete with partial results when a specialist fails permanently.
The default provider is fake, so the full test suite and demo run with no API keys.
Architecture
submit
|
v
JOB_SUBMITTED
|
v
supervisor
|
v
TASK_REQUESTED fan-out
| |
v v
researcher worker analyst worker
| |
v v
TASK_SUCCEEDED/FAILED TASK_SUCCEEDED/FAILED
\ /
\ /
v v
aggregator fan-in
|
v
JOB_COMPLETED or JOB_FAILED
TASK_REQUESTED retry budget exhausted
|
v
DEAD_LETTER
|
v
dead-letter sweeper
|
v
TASK_FAILED
Event Flow
Supervisor.submit(goal) publishes JOB_SUBMITTED with the job id as the
correlation id. The supervisor consumes that event, stores the job state, and
publishes one TASK_REQUESTED event per role. Each worker is in its own consumer
group, so every role receives a copy of the task stream while work remains
exclusive within that role. Workers publish TASK_SUCCEEDED or TASK_FAILED.
The aggregator consumes both, joins by job id, and publishes JOB_COMPLETED or
JOB_FAILED once every expected role has settled.
Every child event preserves the same correlation id and records the causation id
of the event that produced it. GET /jobs/{job_id}/events returns the causal
trace for debugging.
Reliability Semantics
The bus is a Protocol with two implementations. InMemoryBus is the default
used by the examples and the ordinary test suite. RedisStreamsBus provides the
same contract on Redis Streams for real deployments and is available with:
pip install -e .[redis]
tests/test_bus_contract.py runs one conformance suite against both
implementations, using fakeredis for the Redis-backed case, so the abstraction
is verified rather than assumed.
| Guarantee | Mechanism |
|---|---|
| Fan-out by role | One topic copied to each subscribed consumer group |
| Exclusive work within a role | A pending set per topic and group |
| At-least-once delivery | Messages remain pending until acked |
| Crash recovery | Visibility-timeout reclaim returns unacked work to the queue |
| Idempotency | Bus-level seen set skips already-acked event ids |
| Retry budget | nack redelivers until max_deliveries is reached |
| Poison-message isolation | Exhausted messages move to DEAD_LETTER |
| Joins do not hang | Dead-letter sweeper converts poison tasks into TASK_FAILED |
| Partial failure | Aggregator marks jobs degraded when some roles fail permanently |
| Traceability | Correlation and causation ids on every event |
Providers
FakeProvider is deterministic and needs no credentials. It can cycle through
fixed responses, fail transiently for a configured number of calls, or fail
permanently for degradation-path tests.
SDK-backed providers read credentials from the process environment, or from a
gitignored .env file loaded with agent_mesh.config.load_dotenv(). Values
already present in the real environment always win over .env, so
platform-injected secrets are not overridden by a stale file baked into an
image. describe_credentials() reports whether credentials are present without
ever revealing a value.
OpenAIProvider uses the official OpenAI SDK and reads OPENAI_API_KEY when an
API key is not passed directly. OpenAIProvider.DEFAULT_MODEL is
gpt-4o-mini, overridable with OPENAI_MODEL or a model= argument.
GrokProvider uses the same SDK against xAI's OpenAI-compatible endpoint,
https://api.x.ai/v1, so both vendors share one client path. It reads
XAI_API_KEY, falling back to GROK_API_KEY. GrokProvider.DEFAULT_MODEL is
grok-4.5, overridable with XAI_MODEL or a model= argument.
xAI retires model ids aggressively and does not keep bare-major aliases alive.
A plausible-looking id such as grok-3 returns 404 at the first live call
rather than failing at import. The live test suite therefore asserts that each
provider default model id appears in that provider's GET /v1/models listing.
Real keys must never be committed. .env is gitignored.
MCP Integration
agent_mesh.mcp_server.create_mcp_server(supervisor, store, mesh) exposes three
MCP tools:
| Tool | Result |
|---|---|
submit_job(goal) |
Submits a goal, drains the mesh, and returns the job id |
get_job(job_id) |
Returns job status and output |
list_jobs() |
Returns known jobs |
Install MCP support with:
pip install 'agent-mesh[mcp]'
Quickstart
pip install -e .[dev]
python examples/research_brief.py
To use SDK-backed providers:
pip install -e .[llm]
export OPENAI_API_KEY=...
export XAI_API_KEY=...
Running against live models
examples/live_brief.py runs the full mesh with Grok serving the researcher
role and GPT serving the analyst role in the same job, which is the point of
the provider abstraction.
python examples/live_brief.py
An optional goal can be passed as command line arguments. For the no-credentials
equivalent, run examples/research_brief.py, which uses the deterministic fake
provider.
HTTP API
Create an app with agent_mesh.api.create_app(bus, store, supervisor, mesh).
| Method | Path | Description |
|---|---|---|
GET |
/healthz |
Health check |
POST |
/jobs |
Submit { "goal": "..." }; returns 202 and job_id |
GET |
/jobs |
List all jobs |
GET |
/jobs/{job_id} |
Get status, output, results, and failures |
GET |
/jobs/{job_id}/events |
Get the full causal event trace |
GET |
/dead-letters |
Inspect dead-lettered messages |
Testing
ruff check .
pytest -q
The default suite has 26 tests and uses FakeProvider, so it runs with no
credentials. That keeps CI green.
Live integration tests are opt-in and skipped otherwise:
AGENT_MESH_LIVE=1 pytest tests/test_live_providers.py
Both tiers are needed. Unit tests with a fake provider structurally cannot catch a retired model id, a changed base URL, or a moved auth scheme. The first live run of this suite caught exactly that class of bug.
Design Notes
The in-memory bus is the reference implementation and mirrors production queue semantics closely enough to make failure behavior testable. A deployment can replace it with Redis Streams, Kafka, or another durable transport while keeping the event envelope and component APIs stable.
The worker treats permanent provider failures as settled task failures and lets transient failures propagate to the bus retry path. That split keeps policy out of provider adapters and prevents a single bad request from blocking a fan-in.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。