feat(mcp): introduce self-contained Application class#103
Open
allmonday wants to merge 1 commit into
Open
Conversation
Application 封装 SQLModel base + 完整数据库连接信息(url/engine/session_factory
三选一),让 nexusx mcp app 成为可独立导出、可合并的最小单元——子项目
`pip install` 后 import 即可工作,合并项目无需再注入连接资源。
主要变更:
- 新增 src/nexusx/mcp/application.py: Application 类(同步构造、幂等 dispose、
URL 凭据脱敏)+ _coerce_to_application() 兼容 dict 输入
- MultiAppManager 接受 list[Application | AppConfig];dict 路径发 DeprecationWarning
- create_mcp_server 通过 FastMCP lifespan= 自动 dispose 所有 owned engines
- 6 个 call site 迁移到 Application(3 demos + skill template + 2 测试文件)
- 新增 3 个测试文件:test_application.py / test_multi_app_lifespan.py / test_dict_compat.py
- 文档:docs/api/api_mcp.{md,zh.md} + docs/advanced/mcp_service.{md,zh.md}
1189 tests passed; ruff clean; mypy 5 baseline errors (unchanged).
Spec: specs/009-app-self-contained/
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
引入
Application类作为 nexusx mcp 中可独立导出、可合并的最小单元——封装 SQLModelbase+ 完整数据库连接信息(url/engine/session_factory三选一)。子项目pip install后 import 即可工作,合并项目无需再为每个 app 注入连接资源。src/nexusx/mcp/application.py——Application类(同步构造、幂等 dispose、URL 凭据脱敏 FR-013)+_coerce_to_application()兼容 dict 输入MultiAppManager接受list[Application | AppConfig];dict 路径发DeprecationWarning(FR-009)create_mcp_server通过 FastMCPlifespan=自动 dispose 所有 owned engines(FR-006/FR-007)Application形式(3 demos + skill template + 2 测试文件)specs/009-app-self-contained/{spec,plan,tasks,research,data-model,quickstart}.md+contracts/Test plan
uv run pytest tests/—— 1189 passed, 6 skippeduv run ruff check src/nexusx/mcp/—— cleanuv run mypy src/nexusx/mcp/—— 5 baseline errors(pre-existing,新代码无新增)Application(name=, base=)不需要连接信息即可访问 SDL / introspectionpostgresql://user:***@host/db形式出现在 reprDeprecationWarning,消息含 "Application" 引导迁移Application(url=...)形式构造 mcp server 成功await manager.dispose()被调用且幂等list_apps/graphql_query(app_name=...))—— 详见specs/009-app-self-contained/quickstart.md§2Spec reference
完整规格说明与设计决策记录在
specs/009-app-self-contained/:Roadmap(本次范围外)
create_simple_mcp_server也改造为Application-basedUseCaseAppConfig/create_use_case_graphql_mcp_server平行改造[project.entry-points."nexusx.apps"])让合并项目零代码注册🤖 Generated with Claude Code