Overview
mcp-agent allows you to expose your agents and workflows as MCP servers. This enables any MCP-compatible client (Claude Desktop, VS Code, custom applications) to interact with your agents through the standard MCP protocol.How It Works
When you expose an agent as an MCP server, the framework:- Creates an MCP server using FastMCP
- Registers workflows as MCP tools
- Provides standard workflow management tools
- Handles protocol communication
Default MCP Tools
Every agent server automatically provides these workflow management tools:workflows-list
Lists all available workflow types with their parameters and capabilities. Returns:- Workflow names and descriptions
- Parameter schemas
- Available operations (run, resume, cancel, get_status)
- Tool endpoints
workflows-runs-list
Lists all running workflow instances with their current status. Returns:- Workflow instance IDs
- Current state (running, paused, completed, failed)
- Workflow type name
- Execution metadata
workflows-run
Executes a workflow with specified parameters. Parameters:workflow_name
: Name of the workflow to runrun_parameters
: Arguments for the workflow
workflow_id
: Workflow identifierrun_id
: Unique run instance ID
workflows-get_status
Retrieves the current status of a workflow instance. Parameters:run_id
: The run instance IDworkflow_id
: Optional workflow identifier
- Current state
- Results (if completed)
- Error details (if failed)
- Execution progress
workflows-resume
Resumes a paused workflow, optionally with input data. Parameters:run_id
: The run instance IDworkflow_name
: Workflow identifiersignal_name
: Signal to send (default: “resume”)payload
: Optional data to provide
workflows-cancel
Cancels a running workflow instance. Parameters:run_id
: The run instance IDworkflow_name
: Workflow identifier
Custom Tools via Decorators
@app.tool - Synchronous Tools
Synchronous tools execute immediately and return results:calculate_sum
that executes synchronously.
@app.async_tool - Asynchronous Tools
Asynchronous tools run as durable workflows:research_topic
: Starts the workflow- Status tracking via
workflows-get_status
- Cancellation via
workflows-cancel
Server Configuration
Basic Setup
Running the Server
Using stdio
Using SSE
Client Configuration
Claude Desktop
Add toclaude_desktop_config.json
:
Programmatic Access
Workflow Registration
Workflows are automatically discovered and registered as MCP tools:workflows-data_processing-run
: Execute the workflowworkflows-data_processing-get_status
: Check execution status
Human-in-the-Loop Patterns
Agent servers support human interaction through pause/resume:Monitoring and Logging
Agent servers provide real-time logging through MCP’s logging capability:Advanced Features
Custom Tool Names
Override default tool names:Tool Descriptions
Provide detailed descriptions for better discoverability:Parameter Validation
Parameters are automatically validated based on type hints:Best Practices
- Tool Naming: Use clear, descriptive names for workflows and tools
- Documentation: Always include docstrings for workflows and tools
- Error Handling: Implement proper error handling in workflows
- State Management: Use workflow context for persistent state
- Resource Cleanup: Ensure proper cleanup in workflow finally blocks
- Type Hints: Use type hints for automatic parameter validation