# ProdMCP

> **FastAPI-like production layer on top of FastMCP** — schema-driven development, validation, security, middleware, and automatic OpenMCP specification generation.
FastAPI is built on top of Starlette and Pydantic. ProdMCP is built on top of FastMCP and Pydantic.

> **Production Grade security and validation layer for MCP** — We support multiple security providers and validation schemas. While also defining a seperate spec OpenMCP spec (similar to what OpenAPI is for Rest APIs). 42Crunch like security providers can validate the MCP server against the OpenMCP spec. Helping with Enterprice MCP adoption

> **OpenMCP spec** — Checkout OpenMCP-spec at https://github.com/ProdMCP/OpenMCP-spec/blob/main/schemas/v1.0.0/schema.json


## Installation

```bash
pip install prodmcp
```

## Quick Start

```python
from pydantic import BaseModel
from prodmcp import ProdMCP

app = ProdMCP("MyServer", version="1.0.0")


# --- Define Schemas ---

class UserInput(BaseModel):
    user_id: str

class UserOutput(BaseModel):
    name: str
    email: str


# --- Define a Tool ---

@app.tool(
    name="get_user",
    input_schema=UserInput,
    output_schema=UserOutput,
    security=[{"type": "bearer", "scopes": ["user"]}],
)
def get_user(user_id: str) -> dict:
    return {"name": "Alice", "email": "alice@example.com"}


# --- Define a Prompt ---

@app.prompt(
    name="summarize",
    input_schema=UserInput,
)
def summarize(user_id: str) -> str:
    return f"Please summarize data for user {user_id}"


# --- Define a Resource ---

@app.resource(
    uri="data://users",
    name="user_db",
    output_schema=UserOutput,
)
def fetch_users() -> list:
    return [{"name": "Alice", "email": "alice@example.com"}]


# --- Export OpenMCP Spec ---

spec = app.export_openmcp()
print(spec)

# --- Run the server ---

if __name__ == "__main__":
    app.run()
```

## Features

- **Decorator API** — `@app.tool()`, `@app.prompt()`, `@app.resource()` with schema, security, and middleware support
- **Schema-First** — Pydantic models or raw JSON Schema for input/output definitions
- **Validation Engine** — Automatic input/output validation with structured error reporting
- **Security Layer** — Bearer tokens, API keys, custom auth providers
- **Middleware System** — Global before/after hooks (logging, rate limiting, tracing)
- **Dependency Injection** — Composable dependencies injected into handlers
- **OpenMCP Spec** — Auto-generated, machine-readable specification from code

## License

MIT
