Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wazobia_mcp_lib-1.0.3.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

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

wazobia_mcp_lib-1.0.3-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file wazobia_mcp_lib-1.0.3.tar.gz.

File metadata

  • Download URL: wazobia_mcp_lib-1.0.3.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

Hashes for wazobia_mcp_lib-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e3986a4b9170892ec3167df5f365dc126346b1430ef02b2d525ab3a4f07d4272
MD5 d9465d07e064c70bed2f6ae1abedaf59
BLAKE2b-256 554433103a566d64f9e7445541c3bd40d4c73a7cc0e5b78a0eb1361840e43c83

See more details on using hashes here.

File details

Details for the file wazobia_mcp_lib-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for wazobia_mcp_lib-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb79f321f163fb14775487e39a495eb5a469e43ee2a74c44ec8a259ba5f0b291
MD5 82c88517816292ff3b5c270d6eb2b9d9
BLAKE2b-256 364e5d61311e2111f7694a0ebd0814375aece7861b4ed92837b3498a0735f733

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