Skip to content

Neurosymbolic Forge - MCP server for creating new formulas through verified derivation. Combines LLM understanding with SymPy symbolic computation for pharmacokinetics, physics, and more.

License

Notifications You must be signed in to change notification settings

u9401066/nsforge-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ”₯ Neurosymbolic Forge (NSForge)

"Forge" = CREATE new formulas through verified derivation

License Python MCP

🌐 English | 繁體中文

πŸ”¨ Core Concept: The "Forge"

NSForge is NOT a formula database β€” it's a derivation factory that CREATES new formulas.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                             β”‚
β”‚   πŸ”¨ FORGE = Create new formulas through derivation                         β”‚
β”‚                                                                             β”‚
β”‚   Input: Base formulas          Output: NEW derived formulas                β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚   β”‚ β€’ One-compartment   β”‚       β”‚ Temperature-corrected elimination   β”‚    β”‚
β”‚   β”‚ β€’ Arrhenius         β”‚  ──→  β”‚ Body fat-adjusted distribution      β”‚    β”‚
β”‚   β”‚ β€’ Fick's law        β”‚       β”‚ Renal function dose adjustment      β”‚    β”‚
β”‚   β”‚ β€’ ...               β”‚       β”‚ Custom PK/PD models                 β”‚    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚         (from sympy-mcp)                    (stored in NSForge)            β”‚
β”‚                                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Four Core Capabilities

Capability Description Tools
DERIVE Create new formulas by composing base formulas substitute, simplify, differentiate, integrate
CONTROL Full step control: review, edit, rollback, insert get_step, update_step, rollback, delete_step, insert_note
VERIFY Ensure correctness through multiple methods check_dimensions, verify_derivative, symbolic_equal
STORE Save derived formulas with full provenance formulas/derivations/ repository

🌍 Ecosystem: Don't Reinvent the Wheel

NSForge works WITH other MCP servers, not against them:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MCP Scientific Computing Ecosystem                       β”‚
β”‚                         πŸ”’ 108 Tools Total πŸ”’                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  sympy-mcp (32 tools)                                                       β”‚
β”‚  └── Base formulas: F=ma, PV=nRT, Arrhenius...                             β”‚
β”‚  └── Physical constants: c, G, h, R... (SciPy CODATA)                      β”‚
β”‚  └── Symbolic computation engine (ODE, PDE, matrices)                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  nsforge-mcp (76 tools) ← YOU ARE HERE                                      β”‚
β”‚  └── πŸ”¨ Derivation framework: compose, verify, generate code               β”‚
β”‚  └── πŸ“ Derivation repository: store CREATED formulas with provenance      β”‚
β”‚  └── βœ… Verification layer: dimensional analysis, reverse verification     β”‚
β”‚  └── 🌐 Formula search: Wikidata, BioModels, SciPy constants               β”‚
β”‚  └── πŸ”— Optimization bridge: prepare formulas for USolver                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  medical-calc-mcp (75+ tools)                                               β”‚
β”‚  └── Clinical scores: APACHE, SOFA, GCS, MELD, qSOFA...                    β”‚
β”‚  └── Medical calculations: eGFR, IBW, BSA, MEWS...                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  usolver-mcp (Optional collaboration)                                       β”‚
β”‚  └── 🎯 Find optimal values for NSForge-derived formulas                   β”‚
β”‚  └── Solvers: Z3, OR-Tools, CVXPY, HiGHS                                   β”‚
β”‚  └── Use case: dose optimization, circuit parameter selection              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What NSForge stores:

βœ… BELONGS in NSForge ❌ Does NOT belong (use other tools)
Temperature-corrected drug elimination Basic physics formulas (sympy-mcp)
Body fat-adjusted volume of distribution Physical constants (sympy-mcp)
Renal function dose adjustments Clinical scores (medical-calc-mcp)
Custom composite PK/PD models Textbook formulas (references)

πŸš€ NSForge Unique Capabilities

NSForge provides features not available in SymPy-MCP by directly leveraging SymPy modules:

Feature SymPy Module Application Status
Statistics & Probability sympy.stats PopPK variability, uncertainty βœ… v0.2.1
Limits & Series sympy.limit, sympy.series Steady-state, accumulation βœ… v0.2.1
Inequality Solving sympy.solvers.inequalities Therapeutic window βœ… v0.2.1
Assumption Queries sympy.assumptions Auto-validation βœ… v0.2.1
Advanced Algebra sympy.expand/factor/apart... Expression manipulation βœ… v0.2.4
Integral Transforms sympy.laplace_transform/fourier_transform ODE solving, frequency analysis βœ… v0.2.4
Derivation Workflow NSForge exclusive Step tracking, provenance βœ… Available
Verification Suite NSForge exclusive Dimension analysis βœ… Available

πŸ“– Details: See NSForge vs SymPy-MCP Comparison for complete analysis.


🎬 Workflow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                            β”‚
β”‚   User Question                   NSForge Processing Pipeline              β”‚
β”‚   ═════════════                   ═══════════════════════════              β”‚
β”‚                                                                            β”‚
β”‚   "Drug concentration in         1️⃣ Query Formula Knowledge Base           β”‚
β”‚    a 38Β°C fever patient?"   ──→     β”œβ”€ One-compartment PK: C(t) = Cβ‚€Β·e^(-kβ‚‘t)
β”‚                                     └─ Arrhenius equation: k(T) = AΒ·e^(-Ea/RT)
β”‚                                                                            β”‚
β”‚                                  2️⃣ Compose Derivation                      β”‚
β”‚                                     β”œβ”€ Substitute k(T) into PK model       β”‚
β”‚                                     └─ Obtain temperature-corrected formulaβ”‚
β”‚                                                                            β”‚
β”‚                                  3️⃣ Symbolic Computation (SymPy)            β”‚
β”‚                                     └─ C(t,T) = Cβ‚€Β·exp(-kβ‚‘,refΒ·tΒ·exp(...)) β”‚
β”‚                                                                            β”‚
β”‚                                  4️⃣ Verify Results                          β”‚
β”‚                                     β”œβ”€ T=37Β°C reduces to standard model βœ“  β”‚
β”‚                                     └─ Dimensional analysis passed βœ“       β”‚
β”‚                                                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸŽ›οΈ Step-by-Step Control (NEW in v0.2.2)

NSForge now provides full CRUD control over derivation steps:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸŽ›οΈ STEP CONTROL - Navigate and Edit Your Derivation!                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                            β”‚
β”‚   Step 1 β†’ Step 2 β†’ Step 3 β†’ Step 4 β†’ Step 5 β†’ Step 6  (current)          β”‚
β”‚                        ↑                                                   β”‚
β”‚                        β”‚                                                   β”‚
β”‚   "Wait, step 3 looks wrong..."                                           β”‚
β”‚                                                                            β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚   β”‚  πŸ” READ    β”‚ derivation_get_step(3) β†’ View step details         β”‚    β”‚
β”‚   β”‚  ✏️ UPDATE  β”‚ derivation_update_step(3, notes="...") β†’ Fix notes β”‚    β”‚
β”‚   β”‚  βͺ ROLLBACKβ”‚ derivation_rollback(2) β†’ Return to step 2          β”‚    β”‚
β”‚   β”‚  πŸ“ INSERT  β”‚ derivation_insert_note(2, "...") β†’ Add explanation β”‚    β”‚
β”‚   β”‚  πŸ—‘οΈ DELETE  β”‚ derivation_delete_step(6) β†’ Remove last step       β”‚    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                                                                            β”‚
β”‚   After rollback: Step 1 β†’ Step 2  (now current)                          β”‚
β”‚   β†’ Continue derivation from step 2, try a different path!                β”‚
β”‚                                                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step CRUD Tools (5 new tools)

Tool Operation Description
derivation_get_step Read Get details of any step (expression, notes, assumptions)
derivation_update_step Update Modify metadata (notes, assumptions, limitations) - NOT expression
derivation_delete_step Delete Remove the LAST step only (safety constraint)
derivation_rollback Rollback ⚑ Jump back to any step, delete subsequent steps
derivation_insert_note Insert Add explanatory note at any position

πŸ’‘ Key Insight: Expressions can't be edited directly (that would break verification). Use rollback to return to a valid state, then re-derive with corrections.

Use Cases

  1. Peer Review: "Step 5's assumption is questionable" β†’ update_step(5, notes="Validated for T<42Β°C only")
  2. Wrong Path: "We should have used integration instead" β†’ rollback(3) β†’ start fresh
  3. Add Context: "Need to explain the Arrhenius substitution" β†’ insert_note(4, "Temperature effect on enzyme kinetics...")
  4. Clean Up: "Last step was a mistake" β†’ delete_step(8)

🧠 Why NSForge?

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                             β”‚
β”‚   Problem: LLMs doing math directly                                         β”‚
β”‚   ═════════════════════════════════                                         β”‚
β”‚                                                                             β”‚
β”‚   ❌ May calculate wrong        ❌ Different results      ❌ Unverifiable   β”‚
β”‚      (hallucinations)              each time                                β”‚
β”‚                                                                             β”‚
β”‚   ═══════════════════════════════════════════════════════════════════════   β”‚
β”‚                                                                             β”‚
β”‚   Solution: LLM + NSForge                                                   β”‚
β”‚   ═══════════════════════                                                   β”‚
β”‚                                                                             β”‚
β”‚   LLM handles:                      NSForge handles:                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚   β”‚ β€’ Understand query  β”‚          β”‚ β€’ Store verified    β”‚                 β”‚
β”‚   β”‚ β€’ Plan derivation   β”‚    ──→   β”‚   formulas          β”‚                 β”‚
β”‚   β”‚ β€’ Explain results   β”‚          β”‚ β€’ Precise symbolic  β”‚                 β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚   computation       β”‚                 β”‚
β”‚      "Understanding                β”‚ β€’ Track derivation  β”‚                 β”‚
β”‚       & Planning"                  β”‚   sources           β”‚                 β”‚
β”‚                                    β”‚ β€’ Verify results    β”‚                 β”‚
β”‚                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β”‚                                       "Computation                         β”‚
β”‚                                        & Verification"                     β”‚
β”‚                                                                             β”‚
β”‚   βœ… Guaranteed correct    βœ… Reproducible    βœ… Fully traceable            β”‚
β”‚                                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“š Derivation Repository Architecture

NSForge stores derived formulas with full provenance tracking:

formulas/
└── derivations/                    ← All derived formulas go here
    β”œβ”€β”€ README.md                   ← Documentation
    └── pharmacokinetics/           ← PK model derivations
        β”œβ”€β”€ temp_corrected_elimination.md   ← Temperature-corrected k
        └── fat_adjusted_vd.md              ← Obesity-adjusted Vd

Each derivation result contains:

  • LaTeX mathematical expression
  • SymPy computable form
  • Derived from: which base formulas were combined
  • Derivation steps: the actual derivation process
  • Verification status: dimensional analysis, limiting cases
  • Clinical context and usage guidance
  • YAML metadata for programmatic access

Example Derivations:

Derivation Domain Description
Temperature-Corrected Elimination PK First-order elimination + Arrhenius temperature dependence
NPO Antibiotic Effect PK/PD Henderson-Hasselbalch + Emax model for pH-dependent absorption
Temperature-Corrected Michaelis-Menten PK Non-linear saturable kinetics with temperature effects
Cisatracurium Multiple Dosing PK Hydrolytic drug accumulation with temperature correction
Physiological Vd Body Composition PK/PBPK PBPK-based Vd adjustment for body composition (logP > 2)

Example: NPO (Fasting) Impact on Antibiotic Efficacy

id: npo_antibiotic_effect
name: NPO Impact on Oral Antibiotic Efficacy
expression: E_0 + (E_max * C_eff^n) / (EC_50^n + C_eff^n)
  where: C_eff = F_base * D / (Vd * (1 + 10^(pH - pKa)))
derived_from:
  - henderson_hasselbalch       # pH-dependent ionization
  - emax_model                  # Pharmacodynamic effect
verified: true
verification_method: sympy_symbolic_substitution
clinical_context: |
  Predicts reduced antibiotic efficacy in NPO patients due to 
  increased gastric pH. Critical for weak acid antibiotics like 
  Amoxicillin (pKa=2.4) where NPO can reduce effect by >90%.

See also: Python Implementation with clinical recommendations.


✨ Features

Category Capabilities
πŸ”’ Symbolic Computation Calculus, Algebra, Linear Algebra, ODE/PDE
πŸ“– Formula Management Storage, Query, Version Control, Source Tracking
πŸ”„ Derivation Composition Multi-formula composition, Variable substitution, Condition modification
βœ… Result Verification Dimensional analysis, Boundary conditions, Reverse verification
🐍 Code Generation Generate Python functions from symbolic formulas

πŸ“¦ Installation

Requirements

  • Python 3.12+
  • uv (recommended package manager)
# Using uv (recommended)
uv add nsforge-mcp

# Or using pip
pip install nsforge-mcp

From Source

git clone https://github.com/u9401066/nsforge-mcp.git
cd nsforge-mcp

# Create environment and install dependencies
uv sync --all-extras

# Verify installation
uv run python -c "import nsforge; print(nsforge.__version__)"

πŸš€ Quick Start

As MCP Server

// Claude Desktop config (claude_desktop_config.json)
{
  "mcpServers": {
    "nsforge": {
      "command": "uvx",
      "args": ["nsforge-mcp"]
    }
  }
}

Usage Examples

Calculus computation:

User: Calculate ∫(x² + 3x)dx and verify the result

Agent calls NSForge:
β†’ Result: xΒ³/3 + 3xΒ²/2 + C
β†’ Verify: d/dx(xΒ³/3 + 3xΒ²/2) = xΒ² + 3x βœ“
β†’ Steps: Split integral β†’ Power rule β†’ Combine

Physics derivation:

User: Work done by ideal gas in isothermal expansion?

Agent calls NSForge:
β†’ W = nRT ln(Vβ‚‚/V₁)
β†’ Derivation: PV=nRT β†’ P=nRT/V β†’ W=∫PdV β†’ Integrate

Algorithm analysis:

User: Analyze T(n) = 2T(n/2) + n

Agent calls NSForge:
β†’ T(n) = Θ(n log n)
β†’ Method: Master Theorem Case 2
β†’ Example: Merge Sort

πŸ“– Documentation

Design Documents

Example Derivations

  • Power Amp Coupling Capacitor Design - Complete RC high-pass filter derivation
    • From ideal formulas to practical considerations (output impedance, ESR, speaker impedance curve)
    • Demonstrates NSForge "Principles + Modifications" framework in practice

API Reference

πŸ› οΈ MCP Tools

NSForge provides 75 MCP tools organized into 7 modules:

πŸ”₯ Derivation Engine (31 tools)

Tool Purpose
derivation_start Start a new derivation session
derivation_resume Resume a previous session
derivation_list_sessions List all sessions
derivation_status Get current session status
derivation_show πŸ†• Display current formula (like SymPy's print_latex_expression)
derivation_load_formula Load base formulas
derivation_substitute Variable substitution
derivation_simplify Simplify expression
derivation_solve_for Solve for variable
derivation_differentiate Differentiate expression
derivation_integrate Integrate expression
derivation_record_step Record step with notes (⚠️ MUST display formula to user after!)
derivation_add_note Add human insights
derivation_get_steps Get all derivation steps
derivation_get_step Get single step details
derivation_update_step Update step metadata
derivation_delete_step Delete last step
derivation_rollback ⚑ Rollback to any step
derivation_insert_note Insert note at position
derivation_complete Complete and save
derivation_abort Abort current session
derivation_list_saved List saved derivations
derivation_get_saved Get saved derivation
derivation_search_saved Search derivations
derivation_repository_stats Repository statistics
derivation_update_saved Update metadata
derivation_delete_saved Delete derivation
derivation_export_for_sympy πŸ†• Export state to SymPy-MCP
derivation_import_from_sympy πŸ†• Import result from SymPy-MCP
derivation_handoff_status πŸ†• Check handoff capabilities
derivation_prepare_for_optimization πŸ†• Prepare for USolver

βœ… Verification (6 tools)

Tool Purpose
verify_equality Verify two expressions are equal
verify_derivative Verify derivative by integration
verify_integral Verify integral by differentiation
verify_solution Verify equation solution
check_dimensions Dimensional analysis
reverse_verify Reverse operation verification

πŸ”’ Calculation (12 tools)

Tool Purpose
calculate_limit Calculate limits
calculate_series Taylor/Laurent series expansion
calculate_summation Symbolic summation Ξ£
solve_inequality Solve single inequality
solve_inequality_system Solve system of inequalities
define_distribution Define probability distribution
distribution_stats Get distribution statistics (mean, var, skew)
distribution_probability Calculate probability P(condition)
query_assumptions Query symbol assumptions
refine_expression Refine expression with assumptions
evaluate_numeric Numerical evaluation
symbolic_equal Symbolic equality check

πŸ“ Expression (3 tools)

Tool Purpose
parse_expression Parse mathematical expression
validate_expression Validate expression syntax
extract_symbols Extract symbols with metadata

πŸ’» Code Generation (4 tools)

Tool Purpose
generate_python_function Generate Python function
generate_latex_derivation Generate LaTeX document
generate_derivation_report Generate Markdown report
generate_sympy_script Generate standalone SymPy script

πŸ”’ Advanced Algebra (10 tools) - NEW in v0.2.4

Tool Purpose
expand_expression Expand products: (x+1)Β² β†’ xΒ²+2x+1
factor_expression Factorize: xΒ²-1 β†’ (x-1)(x+1)
collect_expression Collect terms by variable
trigsimp_expression Trig simplify: sinΒ²+cosΒ² β†’ 1
powsimp_expression Power simplify: xΒ²Β·xΒ³ β†’ x⁡
radsimp_expression Radical simplify
combsimp_expression Factorial simplify: n!/(n-2)! β†’ n(n-1)
apart_expression πŸ”₯ Partial fractions (for inverse Laplace)
cancel_expression Cancel common factors
together_expression Combine fractions

πŸ“Š Integral Transforms (4 tools) - NEW in v0.2.4

Tool Purpose
laplace_transform_expression πŸ”₯ f(t) β†’ F(s) for ODE solving
inverse_laplace_transform_expression πŸ”₯ F(s) β†’ f(t) multi-compartment PK
fourier_transform_expression f(x) β†’ F(k) frequency analysis
inverse_fourier_transform_expression F(k) β†’ f(x) signal reconstruction

🌐 Formula Search (6 tools) - NEW in v0.2.4

Tool Purpose
formula_search πŸ” Unified search (Wikidata, BioModels, SciPy)
formula_get πŸ“„ Get formula details by ID
formula_categories πŸ“‚ List available categories
formula_pk_models πŸ’Š PK models (1/2-compartment, Michaelis-Menten)
formula_kinetic_laws βš—οΈ Reaction kinetics (Hill, etc.)
formula_constants πŸ”¬ Physical constants (from SciPy)

🧠 Agent Skills Architecture

NSForge includes 19 pre-built Skills that teach AI agents how to use the tools effectively:

πŸ”₯ NSForge-Specific Skills (6)

Skill Trigger Words Description
nsforge-derivation-workflow derive, 推導, prove Complete derivation workflow with session management
nsforge-formula-management list, 公式庫, find formula Query, update, delete saved formulas
nsforge-formula-search Wikidata, BioModels, 物理常數 πŸ†• Search external formula sources
nsforge-verification-suite verify, check, ηΆ­εΊ¦ Equality, derivative, integral, dimension checks
nsforge-code-generation generate, export, LaTeX Python functions, reports, SymPy scripts
nsforge-quick-calculate calculate, simplify, solve Quick calculations without session

πŸ”§ General Development Skills (13)

Includes git-precommit, memory-updater, code-reviewer, test-generator, and more.

πŸ“– Details: See NSForge Skills Guide for complete documentation.

Golden Rule: SymPy-MCP First!

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Phase 1: SymPy-MCP executes computation                        β”‚
β”‚     intro_many([...]) β†’ introduce_expression(...) β†’             β”‚
β”‚     substitute/solve/dsolve... β†’ print_latex_expression(...)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Phase 2: NSForge records & stores                              β”‚
β”‚     derivation_record_step(...) β†’ derivation_add_note(...) β†’    β”‚
β”‚     derivation_complete(...)                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Division of Labor:

Task Tool Reason
Math computation SymPy-MCP Full ODE/PDE/matrix capabilities
Formula display print_latex_expression User confirmation at each step
Knowledge storage NSForge Provenance tracking, searchable
Dimension check NSForge check_dimensions Physical unit verification

πŸ—οΈ Project Structure

This project uses DDD (Domain-Driven Design) architecture with Core and MCP separation:

nsforge-mcp/
β”œβ”€β”€ .claude/skills/            # 🧠 Agent Skills (18 skills)
β”‚   β”œβ”€β”€ nsforge-derivation-workflow/  # Core workflow skill
β”‚   β”œβ”€β”€ nsforge-verification-suite/   # Verification skill
β”‚   └── ...                           # 16 more skills
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ nsforge/               # πŸ”· Core Domain (pure logic, no MCP dependency)
β”‚   β”‚   β”œβ”€β”€ domain/            # Domain Layer
β”‚   β”‚   β”‚   β”œβ”€β”€ entities.py    #   - Entities (Expression, Derivation)
β”‚   β”‚   β”‚   β”œβ”€β”€ value_objects.py #   - Value Objects (MathContext, Result)
β”‚   β”‚   β”‚   └── services.py    #   - Domain service interfaces
β”‚   β”‚   β”œβ”€β”€ application/       # Application Layer
β”‚   β”‚   β”‚   └── use_cases.py   #   - Use Cases (Calculate, Derive, Verify)
β”‚   β”‚   └── infrastructure/    # Infrastructure Layer
β”‚   β”‚       β”œβ”€β”€ sympy_engine.py #   - SymPy engine implementation
β”‚   β”‚       └── verifier.py    #   - Verifier implementation
β”‚   β”‚
β”‚   └── nsforge_mcp/           # πŸ”Ά MCP Layer (Presentation)
β”‚       β”œβ”€β”€ server.py          #   - FastMCP Server
β”‚       └── tools/             #   - MCP tool definitions (76 tools)
β”‚           β”œβ”€β”€ derivation.py  #     - πŸ”₯ Derivation engine (31 tools)
β”‚           β”œβ”€β”€ calculate.py   #     - πŸ”’ Calculation (12 tools)
β”‚           β”œβ”€β”€ simplify.py    #     - πŸ†• Advanced algebra (10+4 tools)
β”‚           β”œβ”€β”€ formula.py     #     - πŸ†• Formula search (6 tools)
β”‚           β”œβ”€β”€ verify.py      #     - Verification (6 tools)
β”‚           β”œβ”€β”€ expression.py  #     - Expression parsing (3 tools)
β”‚           └── codegen.py     #     - Code generation (4 tools)
β”‚
β”œβ”€β”€ formulas/                  # πŸ“ Formula Repository
β”‚   β”œβ”€β”€ derivations/           #   - Human-readable Markdown
β”‚   β”‚   └── pharmacokinetics/  #     - PK derivation examples
β”‚   └── derived/               #   - YAML metadata (auto-generated)
β”‚
β”œβ”€β”€ derivation_sessions/       # πŸ’Ύ Session persistence (JSON)
β”œβ”€β”€ docs/                      # πŸ“– Documentation
β”‚   └── nsforge-skills-guide.md #   - Skills usage guide (588 lines)
β”œβ”€β”€ examples/                  # 🐍 Python examples
β”‚   β”œβ”€β”€ npo_antibiotic_analysis.py  # Clinical application
β”‚   └── physiological_vd_model.py   # PBPK body composition model
β”œβ”€β”€ tests/                     # Tests
└── pyproject.toml             # Project config (uv/hatch)

Architecture Benefits

  • Core independently testable: No MCP dependency, can use nsforge package standalone
  • MCP replaceable: Can support other protocols (REST, gRPC) in the future
  • Dependency Inversion: Domain defines interfaces, Infrastructure implements

πŸ§ͺ Development

# Clone
git clone https://github.com/u9401066/nsforge-mcp.git
cd nsforge-mcp

# Create environment (uv will automatically use Python 3.12+)
uv sync --all-extras

# Run tests
uv run pytest

# Code checks
uv run ruff check src/
uv run mypy src/

# Start dev server
uv run nsforge-mcp

πŸ”— Collaboration with USolver (Optional)

NSForge can work with USolver to provide domain-expert formula derivation + mathematical optimization:

Workflow: NSForge β†’ USolver

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Problem: Find optimal Fentanyl dose for 65yo patient with 30% BF,    β”‚
β”‚           concurrent midazolam, targeting 2.5 ng/mL at t=5min          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Step 1: NSForge derives modified formula                              β”‚
β”‚  β”œβ”€ Consider: CYP3A4 competition (-30% CL)                             β”‚
β”‚  β”œβ”€ Consider: Body fat 30% (+25% Vd)                                   β”‚
β”‚  β”œβ”€ Consider: Age 65 (-15% CL)                                         β”‚
β”‚  └─ Output: C(t, dose) = dose/15.875 Γ— exp(-0.476Γ—t/15.875)           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Step 2: Prepare for optimization                                      β”‚
β”‚  └─ derivation_prepare_for_optimization()                              β”‚
β”‚     β†’ Variables: [dose], Parameters: {CL: 0.476, V1: 15.875}           β”‚
β”‚     β†’ Constraints: dose ∈ [0.01, 0.10], C(5) ∈ [2.0, 4.0]            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Step 3: USolver finds optimal value                                   β”‚
β”‚  └─ usolver.solve(objective="C(5, dose) = 2.5", constraints=[...])    β”‚
β”‚     β†’ optimal_dose = 0.0354 mg (35.4 mcg)                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why Combine?

Tool Strength Output
NSForge Domain knowledge (drug interactions, body composition) Modified formula
USolver Mathematical optimization (Z3, OR-Tools, CVXPY) Optimal parameters
Together Domain-smart + Math-precise Best clinical decision

Setup

  1. Install USolver: uv run https://github.com/sdiehl/usolver/install.py
  2. In NSForge, after completing derivation, call:
    result = derivation_prepare_for_optimization()
    # Copy result.usolver_template to USolver
  3. USolver returns optimal values
  4. Use optimal values in NSForge-derived formula for final calculation

πŸ“– Skill: .claude/skills/nsforge-usolver-collab/SKILL.md


πŸ“‹ Roadmap

  • Design documents
  • MVP Implementation
    • Derivation Engine (26 tools)
    • SymPy Integration
    • Verification Suite (6 tools)
    • MCP Server
  • Step Control System (v0.2.2)
    • Read/Update/Delete steps
    • Rollback to any point
    • Insert notes at any position
  • Agent Skills System
    • 6 NSForge-specific workflows
    • 13 general development skills
    • Skills documentation
  • Advanced Algebra & Transforms (v0.2.4)
    • 10 simplification tools (expand, factor, apart...)
    • 4 integral transforms (Laplace, Fourier)
    • SymPy coverage: 85% β†’ 92%
  • External Formula Search (v0.2.4)
    • Wikidata SPARQL adapter
    • BioModels adapter
    • SciPy constants
  • Pharmacokinetics Domain
    • Temperature-corrected elimination
    • NPO antibiotic effect model
    • Michaelis-Menten with temperature
    • Multiple dosing accumulation
  • Domain Expansion
    • Physics formula library
    • Audio circuits (in progress)
    • Algorithm analysis
  • Advanced Features
    • Lean4 formal verification
    • Automatic derivation planning

🀝 Contributing

Contributions welcome! Please see CONTRIBUTING.md.

πŸ“„ License

Apache License 2.0


NSForge β€” Forge new formulas through verified derivation | Where Neural Meets Symbolic

About

Neurosymbolic Forge - MCP server for creating new formulas through verified derivation. Combines LLM understanding with SymPy symbolic computation for pharmacokinetics, physics, and more.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages