Skip to main content

mcpstat

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

Python observability and usage analytics for MCP (Model Context Protocol) servers.

Track tool, prompt, and resource calls, successful and failed invocations, and execution latency in local SQLite storage. Add tracking to your existing Python MCP server and expose its statistics as MCP tools that an assistant can query. Optional file logging provides an audit trail.

Installation

pip install mcpstat
pip install "mcpstat[server]"  # Includes the SDK for the example below

Quick Start

from mcp.server import MCPServer
from mcpstat import MCPStat, disable_sdk_tracing

app = MCPServer("my-server")
disable_sdk_tracing(app)
stat = MCPStat("my-server")


@app.tool()
@stat.track(name="echo")
async def echo(message: str) -> str:
    """Return a message, tracking usage and latency automatically."""
    return message


@app.tool()
async def get_tool_usage_stats() -> dict:
    """Return cumulative MCP usage statistics."""
    return await stat.get_stats()


if __name__ == "__main__":
    try:
        app.run()
    finally:
        stat.close()

Connect your assistant to this server, then ask: "Give me MCP usage stats"

For a complete request-to-statistics example, follow the weather server walkthrough. It demonstrates successful calls, an intentional failure, unused tools, and statistics that persist after restarting the server.

Choose Your Integration

Use case Installation What it tracks
Add tracking to an existing Python server pip install mcpstat The handlers you instrument with the SDK-independent library; keep your server's MCP SDK installed separately.
Run the bundled documentation and demonstration server pip install "mcpstat[server]" Its own temperature conversion tools and other registered handlers.

The decorator records usage; register a statistics tool such as get_tool_usage_stats to query that data from Claude Code, VS Code, or another MCP client. The standalone server does not automatically observe other MCP servers.

Use mcpstat for Visual Studio Code to view calls, errors, latency and handler usage. Your server records the statistics. The extension reads them through VS Code's MCP tools, an HTTP endpoint, or directly from a SQLite database.

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 - Database operations run in worker threads with serialized transactions

Install mcpstat for the SDK-independent tracking library. The [server] extra includes the SDK and the runnable mcpstat documentation and demonstration server. The standalone server tracks its own calls; integrate the library into each server you want to monitor.

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 ".[dev]"
python examples/example_server.py

See examples/ for minimal and full integration patterns.

Contributing

See CONTRIBUTING.md. From a repository checkout, run tests with:

python -m pip install -e ".[dev]"
python -m 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.

Metadata

Release files for mcpstat 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcpstat 0.3.1
File Size Uploaded Provenance Actions
mcpstat-0.3.1.tar.gz 72.2 kB With provenance Details for mcpstat-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcpstat 0.3.1
File Interpreter ABI Platform Actions
mcpstat-0.3.1-py3-none-any.whl Python 3 none any Details for mcpstat-0.3.1-py3-none-any.whl

Total release size: 129.8 kB

Release files / mcpstat-0.3.1.tar.gz

Download URL mcpstat-0.3.1.tar.gz
Size 72.2 kB
Tags Source
SHA-256 checksum
How to use checksums
847cb205f8fd840083e056e1fcd8ee9f54a546d9e56aea02443f537940b13310
BLAKE2b-256 checksum
How to use checksums
ef7329ede1a4e0e1f2eeb2f6e82e32d4a042468fa456930a17ded49b2a410928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / mcpstat-0.3.1-py3-none-any.whl

Download URL mcpstat-0.3.1-py3-none-any.whl
Size 57.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec3927e6a6856479d4c3604fe51f7892499059f122a9f4e1a5c2204edf697846
BLAKE2b-256 checksum
How to use checksums
163ed8f6645d39f7316dc86035ba5688bda1bcde07d67a26b0d220bd09bf5d44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for mcpstat 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mcpstat-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page