Integrate MCPCat into a Python MCP Server
MCPCat is a one-line SDK integration. It automatically tracks all tool calls, sessions, and user intent. You do NOT add tracking code inside tool functions — MCPCat hooks into the server at the protocol level.
Step 1: Find the MCP server
Search all
files for these import patterns (check in order):
from mcp.server.fastmcp import FastMCP
or from mcp.server import FastMCP
— Official FastMCP
from fastmcp import FastMCP
— Community FastMCP (different package, needs )
from mcp.server.lowlevel import Server
or from mcp.server import Server
— Low-level Server
In the matched file, find the server variable assignment (e.g.,
or
). Store the variable name.
If
is already present in the file, tell the user MCPCat is already integrated and stop.
If multiple server instantiations exist, ask the user which one to instrument.
Step 2: Get the project ID
If the user didn't provide a project ID (format:
followed by characters), ask them:
What is your MCPCat project ID? (format: proj_xxxxx)
Create a free account at
https://mcpcat.io to get one.
Step 3: Check peer dependency
Check the project's
or
for the MCP SDK version:
- Official MCP (): Requires . If older, tell the user to upgrade.
- Community FastMCP (
from fastmcp import FastMCP
): Requires and NOT . If older or on 2.9.x, tell the user to upgrade/change version.
If the version can't be determined from project files, run
or
to check the installed version.
Step 4: Install the package
First check if
(or
) is already listed in the project's dependency files (
or
). If it is already listed, skip this step.
If not listed, detect the package manager and install:
| Indicator | Command |
|---|
| or in pyproject.toml | |
| |
| |
| Add to , then pip-compile requirements.in
|
| Otherwise | Check the project's README and other files for dependency management instructions, then install accordingly |
For community FastMCP (import is
from fastmcp import FastMCP
), use
instead of
in all install commands above.
,
, and
handle dependency files automatically — no extra step needed for those. For
, the dependency is tracked in
. For other package managers, ensure
is added to the appropriate dependency file after installation.
Step 5: Add the integration code
Make two edits to the server file. Do NOT add tracking code inside tool functions — MCPCat does this automatically.
1. Imports — add at the top with other imports:
python
import os
import mcpcat
from mcpcat import MCPCatOptions
Add
only if not already present.
2. Track call — add AFTER the server variable is created, BEFORE
or ASGI mounting:
python
mcpcat.track(SERVER_VAR, "PROJECT_ID", MCPCatOptions(
debug_mode=os.getenv("MCPCAT_DEBUG_MODE", "false").lower() in ("true", "1", "yes", "on")
))
Replace
with the actual variable name (e.g.,
,
,
) and
with the user's project ID.
Placement rules
- MUST be after the line that creates the server (e.g., )
- MUST be before or any ASGI app mounting
- Can go before or after definitions — both work. Before is canonical.
- If server is created inline (e.g.,
export default FastMCP(...)
), refactor to assign to a variable first
Why this MCPCatOptions pattern is required
The
env var IS read at module load time, but
calls
set_debug_mode(options.debug_mode)
which overrides it. Since
defaults to
, calling
without explicit options silently disables env-var-based debug mode. The pattern above preserves env var control. Debug logs are written to
.
Complete example
A typical FastMCP server after integration:
python
import os
import mcpcat
from mcpcat import MCPCatOptions
from mcp.server.fastmcp import FastMCP
server = FastMCP("weather-server", version="2.1.0")
mcpcat.track(server, "proj_abc123", MCPCatOptions(
debug_mode=os.getenv("MCPCAT_DEBUG_MODE", "false").lower() in ("true", "1", "yes", "on")
))
@server.tool()
def get_weather(city: str) -> str:
"""Get current weather for a city."""
return f"Weather in {city}: 72F, sunny"
if __name__ == "__main__":
server.run()
Notice: zero tracking code inside
. MCPCat automatically captures all tool calls at the protocol level.
Step 6: Verify
- Read the modified file and confirm the import and call are correctly placed.
- Run
python -c "import mcpcat"
to verify the package is importable.
- If the project uses a linter (ruff, mypy, pyright), run it if configured.
- Tell the user:
MCPCat is integrated. Your server will automatically report analytics when it runs.
Enable debug logging:
MCPCAT_DEBUG_MODE=true python your_server.py
(logs to ~/mcpcat.log)
View your dashboard at
https://app.mcpcat.io
Common mistakes
| Mistake | Fix |
|---|
| Adding tracking code inside each tool function | MCPCat is automatic. Remove manual tracking. Only is needed. |
| Initializing MCPCat before server creation | mcpcat.track(server, ...)
needs the server variable. Call it AFTER . |
| Using for community FastMCP | Use pip install "mcpcat[community]"
when import is from fastmcp import FastMCP
. |
| Using without | Defaults to , overriding the env var. Pass it explicitly. |
| Using wrong env var name | The env var is , not . |