A library for implementing Model Context Protocol (MCP) servers in Python services with project authentication
Project description
Wazobia MCP Library
A reusable library for implementing Model Context Protocol (MCP) servers in Python services with project-based authentication.
Overview
This library provides a standardized way to add MCP functionality to Python services, with common tools like health checks, authentication, and utility functions that can be extended with service-specific tools. It includes specialized MCP project authentication for secure service-to-service communication.
Features
- Standardized MCP server implementation
- Built-in health checks (system, database, Redis, Kafka)
- MCP-specific project authentication with JWT verification
- FastAPI integration with automatic auth dependency injection
- Migration utilities for legacy systems
- Error handling and logging setup
- Redis caching for JWKS and token validation
Usage
Basic MCP Server with Project Authentication
from mcp_server_lib import mcp_project_auth
from fastapi import APIRouter, Depends
# Create router for MCP endpoints
router = APIRouter(prefix="/mcp", tags=["mcp"])
@router.get("/metrics")
async def get_metrics(
authenticated_project = Depends(mcp_project_auth),
page: int = 1,
per_page: int = 50
):
"""Get analytics metrics for authenticated project"""
project_uuid = authenticated_project.project_uuid
# Your logic here using the authenticated project
return {"project": project_uuid, "metrics": "..."}
@router.get("/health")
async def check_health():
"""Health check endpoint (no auth required)"""
return {"status": "healthy"}
Advanced Usage with MCP Server Class
from mcp_server_lib.core.mcp_service import MCPServer
from mcp_server_lib.models.config import MCPConfig
from mcp_server_lib.auth import JWTAuthenticator, mcp_project_auth
from mcp_server_lib.health.base_checks import SystemHealthCheck
# Create configuration
config = MCPConfig(
service_name="My Service",
service_description="A service with MCP support",
jwt_secret_key="your-secret-key"
)
# Create MCP server
mcp_server = MCPServer(config)
# Setup authentication
authenticator = JWTAuthenticator(secret_key=config.jwt_secret_key)
mcp_server.set_authenticator(authenticator)
# Register health checks
mcp_server.register_health_check(SystemHealthCheck())
# Get the FastAPI app to run
app = mcp_server.get_app()
Installation
pip install wazobia-mcp-lib
Environment Variables
For MCP project authentication, configure these environment variables:
MERCURY_BASE_URL=https://your-mercury-instance.com
SIGNATURE_SHARED_SECRET=your-shared-secret
SERVICE_ID=your-service-id
REDIS_URL=redis://localhost:6379
License
MIT
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 wazobia_mcp_lib-1.0.2.tar.gz.
File metadata
- Download URL: wazobia_mcp_lib-1.0.2.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3abd1a6cf1414daba179807383a5baa2aca94c4c48300fd351eea7bc86cd38a0
|
|
| MD5 |
dae19d696a4ce0ead0c6f6723b9d4978
|
|
| BLAKE2b-256 |
d574fa320d0f43f940dad17cbae5a8824c4e449847d8a0ccbe306a0b1a9eb5af
|
File details
Details for the file wazobia_mcp_lib-1.0.2-py3-none-any.whl.
File metadata
- Download URL: wazobia_mcp_lib-1.0.2-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
949e45bc704639459f823f518d1bf2f79703b69107eace2804612b64c270f50f
|
|
| MD5 |
321d0f738e1a2ff6679a4fc900e11951
|
|
| BLAKE2b-256 |
09e58cd634437228bb31f649756466b6617a8dda95ecd2cc851d0176b989a4a7
|