xiaohongshu
xiaohongshu
fastmcp-integration
Examples and patterns for integrating FastMCP Cloud servers with Claude Agent SDK using HTTP transport
Full skill instructions
This skill provides examples and troubleshooting for FastMCP Cloud integration.
FastMCP Cloud uses HTTP, NOT SSE!
Example: Basic FastMCP Cloud Integration
import os
import asyncio
from dotenv import load_dotenv
from claude_agent_sdk import query
from claude_agent_sdk.types import ClaudeAgentOptions
load_dotenv()
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
FASTMCP_CLOUD_API_KEY = os.getenv("FASTMCP_CLOUD_API_KEY")
async def main():
async for message in query(
prompt="List available tools from the MCP server",
options=ClaudeAgentOptions(
model="claude-sonnet-4-20250514",
# ✅ CRITICAL: Use HTTP for FastMCP Cloud
mcp_servers={
"your-server": {
"type": "http", # ← Must be "http" not "sse"
"url": "https://your-server.fastmcp.app/mcp",
"headers": {
"Authorization": f"Bearer {FASTMCP_CLOUD_API_KEY}"
}
}
},
# Allow MCP tools
allowed_tools=["mcp__your-server__*"],
# Pass API keys via env
env={
"ANTHROPIC_API_KEY": ANTHROPIC_API_KEY,
"FASTMCP_CLOUD_API_KEY": FASTMCP_CLOUD_API_KEY
}
)
):
if hasattr(message, 'type') and message.type == 'text':
print(message.text)
if __name__ == "__main__":
asyncio.run(main())
Example: Multiple FastMCP Cloud Servers
mcp_servers={
"cats": {
"type": "http",
"url": "https://catsmcp.fastmcp.app/mcp",
"headers": {"Authorization": f"Bearer {FASTMCP_CLOUD_API_KEY}"}
},
"github": {
"type": "http",
"url": "https://github-mcp.fastmcp.app/mcp",
"headers": {"Authorization": f"Bearer {FASTMCP_CLOUD_API_KEY}"}
}
}
allowed_tools=[
"mcp__cats__*", # All CATS tools
"mcp__github__*", # All GitHub tools
]
Example: Checking MCP Connection Status
async for message in query(...):
if hasattr(message, 'type') and message.type == 'system':
if hasattr(message, 'data') and 'mcp_servers' in message.data:
for server in message.data['mcp_servers']:
status = server.get('status', 'unknown')
name = server.get('name', 'unknown')
print(f"✅ MCP Server '{name}': {status}")
if status == 'failed':
print("❌ Connection failed!")
print(" Check: 1) Using 'type': 'http'")
print(" Check: 2) FASTMCP_CLOUD_API_KEY is valid")
print(" Check: 3) URL is correct")
Wrong transport type:
"type": "sse" # ❌ Doesn't work with FastMCP Cloud
Missing API key:
# ❌ Not passing FASTMCP_CLOUD_API_KEY
env={"ANTHROPIC_API_KEY": ANTHROPIC_API_KEY}
Wrong package:
from anthropic_agent_sdk import query # ❌ Wrong!
# Should be:
from claude_agent_sdk import query # ✅ Correct
'mcp_servers': [{'name': 'cats', 'status': 'failed'}]Causes:
"type": "sse" instead of "type": "http"FASTMCP_CLOUD_API_KEYFix:
"type": "http"env parameterhttps://your-server.fastmcp.app/mcp (with /mcp endpoint)ImportError: No module named 'anthropic_agent_sdk'Cause: Wrong package name
Fix:
pip uninstall anthropic-agent-sdk # Remove wrong package
pip install claude-agent-sdk # Install correct package
See examples/python/fastmcp-cloud-http.py for a full working example.
Required in .env:
ANTHROPIC_API_KEY=sk-ant-api03-...
FASTMCP_CLOUD_API_KEY=fmcp_...
Must be passed via env parameter:
env={
"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY"),
"FASTMCP_CLOUD_API_KEY": os.getenv("FASTMCP_CLOUD_API_KEY")
}
When you run your agent, you'll see system messages like this:
# System message with connection status
SystemMessage(
subtype='init',
data={
'type': 'system',
'session_id': 'c8feee3e-bb62-4dcc-92bc-042b507e614a',
'mcp_servers': [{'name': 'cats', 'status': 'connected'}], # ✅ Connected!
'tools': ['mcp__cats__search_candidates', 'mcp__cats__get_candidate', ...],
'model': 'claude-sonnet-4-20250514',
...
}
)
What this means:
'status': 'connected' ✅ - Your HTTP configuration worked!'tools': [...] - All 163 CATS tools are now availablemcp__cats__search_candidates, etc.If you use wrong transport type, you'll see:
SystemMessage(
data={
'mcp_servers': [{'name': 'cats', 'status': 'failed'}], # ❌ Failed!
'tools': ['Task', 'Bash', 'Read', ...], # Only built-in tools, no MCP tools
...
}
)
What this means:
'status': 'failed' ❌ - Connection didn't workmcp__cats__* tools available"type": "sse" instead of "type": "http"When Claude uses an MCP tool:
# Claude decides to call search_candidates
AssistantMessage(
content=[
ToolUseBlock(
id='toolu_01HhvXi5wyvVa2DWtbP8KvJw',
name='mcp__cats__search_candidates',
input={'search_string': 'heavy duty mechanic'}
)
]
)
# Tool result comes back
UserMessage(
content=[
ToolResultBlock(
tool_use_id='toolu_01HhvXi5wyvVa2DWtbP8KvJw',
content='{"count":2,"total":3540,"_embedded":{"candidates":[...]}}'
)
]
)
# Claude responds with analysis
AssistantMessage(
content=[
TextBlock(
text="I found 3,540 heavy duty mechanic candidates. Here are the first 2..."
)
]
)
================================================================================
CATS Multi-Tool Agent Demo - Claude Agent SDK
================================================================================
🔌 MCP Server Status:
--------------------------------------------------------------------------------
✅ cats: CONNECTED
📦 Available CATS Tools: 163
- search_candidates
- get_candidate
- list_candidate_custom_fields
- list_candidate_attachments
- parse_resume
... and 158 more
💬 Claude:
--------------------------------------------------------------------------------
I'll search for heavy duty mechanics using the CATS database...
💬 Claude:
--------------------------------------------------------------------------------
I found 3,540 heavy duty mechanic candidates in the system. Here are the
first 2 results with their Red Seal certification status:
1. **Sahlan Samsuddin**
- Email: [email protected]
- Location: Mimika, Papua
- Red Seal Status: Not found in "Notes on Qualifications" field
- Tags: None
2. **[Next candidate]**
...
See the examples/ directory in this skill:
examples/multi-server.py - Connecting to multiple FastMCP Cloud serversexamples/connection-status.py - Testing and troubleshooting connections@plugins/claude-agent-sdk/examples/python/complete-example-with-output.py - Full example with output@plugins/claude-agent-sdk/examples/python/basic-query.py@plugins/claude-agent-sdk/examples/python/fastmcp-cloud-http.py@plugins/claude-agent-sdk/examples/README.md@plugins/claude-agent-sdk/docs/sdk-documentation.mdxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience