经 AI Skill Hub 精选评估,Pydantic Resolve 获评「强烈推荐」。这款MCP工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.0 分,适合有一定技术背景的用户使用。
Python实现的MCP工具,提供清晰的架构设计
Pydantic Resolve 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
Python实现的MCP工具,提供清晰的架构设计
Pydantic Resolve 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/KLR-Pattern/pydantic-resolve
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"pydantic-resolve": {
"command": "npx",
"args": ["-y", "pydantic-resolve"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 Pydantic Resolve 执行以下任务... Claude: [自动调用 Pydantic Resolve MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"pydantic_resolve": {
"command": "npx",
"args": ["-y", "pydantic-resolve"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
A progressive data-assembly framework for Python in Clean Architecture style — adopt each layer as you need it.
Requirements: Python 3.10+, Pydantic v2
---
pip install pydantic-resolve
pip install pydantic-resolve[mcp] # with MCP support
Throughout the Quick Start, we build one API:
Sprint has many TaskTask has one owner (a User)task_count and contributorsEach step adds one concept on top of the previous code.
from typing import Optional
from pydantic import BaseModel
from pydantic_resolve import Relationship, base_entity, config_global_resolver
BaseEntity = base_entity()
class UserEntity(BaseModel, BaseEntity):
id: int
name: str
class TaskEntity(BaseModel, BaseEntity):
__relationships__ = [
Relationship(fk='owner_id', name='owner', target=UserEntity, loader=user_loader)
]
id: int
title: str
owner_id: int
class SprintEntity(BaseModel, BaseEntity):
__relationships__ = [
Relationship(fk='id', name='tasks', target=list[TaskEntity], loader=task_loader)
]
id: int
name: str
diagram = BaseEntity.get_diagram()
AutoLoad = diagram.create_auto_load()
config_global_resolver(diagram)
class TaskView(TaskEntity):
# Field name matches Relationship(name='owner') → AutoLoad is implicit
owner: Optional[UserEntity] = None
class SprintView(SprintEntity):
# Field name matches Relationship(name='tasks') → AutoLoad is implicit
tasks: list[TaskView] = []
task_count: int = 0
def post_task_count(self):
return len(self.tasks)
Compared with the Core API version:
resolve_owner disappears.resolve_tasks disappears.post_* still works exactly the same.Annotated[..., AutoLoad()] is optional (implicit AutoLoad). Use the explicit form only when the field name differs from the relationship name.If you want to hide internal FK fields such as owner_id, add DefineSubset on top of the ERD setup:
from pydantic_resolve import DefineSubset
class TaskSummary(DefineSubset):
__subset__ = (TaskEntity, ('id', 'title'))
owner: Optional[UserEntity] = None # implicit AutoLoad
Compose GraphQL queries over UseCaseService classes — the API surface is a set of business operations, not a graph of entities:
from pydantic_resolve import query
from pydantic_resolve.use_case import UseCaseService
from pydantic_resolve.use_case.manager import UseCaseAppConfig, UseCaseManager
class UserService(UseCaseService):
"""User management."""
@query
async def list_users(cls) -> list[UserSummary]:
"""Get all users."""
...
manager = UseCaseManager(
apps=[UseCaseAppConfig(name="blog", services=[UserService])]
)
app = manager.get_app("blog")
result = await app.compose("{ listUsers { id name } }")
Use this when the API is operation-first (RPC-style) rather than entity-graph-first.
Expose UseCase operations to AI agents via the same compose surface:
from pydantic_resolve.use_case import (
UseCaseAppConfig,
create_use_case_graphql_mcp_server,
)
mcp = create_use_case_graphql_mcp_server(
apps=[UseCaseAppConfig(name="blog", services=[UserService, PostService])],
)
mcp.run()
The MCP server uses a 4-layer progressive disclosure (list_apps → describe_compose_schema → describe_compose_method → compose_query) so the agent can discover operations and shape queries without flooding its tool list.
When parent and child nodes need to share data without hard-coding references to each other, two helpers cover the two directions.
Send a value from an ancestor down to its descendants.
from typing import Annotated
from pydantic_resolve import ExposeAs
class SprintView(BaseModel):
id: int
name: Annotated[str, ExposeAs('sprint_name')] # visible to all descendants
tasks: List[TaskView] = []
def resolve_tasks(self, loader=Loader(task_loader)):
return loader.load(self.id)
class TaskView(BaseModel):
id: int
title: str
owner_id: int
owner: Optional[UserView] = None
full_title: str = ""
def resolve_owner(self, loader=Loader(user_loader)):
return loader.load(self.owner_id)
def post_full_title(self, ancestor_context):
return f"{ancestor_context['sprint_name']} / {self.title}"
Use this when a child needs context from an ancestor (sprint name, permissions, locale).
Aggregate values from many descendants up to one ancestor.
from typing import Annotated
from pydantic_resolve import Collector, SendTo
class SprintView(BaseModel):
id: int
name: str
tasks: List[TaskView] = []
contributors: list[UserView] = []
def resolve_tasks(self, loader=Loader(task_loader)):
return loader.load(self.id)
def post_contributors(self, collector=Collector('contributors')):
return collector.values()
class TaskView(BaseModel):
id: int
title: str
owner_id: int
owner: Annotated[Optional[UserView], SendTo('contributors')] = None
def resolve_owner(self, loader=Loader(user_loader)):
return loader.load(self.owner_id)
Use this when a parent needs to aggregate values from many descendants (all contributors, all tags, all attachments).
---
Start with resolve_* and post_* on one endpoint. You gain immediate N+1 protection without changing your architecture.
The library exposes your data through two entry points — ERD mode (data-model-first) and UseCase mode (operation-first). Both can power GraphQL, MCP, and admin tools:
| Question | Hand-written Core API | ER Diagram + AutoLoad |
|---|---|---|
| First endpoint | Faster | Slower |
| Upfront setup | Low | Medium |
| Reusing the same relation in many models | Repetitive | Centralized |
| Changing a relationship later | Update many resolve_* methods | Update one ERD declaration |
| GraphQL / MCP generation | Separate work | Natural extension |
ERD mode asks for more discipline up front:
AutoLoad from the same diagram used by the resolver.That setup cost is real. The payoff is that relationship knowledge converges into one place — every Response is just a different view of the same Entity graph. The same ERD also powers GraphQL queries, MCP services, and admin tools.
| Dimension | ORM-First | Entity-First |
|---|---|---|
| Type source of truth | ORM model | Entity (Pydantic) |
| Relationship wiring | Repeated per endpoint | Centralized in ERD |
| Data assembly | Manual in Service/Route | Automatic via Resolver |
| N+1 prevention | Manual eager loading | Built-in DataLoader batching |
| Multi-data source | Scattered conversion code | Unified Loader interface |
| API contract stability | Tied to DB schema | Independent of DB |
| Feature | GraphQL | pydantic-resolve |
|---|---|---|
| **N+1 Prevention** | Manual DataLoader setup | Built-in automatic batching |
| **Type Safety** | Separate schema files | Native Pydantic types |
| **Learning Curve** | Steep (Schema, Resolvers, Loaders) | Moderate (Loader/batch pattern required) |
| **Debugging** | Complex introspection | Standard Python debugging |
| **Integration** | Requires dedicated server | Works with any framework |
| **Query Flexibility** | Any client can query anything | Explicit API contracts |
Note: pydantic-resolve borrows the DataLoader batch pattern from GraphQL ecosystems but stays inside your existing REST framework. If you already use strawberry or ariadne and are happy with it, pydantic-resolve may be redundant for you.
---
pydantic-resolve 是一个专为 Python 设计的整洁架构(Clean Architecture)工具库。它允许开发者定义业务实体并声明它们之间的关系,通过框架自动完成数据的组装。它旨在解决传统开发中手动处理数据关联时产生的复杂性,让你的代码从繁琐的 N+1 查询组装逻辑中解脱出来,实现业务逻辑与数据获取层的优雅分离。
该框架的核心优势在于“声明式数据��装”。通过在 Pydantic 模型中定义 resolve 方法,你可以声明哪些字段需要额外加载,而无需在业务逻辑层手动编写复杂的映射和循环。这不仅能有效防止 N+1 查询问题,还能将 Interface Adapter(接口适配器)逻辑内聚在模型中,使 Application Business Rules(应用业务规则)更加纯粹。
你可以通过 pip 轻松安装 pydantic-resolve。基础版本使用 `pip install pydantic-resolve` 即可;如果你的项目需要支持 MCP(Model Context Protocol),请使用 `pip install pydantic-resolve[mcp]` 进行安装。
在 Quick Start 示例中,我们将构建一个包含 Sprint、Task 和 User 关系的 API。通过定义模型关系,框架能够自动处理复杂的嵌套结构(如 Sprint 包含多个 Task,而 Task 关联特定的 User),并支持生成如 task_count 等派生字段。此外,你还可以通过 ERD 模式将关系逻辑从模型中抽离到实体图中,实现更高级的数据建模。
项目支持通过 ERD 模式进行关系建模,并提供全局 Resolver 配置。对于需要集成到不同生态系统的开发者,pydantic-resolve 的设计不仅支持 REST API,还能驱动 GraphQL 查询、MCP services 以及各类 Admin 工具,确保配置���一致性与扩展性。
API 设计遵循整洁架构原则。通过使用 `resolve_*` 方法,你可以将模型中缺失的字段(需要从数据库或外部服务获取的数据)定义为 Interface Adapter。这种方式允许你在不改变现有架构的前提下,通过在 Endpoint 上直接应用 resolve 逻辑,快速获得 N+1 查询保护,实现数据填充的自动化。
高质量的Python MCP工具,架构清晰
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
AI Skill Hub 点评:Pydantic Resolve 的核心功能完整,质量优秀。对于Claude Desktop / Claude Code 用户来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | pydantic-resolve |
| 原始描述 | 开源MCP工具:pydantic-resolve is a Pythonic clean architecture implementation。⭐326 · Python |
| Topics | bfffastapifullstackgraphqlmcppython |
| GitHub | https://github.com/KLR-Pattern/pydantic-resolve |
| License | MIT |
| 语言 | Python |
收录时间:2026-06-06 · 更新时间:2026-06-06 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端