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 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()
async def handle_tool(name: str, arguments: dict):
    await stat.record(name, "tool")  # ← Add as FIRST line
    # ... your tool logic

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
  • 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.1.tar.gz (37.2 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.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcpstat-0.2.1.tar.gz
  • Upload date:
  • Size: 37.2 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.1.tar.gz
Algorithm Hash digest
SHA256 69e6585ef69e0f17cfca51348b02394e44b35f4f25acdc848783a8783110ba09
MD5 c616f44087cf574af2121dc2b229a103
BLAKE2b-256 badbf8a0d8d0a91a805857dfbf22199b3bd9eb307710bceb5680e87bb2d4b9f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcpstat-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b73c712a0a6620e43a7d4bfd2cd2dde989fbc42c94b4ba23b3a4921bba2bdc1d
MD5 bea2c8473906575adf9cb715e592fa5b
BLAKE2b-256 bd23d54a72ec532ba85573fc55cd208a0c8057b2917607661041ccad26b20b0b

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