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.0.tar.gz (20.9 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.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wazobia_mcp_lib-1.0.0.tar.gz
  • Upload date:
  • Size: 20.9 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.0.tar.gz
Algorithm Hash digest
SHA256 d0b4becfef48036f245150e7fcf45602d13a91a90aac813f4854fb02b9853336
MD5 d48bd6e4347e209a6cbca8909bcbe2bb
BLAKE2b-256 5404bf6be730b059d1e3baef20270452a68fffed13c48bde205e66b3c359ba06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wazobia_mcp_lib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03811b48ee656cee0068cd6352880a7c247484b16c3a8a4692cbd6a7f25683b9
MD5 06ba5d828c1da100a60d90cc7a5cc297
BLAKE2b-256 dd205c4f9321271ef971023541a163915d8ab37dec2b68e8b36578bcaee8bb20

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