Skip to content

feat(mcp): introduce self-contained Application class#103

Open
allmonday wants to merge 1 commit into
masterfrom
feat/009-app-self-contained
Open

feat(mcp): introduce self-contained Application class#103
allmonday wants to merge 1 commit into
masterfrom
feat/009-app-self-contained

Conversation

@allmonday

Copy link
Copy Markdown
Collaborator

Summary

引入 Application 类作为 nexusx mcp 中可独立导出、可合并的最小单元——封装 SQLModel base + 完整数据库连接信息(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 通过 FastMCP lifespan= 自动 dispose 所有 owned engines(FR-006/FR-007)
  • 6 个 call site 迁移到 Application 形式(3 demos + skill template + 2 测试文件)
  • 完整 spec-kit 产物:specs/009-app-self-contained/{spec,plan,tasks,research,data-model,quickstart}.md + contracts/

Test plan

  • uv run pytest tests/ —— 1189 passed, 6 skipped
  • uv run ruff check src/nexusx/mcp/ —— clean
  • uv run mypy src/nexusx/mcp/ —— 5 baseline errors(pre-existing,新代码无新增)
  • schema-only 模式:Application(name=, base=) 不需要连接信息即可访问 SDL / introspection
  • URL 凭据脱敏:postgresql://user:***@host/db 形式出现在 repr
  • dict 兼容路径触发 DeprecationWarning,消息含 "Application" 引导迁移
  • multi_app demo 用 Application(url=...) 形式构造 mcp server 成功
  • lifespan 退出时 await manager.dispose() 被调用且幂等
  • 人工测试 mcp client 端到端(list_apps / graphql_query(app_name=...))—— 详见 specs/009-app-self-contained/quickstart.md §2

Spec reference

完整规格说明与设计决策记录在 specs/009-app-self-contained/

Roadmap(本次范围外)

  • create_simple_mcp_server 也改造为 Application-based
  • UseCaseAppConfig / create_use_case_graphql_mcp_server 平行改造
  • entry-point 自动发现([project.entry-points."nexusx.apps"])让合并项目零代码注册

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant