Analytics Tool for MCP Servers - provides insights into MCP tool usage patterns
Project description
MCPCat Python SDK
Analytics tool for MCP (Model Context Protocol) servers that provides insights into tool usage patterns.
Features
- Tool Usage Analytics: Tracks which tools are called and how frequently
- Context Injection: Adds context parameters to tools to understand user intent
- Session Tracking: Identifies and tracks user sessions
- Report Missing Tools: Allows clients to report when needed tools are missing
- PII Redaction: Automatically redacts sensitive information from logs
- Non-invasive Integration: Simple one-line integration with existing MCP servers
Compatibility
MCPCat officially supports >=v1.2.0 of the Python SDK. Support for >=1.0.0 is experimental.
Installation
pip install mcpcat
Quick Start
from fastmcp import FastMCP
from mcpcat import track
# Create your MCP server
mcp = FastMCP("my-server")
# Add your tools
@mcp.tool()
def my_tool(arg: str) -> str:
return f"Result: {arg}"
# Enable MCPCat tracking
track(mcp)
# Run the server
mcp.run()
Configuration
MCPCat can be configured with various options:
from mcpcat import track, MCPCatOptions
options = MCPCatOptions(
enable_tool_context=True, # Add context parameters to tools
enable_tracing=True, # Trace tool calls
enable_report_missing=True, # Add report_missing tool
identify=my_identify_func # Custom session identification
)
track(mcp, options)
How It Works
- MCPCat intercepts the MCP server's tool listing and calling mechanisms
- It injects a
contextparameter into each tool's schema - When tools are called, it captures analytics data including timing, arguments, and results
- The
report_missingtool allows LLMs to report when they need functionality that isn't available
Custom Session Identification
You can provide a custom function to identify users:
def identify_user(request_context):
# Your logic to identify the user
return {
"sessionId": "session-123",
"user_id": "user-456"
}
options = MCPCatOptions(identify=identify_user)
Log Format
MCPCat logs are written in JSON format with the following structure:
{
"timestamp": "2024-01-20T10:30:00Z",
"event": "tool_call",
"tool_name": "my_tool",
"session_id": "session-123",
"user_id": "user-456",
"duration": 0.123,
"result": "success",
"context_provided": true
}
Development
To set up for development:
# Clone the repository
git clone https://github.com/yourusername/mcpcat-python-sdk.git
cd mcpcat-python-sdk
# Install dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run type checking
mypy src
# Run linting
ruff check src
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcpcat-0.1.0b6.tar.gz.
File metadata
- Download URL: mcpcat-0.1.0b6.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096907ff881d206129b7add1d28191dd0eadb533b829937796dfc675beef3f75
|
|
| MD5 |
25b4e9db8870023634910b08eb4d0caf
|
|
| BLAKE2b-256 |
bacf208f59a7c155b0094968ff4cf98c02f2cd845458dd7e069028ed17295880
|
File details
Details for the file mcpcat-0.1.0b6-py3-none-any.whl.
File metadata
- Download URL: mcpcat-0.1.0b6-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
549843b5f72f03a99688e598645d143d6e9a1b4235b93c7c43ec8a6ef6f2dcb3
|
|
| MD5 |
b74d3fcbd5a2b4b527490f2021b1a63d
|
|
| BLAKE2b-256 |
acace98067c30dcb238cfbd21768d096d7fed62ac8868e702bd42502654df87a
|