MCP Catalogs
首页

pydantic-rpc

by i2y·74·综合分 45

PydanticRPC 快速将 Pydantic 模型暴露为 gRPC、ConnectRPC 和 MCP 服务,无需 protobuf 文件。

developer-toolsai-llm
7
Forks
1
活跃 Issue
3 个月前
最近提交
2 天前
收录于

概述

PydanticRPC 是一个 Python 库,能够从 Pydantic 模型签名自动生成 protobuf 文件,让开发者能通过多种协议快速暴露服务。该库全面支持 gRPC 和 Connect-RPC,内置健康检查、服务器反射和流传输等功能。其 MCP 支持允许通过 stdio 和 HTTP/SSE 传输将服务暴露为 AI 助手工具,使其适用于 AI 集成场景。

试试问 AI

装完之后,这里有 5 个你可以让 AI 做的事:

:构建通过 MCP 协议暴露工具的 AI 服务
:无需编写 protobuf 文件创建 gRPC 服务
:使用 Connect-RPC 开发基于 HTTP 的 RPC 服务
:PydanticRPC 支持哪些协议?
:在生产环境中可以跳过 protobuf 生成吗?

什么时候选它

当您需要通过多种协议暴露具有强类型定义的 Python 服务并希望避免手动定义 protobuf 时,选择 PydanticRPC。

什么时候不要选它

如果您需要对生成的 protobuf 文件进行精细控制或需要内置的全面可观测性等高级功能,应避免使用。

此 server 暴露的工具

从 README 抽取出 2 个工具
  • ask(req: OlympicsQuery) -> CityLocation

    Query information about Olympic locations for a specific year

  • ask_stream(req: OlympicsDurationQuery) -> AsyncIterator[StreamingResult]

    Stream information about Olympic locations across a range of years

说明:Tool names were inferred from the example code showing methods of the OlympicsAgent class. The actual MCP tool naming convention isn't explicitly documented in this README excerpt.

可对比工具

fastapi-mcppython-mcpgrpc-gateway

安装

通过 pip 安装 PydanticRPC:

pip install pydantic-rpc

安装 CLI 支持:

pip install pydantic-rpc-cli

在 Claude Desktop 中使用,添加到 config.json:

{
  "mcpServers": {
    "pydantic-rpc": {
      "command": "python",
      "args": ["-m", "pydantic_rpc.server"],
      "env": {
        "PYDANTIC_RPC_PACKAGE_NAME": "my.services"
      }
    }
  }
}

FAQ

PydanticRPC 支持哪些协议?
PydanticRPC 支持 gRPC、Connect-RPC 和 MCP 协议,MCP 支持 stdio 和 HTTP/SSE 两种传输方式。
在生产环境中可以跳过 protobuf 生成吗?
是的,设置环境变量 PYDANTIC_RPC_SKIP_GENERATION=true 可跳过运行时生成,使用预生成的模块。

pydantic-rpc 对比

GitHub →

最后更新于 · 由 README + GitHub 公开数据自动生成。