mcp-agent Documentation
repository·main·Indexed 27 days ago
https://github.com/lastmile-ai/mcp-agentA composable framework for building robust agents using the Model Context Protocol (MCP). mcp-agent simplifies MCP server lifecycle management and implements production-ready agentic patterns such as map-reduce, orchestrator, router, and swarm. It supports durable execution via Temporal, provides Augmented LLM wrappers for providers like OpenAI, and includes a CLI for project scaffolding and cloud deployment.
What's inside mcp-agent
- mcp-agent is a composable framework for building effective agents using the Model Context Protocol (MCP). It provides full MCP support (Tools, Resources, Prompts, Notifications, etc.), implements effective agent patterns (like map-reduce, orchestrator, and router), and supports durable execution via Temporal for scaling to production workloads without API changes.
Overview of Workflow Pattern Composition
mainWorkflow pattern composition is an advanced technique for building complex agent systems by combining simpler, reusable, and well-tested patterns. This modular approach enables building complex workflows from components, testing individual patterns in isolation, maintaining and evolving patterns independently, and scaling different patterns based on specific workloads.Observability Overview
mainFor production agent workflows,
mcp-agentsupports a comprehensive observability stack to ensure reliability and performance. This includes:- Metrics Collection: Tracking performance, throughput, and system health.
- Distributed Tracing: Following requests across agents, workflows, and external services.
- Structured Logging: Centralized, searchable logs with contextual information.
- Alerting: Proactive notifications for issues and anomalies.
Choose an agent workflow pattern
mainThe
mcp-agentSDK provides production-ready implementations of various agentic patterns via helpers inworkflows/factory.py. Each helper returns anAugmentedLLMthat can be composed, exposed as a tool, or wrapped with additional logic.Pattern Use Case Factory Helper(s) Parallel (Map-Reduce) Multiple specialists looking at the same request concurrently create_parallel_llm(...)Router Dispatching requests to the best skill, server, or function create_router_llm(...),create_router_embedding(...)Intent Classifier Lightweight intent bucketing before routing/automation create_intent_classifier_llm(...),create_intent_classifier_embedding(...)Planner (Orchestrator) Multi-step planning and coordination across agents create_orchestrator(...)Deep Research Long-horizon investigations with budgets and memory create_deep_orchestrator(...)Evaluator-Optimizer Automated reviewers to approve or iterate on drafts create_evaluator_optimizer_llm(...)Custom/Swarm Bespoke patterns stitched from primitives create_swarm(...)Deploy mcp-agent applications to production
mainmcp-agentprovides a unified programming model that scales from local development to managed cloud runtimes. You can deploy full agents with durable workflows or standalone MCP servers (FastMCP services, ChatGPT App backends, bespoke tool APIs) using the same code.Key benefits include:
- One protocol everywhere: All deployments expose standard MCP endpoints (
call_tool,read_resource,list_prompts). - Durable workflows: Decorators like
@app.tool,@app.async_tool, and@app.workflowtransition from localasyncioto cloud-based Temporal execution, providing retries and human-in-the-loop support. - Operational guardrails: The CLI manages build artifacts, secrets, authentication, and observability.
- One protocol everywhere: All deployments expose standard MCP endpoints (
Understand Secret Management Phases
mainSecrets management in
mcp-agent cloudis divided into two distinct types:- Deployment secrets: Values known at deploy time (e.g., provider API keys, service accounts). These are stored encrypted and automatically mounted into the runtime for all users.
- User secrets: Values that individual consumers must supply (e.g., personal access tokens, OAuth tokens). These are collected per user via
mcp-agent cloud configureand are scoped to that specific user's configuration.
Quickstart: Deploy and install an mcp-agent application
mainFollow these steps to move from local development to a deployed cloud application:
- Install the CLI: Use
uvto install themcp-agenttool. - Authenticate: Log in to create your API key.
- Deploy: Bundle your code and push it to the managed cloud.
- Install to Client: Add the deployed MCP server to your client configuration (e.g., Claude Desktop, Cursor, VS Code).
uv tool install mcp-agent # Install the CLI mcp-agent login # Launch browser auth and create an API key mcp-agent deploy web-summarizer # Bundle code, process secrets, push to the cloud mcp-agent install web-summarizer # Add the MCP server to a client config- Install the CLI: Use
Quickstart: Scaffold and run a new project
mainYou can quickly set up a new project using the
mcp-agentCLI viauvx.- Scaffold a project:
uvx mcp-agent init- Initialize a python environment:
uv init- Add dependencies:
uv add "mcp-agent[openai]"- Configure secrets: Add your
OPENAI_API_KEYtomcp_agent.secrets.yamlor set it as an environment variable. - Run the application:
uv run main.pymkdir hello-mcp-agent && cd hello-mcp-agent uvx mcp-agent init uv init uv add "mcp-agent[openai]" uv run main.pyQuickstart with mcp-agent
mainTo scaffold and run an agent locally in under 5 minutes, use theuvx mcp-agent initcommand. This will set up the necessary structure to begin building your agent.uvx mcp-agent initInstall MCP Agent Cloud SDK for development
mainTo set up the SDK in a development environment, use
uvto create a virtual environment and install the package in editable mode with development dependencies.# Navigate to the package root # Create and activate a virtual environment uv venv .venv source .venv/bin/activate # Install in editable mode with dev dependencies uv pip install -e ".[dev]"Choose a deployment path for mcp-agent
mainSelect a deployment strategy based on your requirements:
Use case Recommended path Description Prototype & debugging uv run main.pyormcp-agent dev startLocal development with hot reload and local logs. Durable agents mcp-agent deploy(managed)Uses the managed cloud environment with Temporal-backed workflows, cloud logging, secrets, and auth. Regulated / on-prem Self-hosted Temporal + mcp_agent.config.yamloverridesUse your own Temporal cluster for air-gapped or regulated environments. Reusable MCP tools FastMCP or @app.toolvia cloudDeploy stateless tools via standard MCP transport, installable via CLI. Run mcp-agent CLI commands
mainYou can run
mcp-agentcommands ad hoc without installation usinguvx mcp-agent .... If the package is already a dependency in your project, useuv run mcp-agent ...to execute within your project's environment.All commands support these global flags:
--verbose/-v--quiet/-q--format <text|json|yaml>--color/--no-color--version