Overview
The Application SDK provides deep integration with the Model Context Protocol (MCP), enabling your Temporal workflows and activities to be exposed as AI tools that can be discovered and invoked by AI assistants like Claude Desktop, Claude Code, Cursor, and other MCP-compatible clients.MCP integration is optional. Install the
mcp extras group to enable it:Architecture
The MCP integration consists of three main components:Component Details
Decorator
The
@mcp_tool decorator adds metadata to activity methods, marking them for MCP exposureServer
The
MCPServer class discovers marked activities and creates FastMCP tool registrationsTransport
Uses FastMCP 2.0’s streamable HTTP transport for compatibility with modern MCP clients
Discovery
Automatic discovery happens at application startup by scanning workflow activity lists
Marking Activities as Tools
Basic Usage
Use the@mcp_tool decorator to expose activities:
application_sdk/decorators/mcp_tool.py
Decorator Parameters
The@mcp_tool decorator accepts the following parameters:
Custom name for the tool. Defaults to the function name.
Description shown to AI assistants. Defaults to the function’s docstring.
Whether to expose this tool at runtime. Set to
False to conditionally hide tools.Advanced Example with Pydantic Models
Pydantic models are automatically converted into JSON schema by FastMCP. The AI assistant will see the individual fields with their descriptions and types.
Server Implementation
TheMCPServer class handles automatic discovery and registration:
application_sdk/server/mcp/server.py
Discovery Process
The server discovers tools through the following process:Metadata Structure
The metadata attached by@mcp_tool is defined by the MCPMetadata model:
application_sdk/server/mcp/models.py
Configuration
Environment Variables
Control MCP behavior with environment variables:.env
Conditional Tool Exposure
You can conditionally expose tools based on environment or configuration:AI Client Configuration
Claude Desktop
Add your application to Claude Desktop’s configuration file:Configuration file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Other MCP Clients
For clients supporting streamable HTTP transport directly:client-config.yaml
Testing and Debugging
MCP Inspector
Use the MCP Inspector to test your tools:Open MCP Inspector
Navigate to the MCP Inspector
Logging
The MCP server provides detailed logging during tool registration:Best Practices
Write Clear Descriptions
Write Clear Descriptions
AI assistants rely on descriptions to understand when and how to use tools. Be explicit about:
- What the tool does
- What inputs it expects
- What outputs it returns
- Any preconditions or constraints
Use Type Hints
Use Type Hints
Type hints help generate accurate JSON schemas:
Handle Errors Gracefully
Handle Errors Gracefully
Return user-friendly error messages that AI assistants can understand:
Keep Tools Focused
Keep Tools Focused
Each tool should do one thing well. Split complex operations:
Advanced Patterns
Dynamic Tool Configuration
Load tool configurations from external sources:Tool Composition
Compose complex workflows from simple tools:Troubleshooting
Tools Not Appearing in AI Client
Tools Not Appearing in AI Client
- Check that
ENABLE_MCP=trueis set - Verify
@mcp_tooldecorator is applied correctly - Ensure
visible=True(default) - Check server logs for registration messages
- Restart your AI client after configuration changes
Parameter Schema Issues
Parameter Schema Issues
If AI assistants are confused about parameters:
- Use Pydantic models with clear field descriptions
- Add type hints to all parameters
- Provide default values where appropriate
- Test with MCP Inspector to see the generated schema
Connection Errors
Connection Errors
- Verify your application is running and accessible
- Check firewall settings for port 8000
- Test the endpoint:
curl http://localhost:8000/mcp - Ensure no other service is using port 8000
Related Topics
Activities
Learn about creating activities
Workflows
Understand workflow orchestration
Monitoring
Monitor MCP tool usage
Temporal Auth
Secure your workflows