$ show lastmile-ai/mcp-agent
mcp-agent is a Python framework for building, deploying, and serving AI agents that interact with the Model Context Protocol (MCP). In production, it provides a library and CLI toolkit that allows developers to compose agents using configurable LLM providers (OpenAI, Anthropic, Azure, Bedrock, Ollama, Google), connect to any MCP server (stdio, SSE, Websocket, Streamable HTTP), and orchestrate multi-step workflows with patterns like parallel fan-out/fan-in, router, orchestrator-worker, evaluator-optimizer, and swarm. The framework is architecture-agnostic, supporting both asyncio in-process execution and durable execution via Temporal for long-running, fault-tolerant agent loops. The system ships with a feature-rich CLI (mcp-agent) for local scaffolding, configuration, and cloud deployment to MCP Agent Cloud, including secret management, log tailing, and OAuth integration. Key entry points include the main application bootstrap (MCPApp), the Agent class (managing MCP server connections and LLM), workflow implementations in src/mcp_agent/workflows/, and the server module that exposes agents as MCP servers via FastMCP. The codebase is well-structured with clean abstractioons (ContextDependent, AugmentedLLM base), extensive testing (over 100 test files), and comprehensive observability through OpenTelemetry tracing, token counting, and structured logging. Use cases range from simple chat agents to complex research assistants, real estate analyts, and customer service desks with swarm routing. The framework is actively maintained with frequent commits, a large community, and is built to production standards.
The LLM identified 4 files worth highlighting for reuse:
Implements the Proof Key for Code Exchange (PKCE) code_challenge and code_verifier generation for OAuth 2.0 authorization flows. Uses standard library modules (secrets, hashlib, base64) to create secure, URL-safe S256 challenges. Fully isolated, zero internal dependencies β can be extracted as a standalone utility for any OAuth client implementation.
Discovers OAuth authorization server metadata from the well-known endpoint (RFC 8414). Loads and validates the JSON response into a Pydantic model, providing typed access to endpoints, scopes, and grant types. Uses httpx for HTTP calls and is fully self-contained, except for the Pydantic dependency. Exemplifies a clean implementation of a common OAuth configuration pattern.
Provides pure functions to extract text, images, or resources from MCP message content types (TextContent, ImageContent, EmbdeddedResource, etc.). Handles multiple content types polymorphically, returning plain text or structured data. No internal imports from the mcp_agent package; uses only standard library and Pydanticβs BaseModel. An essential, reusable utility for any MCP client application.
A standalone script that recursively traverses a project directory and compiles all source files into a single Markdown document, respecting ignore patterns and token limits. Useful for feeding an entire project context into an LLM prompt. Uses only Python standard libraries (pathlib, re, sys, argparse). Demonstrates a practical solution for a common problem (providing full code context to LLMs) and can be reused in any codebase with minimal adaptation.