Skip to main content

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

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(
    enableToolCallContext=True,   # Add context parameters to tools
    enableTracing=True,           # Trace tool calls
    enableReportMissing=True,     # Add report_missing tool
    identify=my_identify_func     # Custom session identification
)

track(mcp, options)

How It Works

  1. MCPCat intercepts the MCP server's tool listing and calling mechanisms
  2. It injects a context parameter into each tool's schema
  3. When tools are called, it captures analytics data including timing, arguments, and results
  4. The report_missing tool 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",
        "userId": "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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcpcat-0.1.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcpcat-0.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file mcpcat-0.1.0.tar.gz.

File metadata

  • Download URL: mcpcat-0.1.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for mcpcat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49fc79650840757f1155535dd95fb2f756cfc80dbed8738ab8406c0d4442dacb
MD5 51ab7372d4d51f483f7f9a8e099950bd
BLAKE2b-256 a2884a9a7de03a50d01e37ac2743dd32f97cf8200fb4bcf7960ee124c6f939e3

See more details on using hashes here.

File details

Details for the file mcpcat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcpcat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for mcpcat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c12146829e150fe28b88a7d1d54ca19debdeb9be6e8c3cc3a74cfefc367e68a3
MD5 4e79514d32c7de7fe1d89f7f718190b1
BLAKE2b-256 e4d8684ec3c8940d1e21af36d89229237e55fe938c00c6352106de9d4b069cd0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page