Pydantic RPC

v1.0.0Developer Toolsstable

PydanticRPC is a Python library for rapidly exposing Pydantic models as gRPC, ConnectRPC, and MCP services without protobuf files.

connectrpcgrpcmcpmcp-serverprotobuf
Share:
74
Stars
0
Downloads
0
Weekly
0/5

What is Pydantic RPC?

Pydantic RPC is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to pydanticrpc is a python library for rapidly exposing pydantic models as grpc, connectrpc, and mcp services without protobuf files.

PydanticRPC is a Python library for rapidly exposing Pydantic models as gRPC, ConnectRPC, and MCP services without protobuf files.

This server falls under the Developer Tools category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • PydanticRPC is a Python library for rapidly exposing Pydanti

Use Cases

Expose Pydantic models as gRPC, ConnectRPC, and MCP services.
Eliminate protobuf files with Python-native service generation.
i2y

Maintainer

LicenseMIT
Languagepython
Versionv1.0.0
UpdatedMay 8, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx pydantic-rpc

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use Pydantic RPC

PydanticRPC is a Python library that lets you expose Pydantic model-based services as gRPC, ConnectRPC, and Model Context Protocol (MCP) endpoints without writing a single .proto file. It auto-generates protobuf definitions from Python type hints at runtime, supports unary and streaming patterns, and includes built-in health checks and server reflection. Developers use it to rapidly turn existing Python classes into production-grade RPC services or MCP tool servers with minimal boilerplate.

Prerequisites

  • Python 3.9 or higher
  • pip install pydantic-rpc (or pydantic-rpc-cli for CLI support and Hypercorn/Gunicorn servers)
  • Pydantic v2 installed (pulled in automatically as a dependency)
  • An MCP-compatible client such as Claude Desktop or Claude Code if using the MCP transport
  • For gRPC: grpcio and grpcio-tools available in the environment
1

Install PydanticRPC

Install the core library. Add the CLI extra if you want the pydantic-rpc command for generating protos and running servers from the terminal.

pip install pydantic-rpc
# Or with CLI tools:
pip install pydantic-rpc-cli
2

Define your service with Pydantic models

Create a Python class whose methods accept and return Pydantic BaseModel instances. PydanticRPC will auto-generate the protobuf schema from these type hints.

from pydantic import BaseModel
from pydantic_rpc import AsyncIOServer

class EchoRequest(BaseModel):
    message: str

class EchoResponse(BaseModel):
    reply: str

class EchoService:
    async def echo(self, req: EchoRequest) -> EchoResponse:
        return EchoResponse(reply=f"You said: {req.message}")
3

Run as a gRPC server

Wrap your service class in AsyncIOServer and run it. The server will auto-generate the .proto file and start listening on the specified port.

import asyncio
from pydantic_rpc import AsyncIOServer

async def main():
    server = AsyncIOServer(service=EchoService(), port=50051)
    await server.run()

asyncio.run(main())
4

Run as a ConnectRPC ASGI application

Expose the same service over HTTP/1.1 and HTTP/2 using the ASGI adapter, suitable for deployment behind any ASGI server.

from pydantic_rpc import ASGIApp

app = ASGIApp(service=EchoService(), package_name="my.service")
# Run with: uvicorn script:app --port 8000
5

Expose as an MCP tool server

Use the CLI to serve your service over the MCP transport so AI assistants can call its methods as structured tools.

pydantic-rpc serve myapp.services.EchoService --mcp --port 8000
6

Configure your MCP client

Point Claude Desktop or another MCP client at the running server using the streamable-HTTP transport URL.

{
  "mcpServers": {
    "pydantic-rpc": {
      "command": "python",
      "args": ["-m", "pydantic_rpc.cli", "serve", "myapp.services.EchoService", "--mcp"]
    }
  }
}

Pydantic RPC Examples

Client configuration

Configure Claude Desktop to launch your PydanticRPC MCP service directly as a subprocess.

{
  "mcpServers": {
    "pydantic-rpc": {
      "command": "python",
      "args": ["-m", "pydantic_rpc.cli", "serve", "myapp.services.EchoService", "--mcp"]
    }
  }
}

Prompts to try

Once connected, Claude can call your service methods as MCP tools by their Python method names.

- "Call the echo method with the message 'Hello from Claude'"
- "Generate a protobuf file for the UserService class and show me the output"
- "Run the EchoService and send it ten messages, then summarize the responses"
- "Explain what tools are available from this MCP server and what each one does"

Troubleshooting Pydantic RPC

Protobuf generation fails with field number conflicts after adding new fields

Set PYDANTIC_RPC_RESERVED_FIELDS=1 to reserve field numbers for backward compatibility. You can also set PYDANTIC_RPC_PROTO_PATH to a custom directory to inspect the generated .proto files.

Slow startup because protobuf is regenerated on every launch in production

Set PYDANTIC_RPC_SKIP_GENERATION=true to skip runtime protobuf generation. Pre-generate the files during your build step with 'pydantic-rpc generate myapp.services.MyService --output ./proto/'.

Nested Pydantic models are not serialized correctly in gRPC responses

Adjust PYDANTIC_RPC_SERIALIZER_STRATEGY to 'deep' or 'shallow' depending on how deeply nested models should be resolved. The default 'none' strategy may skip nested model serialization.

Frequently Asked Questions about Pydantic RPC

What is Pydantic RPC?

Pydantic RPC is a Model Context Protocol (MCP) server that pydanticrpc is a python library for rapidly exposing pydantic models as grpc, connectrpc, and mcp services without protobuf files. It connects AI assistants to external tools and data sources through a standardized interface.

How do I install Pydantic RPC?

Follow the installation instructions on the Pydantic RPC GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with Pydantic RPC?

Pydantic RPC works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is Pydantic RPC free to use?

Yes, Pydantic RPC is open source and available under the MIT license. You can use it freely in both personal and commercial projects.

Browse More Developer Tools MCP Servers

Explore all developer tools servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "pydantic-rpc": { "command": "npx", "args": ["-y", "pydantic-rpc"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

Ready to use Pydantic RPC?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides