MCP Server Hero

MCP Server Hero

A professional Python framework and template for building robust Model Context Protocol (MCP) servers with modular architecture, enterprise features like authentication and rate limiting, and comprehensive tooling. Provides easy-to-use APIs for registering tools, resources, and prompts with full type safety and multiple transport support.

Category
Visit Server

README

MCP Server Hero

A professional Model Context Protocol (MCP) server template and framework for building robust MCP servers in Python.

Features

  • ๐Ÿ—๏ธ Modular Architecture: Clean separation of tools, resources, prompts, and configuration
  • ๐Ÿ”ง Easy Registration: Simple APIs for registering tools, resources, and prompts
  • ๐Ÿ“ Type Safety: Full type hints and validation throughout
  • ๐Ÿš€ Multiple Transports: Support for stdio and SSE (Server-Sent Events) transports
  • ๐Ÿ“Š Professional Logging: Built-in logging and debugging support
  • ๐Ÿงช Testing Ready: Structured for easy testing with pytest
  • ๐Ÿ“– Comprehensive Examples: Both basic and advanced usage examples

Enterprise Features

  • โšก Middleware System: Request/response processing pipeline with validation, logging, timing, and rate limiting
  • ๐Ÿงฉ Plugin System: Dynamic plugin loading with dependency management
  • ๐Ÿ” Authentication & Authorization: Flexible auth providers with permission-based access control
  • ๐Ÿ’พ Caching System: Multi-layer caching with TTL support and LRU eviction
  • ๐Ÿ“Š Metrics & Monitoring: Comprehensive performance metrics and health checks
  • ๐Ÿ›ก๏ธ Rate Limiting: Token bucket rate limiting with per-client support

Quick Start

Installation

# Install uv package manager
make install-uv

# Install all dependencies
make install

# Or install production only
make install-prod

Basic Usage

from mcp_server_hero import MCPServerHero
import anyio
from mcp.server.stdio import stdio_server

async def add_numbers(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

async def main():
    # Create server instance
    server = MCPServerHero(name="My Server")
    
    # Register a tool
    server.add_tool(
        name="add",
        tool_func=add_numbers,
        description="Add two numbers",
        schema={
            "type": "object",
            "properties": {
                "a": {"type": "integer"},
                "b": {"type": "integer"}
            },
            "required": ["a", "b"]
        }
    )
    
    # Run the server
    async with stdio_server() as streams:
        await server.run(streams[0], streams[1], server.create_initialization_options())

if __name__ == "__main__":
    anyio.run(main)

Enterprise Usage

from mcp_server_hero import MCPServerHero
from mcp_server_hero.middleware.rate_limit import RateLimitMiddleware
from mcp_server_hero.auth.base import SimpleAuthProvider

# Create enterprise server
server = MCPServerHero("Enterprise Server", debug=True)

# Add advanced features
server.add_middleware(RateLimitMiddleware(tool_limit=100))
server.enable_auth_provider(SimpleAuthProvider())
await server.load_plugins_from_directory("plugins/")

# Initialize and run
await server.initialize()

Running Examples

# Run different server examples
make run-basic       # Basic function-based server
make run-advanced    # Class-based server with custom components  
make run-enterprise  # Full-featured enterprise server

# Run with different transports
make run-server      # SSE transport (web-based)
make run-stdio       # Stdio transport (direct communication)
make run-debug       # Debug mode with detailed logging

Development

# Code quality
make check          # Run all quality checks (lint + format + typecheck)
make test           # Run tests
make test-cov       # Run tests with coverage

# Individual quality checks  
make lint           # Code linting
make format         # Code formatting
make typecheck      # Type checking

Architecture

src/mcp_server_hero/
โ”œโ”€โ”€ core/              # Core server implementation
โ”‚   โ”œโ”€โ”€ cli.py         # Command-line interface
โ”‚   โ”œโ”€โ”€ server.py      # Main server class
โ”‚   โ””โ”€โ”€ version.py     # Version info
โ”œโ”€โ”€ tools/             # Tool management
โ”œโ”€โ”€ resources/         # Resource management  
โ”œโ”€โ”€ prompts/           # Prompt management
โ”œโ”€โ”€ middleware/        # Middleware system
โ”‚   โ”œโ”€โ”€ logging.py     # Request/response logging
โ”‚   โ”œโ”€โ”€ timing.py      # Performance monitoring
โ”‚   โ”œโ”€โ”€ validation.py  # Input validation
โ”‚   โ””โ”€โ”€ rate_limit.py  # Rate limiting
โ”œโ”€โ”€ plugins/           # Plugin system
โ”œโ”€โ”€ auth/              # Authentication framework
โ”œโ”€โ”€ cache/             # Caching system
โ”œโ”€โ”€ metrics/           # Metrics collection
โ”œโ”€โ”€ config/            # Configuration
โ”œโ”€โ”€ utils/             # Utilities
โ””โ”€โ”€ examples/          # Usage examples

Components

Tools

Tools perform actions and return results:

# Simple function tool
async def my_tool(param: str) -> str:
    return f"Result: {param}"

server.add_tool("my_tool", my_tool, "Description")

# Class-based tool with advanced features
from mcp_server_hero.tools.base import BaseTool

class MyTool(BaseTool):
    async def execute(self, arguments):
        return [TextContent(type="text", text="Result")]

Resources

Resources provide read-only data:

# Simple function resource
async def get_data() -> str:
    return "Resource data"

server.add_resource("data://example", get_data, "Example data")

Prompts

Prompts generate structured messages:

# Simple function prompt
async def create_prompt(topic: str) -> str:
    return f"Please explain {topic}"

server.add_prompt("explain", create_prompt, "Explanation prompt")

Middleware

Process requests through a pipeline:

from mcp_server_hero.middleware import ValidationMiddleware, TimingMiddleware

server.add_middleware(ValidationMiddleware())
server.add_middleware(TimingMiddleware())

Plugins

Extend functionality dynamically:

from mcp_server_hero.plugins.base import BasePlugin

class MyPlugin(BasePlugin):
    async def initialize(self, server):
        server.add_tool("plugin_tool", self.my_tool, "Plugin tool")

Configuration

from mcp_server_hero.config import ServerSettings

settings = ServerSettings(
    name="My Server",
    debug=True,
    log_level="DEBUG",
    timeout=60.0
)

server = MCPServerHero(settings=settings)

Monitoring & Metrics

The server provides comprehensive monitoring:

# Get server statistics
stats = server.get_server_stats()

# Get performance metrics  
metrics = await server.get_metrics()

# Health check
health = await server.health_check()

Project Commands

make help           # Show all available commands
make examples       # List example servers
make stats          # Show project statistics  
make clean          # Clean build artifacts

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run make check to verify code quality
  5. Add tests if applicable
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

MCP Protocol

This framework implements the Model Context Protocol (MCP), enabling seamless integration between AI models and external data sources and tools.

For more information about MCP, visit the official documentation.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured