NSForge MCP 架構文檔 (v0.2.4)
NSForge 是一個 Neurosymbolic AI 工具,透過 MCP (Model Context Protocol) 為 AI 代理提供精確的符號推理能力。
┌─────────────────────────────────────────────────────────────────┐
│ AI Agent (Claude, etc.) │
├─────────────────────────────────────────────────────────────────┤
│ MCP Protocol Layer │
│ ┌─────────────────────────────────────────────────────────────┐│
│ │ nsforge_mcp (76 Tools) ││
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌─────────────┐ ││
│ │ │Derivation │ │ Calculate │ │ Simplify │ │ Verify │ ││
│ │ │ 31 tools │ │ 12 tools │ │ 14 tools │ │ 6 tools │ ││
│ │ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ └──────┬──────┘ ││
│ │ │ │ │ │ ││
│ │ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌──────┴──────┐ ││
│ │ │ Formula │ │Expression │ │ Codegen │ │ Others │ ││
│ │ │ 6 tools │ │ 3 tools │ │ 4 tools │ │ │ ││
│ │ └───────────┘ └───────────┘ └───────────┘ └─────────────┘ ││
│ └─────────────────────────────────────────────────────────────┘│
├─────────────────────────────────────────────────────────────────┤
│ nsforge (Core Library) │
│ ┌───────────────┐ ┌─────────────────┐ ┌───────────────────┐ │
│ │ Domain │ │ Application │ │ Infrastructure │ │
│ │ Pure Logic │◄─│ Use Cases │──►│ Persistence │ │
│ └───────────────┘ └─────────────────┘ └───────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
純業務邏輯,無外部依賴。
| 模組 | 說明 |
|---|---|
entities/ |
Formula, DerivationStep, DerivationSession |
value_objects/ |
Expression, Assumption, Metadata |
services/ |
SymPyEngine, DerivationEngine |
repositories/ |
FormulaRepository (抽象介面) |
協調 Domain 與 Infrastructure。
| 模組 | 說明 |
|---|---|
use_cases/ |
推導、驗證、公式管理用例 |
dto/ |
資料傳輸物件 |
外部系統介面。
| 模組 | 說明 |
|---|---|
persistence/ |
YAML/JSON 檔案存儲 |
formula_repository_impl.py |
FormulaRepository 實作 |
MCP 協議介面,獨立於核心庫。
| 模組 | 說明 |
|---|---|
server.py |
MCP Server 入口 |
tools/ |
76 個 MCP 工具實作 |
| 類別 | 數量 | 說明 |
|---|---|---|
| Derivation | 31 | 推導會話管理、步驟操作 |
| Calculate | 12 | 極限、級數、求和、Laplace/Fourier 變換 |
| Simplify | 14 | 展開、因式分解、三角簡化等 |
| Verify | 6 | 等價驗證、維度檢查 |
| Formula | 6 | 公式庫 CRUD |
| Expression | 3 | 表達式解析、符號提取 |
| Codegen | 4 | Python/LaTeX 生成 |
User Request → MCP Tool → Use Case → Domain Service → SymPy Engine
│
▼
Infrastructure (YAML/JSON)
derivation_start()- 開始會話derivation_record_step()- 記錄每步derivation_substitute()/derivation_integrate()- 操作derivation_show()- 顯示當前狀態derivation_complete()- 存檔
nsforge-mcp/
├── src/
│ ├── nsforge/ # Core Library (DDD)
│ │ ├── domain/ # 純業務邏輯
│ │ ├── application/ # 用例協調
│ │ └── infrastructure/ # 持久化
│ └── nsforge_mcp/ # MCP Server
│ ├── server.py # 入口
│ └── tools/ # 76 工具
├── formulas/ # 公式庫
│ ├── derivations/ # 原始推導
│ └── derived/ # 推導結果
├── derivation_sessions/ # 會話存檔
├── templates/ # 公式模板
└── tests/ # 測試
- Python: 3.12+
- SymPy: 符號計算引擎
- MCP SDK: Model Context Protocol
- uv: 套件管理
- Ruff: Linting
- pytest: 測試框架
- README.md - 專案說明
- CONSTITUTION.md - 開發原則
- docs/nsforge-skills-guide.md - 技能指南