Overview
MCPApp is the orchestration layer for every mcp-agent project. It boots the global Context, loads configuration, wires in logging and tracing, manages MCP server connections, and exposes workflows and tools to clients. If you think of agents, LLMs, and workflows as the “workers”, MCPApp is the runtime that keeps them coordinated.
Configuration loader
Discovers
mcp_agent.config.yaml, merges mcp_agent.secrets.yaml, .env, and environment overrides, or uses explicit SettingsRuntime context
Initialises the global
Context with registries, executors, token stores, tracing, and loggingMCP integration
Provides a FastMCP server façade so workflows and tools can be exposed over MCP
Decorator hub
Supplies decorators that turn Python callables and classes into durable workflows and tools
Quick start
The fastest way to useMCPApp is the pattern followed in the finder agent example:
app.run()initialises the context and cleans it up automatically.app.initialize()/app.cleanup()are still available for advanced CLI or testing flows.- Keep one
MCPAppper process; share it across agents, workflows, and custom tasks.
Key properties
Once initialised you gain access to the runtime building blocks via theMCPApp instance:
app.context: the sharedContextobject containing registries, token manager,MCPAppreference, and request helpers.app.config: the resolvedSettingsmodel.app.logger: a structured logger that automatically injects the session id and context.app.server_registry: theServerRegistrythat tracks configured MCP servers.app.executor: the active execution backend (AsyncioExecutororTemporalExecutor).app.engine: shorthand forapp.executor.execution_engine.app.mcp: the FastMCP server instance backing this application (when created).
Supplying configuration explicitly
MCPApp accepts multiple configuration entrypoints:
settings=None(default) discovers config/secrets automatically.settings="/path/to/mcp_agent.config.yaml"loads an explicit file.settings=Settings(...)reuses an existingSettingsinstance (for example when you derive from environment variables at runtime).
human_input_callbackexposes human input as a tool.elicitation_callbackforwards elicitation responses from MCP clients.signal_notificationsurfaces Temporal/asyncio workflow signal waits (great for dashboards).model_selector: provide a customModelSelectorimplementation.session_id: override the generated session identifier.
Automatic subagent loading
Whensettings.agents.enabled is true, the app automatically discovers AgentSpec definitions from the configured search paths (and optional inline definitions) via load_agent_specs_from_dir. This creates a pool of reusable subagents that can be fetched inside workflows or factories without manual registration.
app.context.loaded_subagents.
Observability and credentials
During initialisationMCPApp:
- Configures structured logging and progress reporting based on
settings.logger. - Enables tracing when
settings.otel.enabledis true, flushing exporters safely during cleanup. - Creates the shared
TokenManagerandTokenStorewhen OAuth is configured (settings.oauth), allowing downstream MCP servers to participate in delegated auth. - Installs a token counter when tracing is enabled so you can query usage (
await app.get_token_summary()).
OAuth and delegated auth
MCPApp’s OAuth integration is what powers the GitHub flows in the OAuth basic agent and the server/client samples under examples/oauth:
- If a server declares
auth.oauth, the app injectsOAuthHttpxAuthso connections can request tokens on demand. - Pre-seeded tokens (for example via
workflows-store-credentials) are written to the configured token store (memory or Redis). app.context.token_managerandapp.context.token_storeexpose the runtime handles when you need custom automation.
Decorator toolkit
MCPApp is the home for all decorators that transform plain Python into MCP-ready workflows and tools:
@app.workflow: register a workflow class (e.g. for Temporal orchestration).@app.workflow_run: mark the entrypoint method on a workflow.@app.workflow_task: declare reusable activities/tasks that work across engines.@app.workflow_signal: register signal handlers (Temporal-compatible).@app.tool: expose a function as a synchronous MCP tool (with auto-generated workflow bindings).@app.async_tool: expose a long-running tool that returns workflow handles.
create_mcp_server_for_app), mcp-agent automatically emits additional tools like workflows-run and workflows-get_status for every decorated workflow.
Running as an MCP server
MCPApp pairs with FastMCP to expose your application as an MCP server:
FastMCP instance via the mcp parameter to piggyback on a shared server or embed the app into another MCP host.
Integrating with agents and workflows
app.context.server_registry grants access to the configured MCP servers. Agents created inside the app automatically reuse the same registry and connection manager, and workflows scheduled through app.executor inherit the same Context.
Context, server connections, logging metadata, token counters, and tracing spans remain consistent across the stack.
