mcp-agent patterns are deliberately composable. You can mix routers, parallel fan-outs, evaluators, orchestrators, and plain Python callables to create flows that match your product requirements—without authoring new workflow classes.Documentation Index
Fetch the complete documentation index at: https://docs.mcp-agent.com/llms.txt
Use this file to discover all available pages before exploring further.
Building blocks recap
create_llm(...)– wrap anAgentSpecin an AugmentedLLM tied to a provider (OpenAI, Anthropic, Azure, Google, Bedrock, Ollama).create_router_llm(...)/create_router_embedding(...)– dispatch requests to the best specialist.create_intent_classifier_llm(...)– bucket requests before routing.create_parallel_llm(...)– run multiple workers in parallel and aggregate their outputs.create_evaluator_optimizer_llm(...)– iterate until a reviewer approves the response.create_orchestrator(...)– break complex objectives into sequenced steps.create_deep_orchestrator(...)– add knowledge extraction, policy engines, and budgets.create_swarm(...)– OpenAI/Anthropic-compatible handoffs between agents.load_agent_specs_from_dir(...)– hydrate agents from YAML/JSON specs.
Design playbook
- Model your specialists as
AgentSpec(name, instruction, tool access). Keep prompts short and behaviour-specific. - Pick a routing strategy: intent classifier for lightweight gating, router for multi-skill dispatch, or orchestrator for complex plans.
- Layer guardrails: wrap high-risk steps in an evaluator-optimizer loop, or add policy agents inside an orchestrator step.
- Add determinism: integrate
fan_out_functionsfor repeatable checks or use embedding routers for fixed scoring. - Expose the composition with
@app.tool/@app.async_toolso MCP clients can call it as a single tool. - Instrument with the token counter (
await workflow.get_token_node()) and tracing (otel.enabled: true) before shipping.
Example: router ➝ parallel research ➝ evaluator
- Router, parallel workflow, and evaluator are created once and reused across requests.
- The evaluator-loop wraps the parallel workflow, so quality checks happen before the response leaves the system.
- The entire composition is exposed as an MCP tool via
@app.async_tool, making it callable from Claude, Cursor, or other MCP clients.
Patterns that mix well
- Intent classifier ➝ router: Use the classifier for coarse gating (“is this support vs. billing?”) then route to specialists.
- Parallel ➝ evaluator: Run multiple evaluators in parallel (policy, clarity, bias) and feed their combined verdict back to the optimizer.
- Orchestrator ➝ evaluator: Wrap the final synthesis step in an evaluator loop so the orchestrator keeps iterating until the review passes.
- Router ➝ orchestrator: Route strategic tasks to an orchestrator for deep execution, while simple tasks go to lightweight agents.
- Swarm handlers: Use
create_swarm(...)to hand off between agents mid-conversation, while still using MCP tools for capabilities.
Operational tips
- Share the context: keep compositions inside
async with app.run()so every component reuses the sameContext(server registry, executor, secrets, tracing). - Tune once, reuse everywhere: store provider/model defaults in
mcp_agent.config.yaml; override per pattern only when necessary. - Observe everything:
await workflow.get_token_node()shows token spend for nested workflows; enable OTEL tracing to follow router choices, parallel branches, and evaluator scores. - Blend deterministic helpers: pass
fan_out_functionsor routerfunctionsfor cheap heuristics (regex, lookups) alongside LLM-heavy steps. - Think in tools: once composed, wrap the entire pattern with
@app.tool/@app.async_toolso it becomes an MCP tool. Other agents, orchestrators, or human operators can call it without knowing how it is assembled.
Examples to study
- workflow_orchestrator_worker – combines routing, parallel tasks, and orchestration to grade student assignments.
- workflow_evaluator_optimizer – demonstrates evaluator loops, tool exposure, and cloud deployment.
- workflow_parallel – shows how to compose
AgentSpec, AugmentedLLMs, and deterministic helpers inside one tool. - Temporal examples – walk through exposing custom compositions as durable Temporal workflows.
