Open, vendor-agnostic observability SDK for Model Context Protocol (MCP) applications
Project description
MCP Observability SDK for Python
Open, vendor-agnostic observability SDK for Model Context Protocol (MCP) applications. No vendor lock-in, plug-and-play integration, and extensible for rate limiting, tool filtering, auth, and traceability.
Installation
pip install mcp-hack
Quick Start
import os
from mcp_observability import MCPObservability
# Initialize observability
obs = MCPObservability(
api_url="http://localhost:3001", # Your backend URL
api_key=os.getenv('MCP_API_KEY') # Get from your dashboard
)
# Add observability to your MCP tools
@mcp.tool()
@obs.tool_observer("add_numbers")
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
# Get metrics
metrics = obs.get_metrics()
print(f"Total calls: {metrics['summary']['total_calls']}")
Features
- 🔍 Automatic Tool Tracing: Monitor all MCP tool calls with zero configuration
- 📊 Rich Metrics: Execution time, success rates, error tracking
- 🚀 Non-blocking: Async trace submission doesn't slow down your tools
- 🔒 Secure: API key authentication with environment variable support
- 📈 Dashboard Integration: Real-time visualization of your MCP tools
API Reference
MCPObservability
Main class for MCP observability.
Constructor
MCPObservability(api_url: str, api_key: Optional[str] = None)
api_url: URL of your observability backendapi_key: API key for authentication (optional, but required for trace submission)
Methods
tool_observer(tool_name: Optional[str] = None)
Decorator to add observability to MCP tools.
@obs.tool_observer("my_tool")
def my_tool(param: str) -> str:
return f"Hello {param}"
trace(task: str, context: Dict[str, Any], model_output: str, metadata: Optional[Dict[str, Any]] = None)
Send a custom trace to the backend.
obs.trace(
task="Custom Task",
context={"user_input": "Hello"},
model_output="Response",
metadata={"custom_field": "value"}
)
get_metrics() -> Dict[str, Any]
Get current metrics snapshot.
metrics = obs.get_metrics()
print(metrics['summary']['total_calls'])
print_metrics()
Print formatted metrics to console.
obs.print_metrics()
Environment Variables
MCP_API_KEY: Your API key from the observability dashboardBACKEND_URL: URL of your observability backend (default: http://localhost:3001)
License
MIT License. See LICENSE file for details.
Contributing
Contributions are welcome! Please see our Contributing Guide.
Links
- Documentation
- GitHub Repository
- Issue Tracker
- Dashboard (when running locally)
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 mcp_observability-0.1.1.tar.gz.
File metadata
- Download URL: mcp_observability-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f806a0e71edc68e1273324df853381ba693a11431fb6c113328482b46d85fa82
|
|
| MD5 |
9292eb319268e601e686b19ca85fd187
|
|
| BLAKE2b-256 |
567bc6c963bc9d1997bb2e8bd5a378cb5085bdd04f1b47e5c1d7e8a439496a58
|
File details
Details for the file mcp_observability-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_observability-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e6b14d34579abf863dd38537095d690df035695bfb85567c9f78b2ffda410d9
|
|
| MD5 |
67d27f5f3c2f374342b26207333324f1
|
|
| BLAKE2b-256 |
169f35537ffd3a9d730d27cce71d1e8f92e0864ef0b3fc584237c1ac27d0caea
|