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.1.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.1-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wazobia_mcp_lib-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d72a76a6e403a22a53f971407b01dc64f0ae562255fc7f7107876e2f07d7c08f
MD5 641930c7729549e81e4b2fe64d7784ed
BLAKE2b-256 a32adf0be7677ceaa4c5b5dc8cb9b8a5588257b9e3a9693e547563e4670e3ad5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wazobia_mcp_lib-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a90abd8eb01581ee74f531337b89478142406e6e7c3e8d1ad3a4d135cc28330
MD5 89b11fcf6721970420c56ce29d31e60c
BLAKE2b-256 a8791527e52a0dafe6fb29bff40d949750d478ebdd11560d74d31a0d4109d9be

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