Skip to main content

Usage tracking, analytics, and file logging for MCP (Model Context Protocol) servers

Project description

mcpstat

PyPI - Version GitHub License PyPI - Python Version GitHub Actions Workflow Status PyPI - Downloads Checked with mypy Security: bandit Codecov

Usage tracking and analytics for MCP servers. Pure Python, zero required dependencies.

Track which tools get called, how often, and keep an audit trail - all in 3 lines of code.

Installation

pip install mcpstat

With MCP SDK:

pip install "mcpstat[mcp]"

Quick Start

from mcp.server import Server
from mcpstat import MCPStat

app = Server("my-server")
stat = MCPStat("my-server")

@app.call_tool()
@stat.track  # ← One decorator does everything!
async def handle_tool(name: str, arguments: dict):
    # Your logic here - latency tracked automatically
    return await my_logic(arguments)

Then ask your AI assistant: "Give me MCP usage stats"

Features

  • SQLite-backed - Stats persist across restarts
  • Built-in MCP tools - get_tool_usage_stats, get_tool_catalog
  • Tag system - Categorize and filter tools
  • Token tracking - Estimate or record actual token usage
  • Latency tracking - Measure execution duration, identify slow tools
  • File logging - Optional timestamped audit trail
  • Async-first - Thread-safe via asyncio.Lock

Documentation

Full Documentation - Quick start, API reference, examples

Examples

# Clone and run example server
git clone https://github.com/tekkidev/mcpstat.git
cd mcpstat
pip install -e ".[mcp]"
python examples/example_server.py

See examples/ for minimal and full integration patterns.

Contributing

See CONTRIBUTING.md. Run tests with:

pip install "mcpstat[dev]"
pytest tests/

License

MIT - see LICENSE for details.


MCP is a trademark of its respective owners. This project is not affiliated with or endorsed by any trademark holders.

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

mcpstat-0.2.2.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

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

mcpstat-0.2.2-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file mcpstat-0.2.2.tar.gz.

File metadata

  • Download URL: mcpstat-0.2.2.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mcpstat-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8346e4c8a35359a8000366521e0a673e2b1ffdbfeed18e406e0d067185dc292b
MD5 1bd93e47a6798d98f56ab685198198b5
BLAKE2b-256 eb0dbed573866b34c94b68acb579c7adf5dd58b310d74c0837260ebc937b761a

See more details on using hashes here.

File details

Details for the file mcpstat-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: mcpstat-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mcpstat-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f96ad0ccbe77ea0fea096e11c5c4571058abdc741ccb867d2aa9be20a8be666
MD5 f267eb43983eca89ba8c646a574c5f24
BLAKE2b-256 f83b89f05c177136f5d56df44182deb9aa24162ec689ccfa1f6bf014f7241abf

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