mpc-mcp-server 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mpc_mcp_server-0.3.0/PKG-INFO +278 -0
- mpc_mcp_server-0.3.0/README.md +253 -0
- mpc_mcp_server-0.3.0/mpc_core/__init__.py +27 -0
- mpc_mcp_server-0.3.0/mpc_core/compiler.py +507 -0
- mpc_mcp_server-0.3.0/mpc_core/models.py +181 -0
- mpc_mcp_server-0.3.0/mpc_core/providers.py +335 -0
- mpc_mcp_server-0.3.0/mpc_core/router.py +243 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/PKG-INFO +278 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/SOURCES.txt +15 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/dependency_links.txt +1 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/entry_points.txt +2 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/requires.txt +21 -0
- mpc_mcp_server-0.3.0/mpc_mcp_server.egg-info/top_level.txt +2 -0
- mpc_mcp_server-0.3.0/mpc_server/__init__.py +0 -0
- mpc_mcp_server-0.3.0/mpc_server/server.py +566 -0
- mpc_mcp_server-0.3.0/pyproject.toml +68 -0
- mpc_mcp_server-0.3.0/setup.cfg +4 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mpc-mcp-server
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Metastable Propositional Calculus — thermodynamic framework for resource-bounded inference
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: fastmcp>=2.0.0
|
|
9
|
+
Requires-Dist: anthropic>=0.45.0
|
|
10
|
+
Requires-Dist: google-generativeai>=0.8.0
|
|
11
|
+
Requires-Dist: openai>=1.30.0
|
|
12
|
+
Requires-Dist: numpy>=1.26.0
|
|
13
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
14
|
+
Provides-Extra: qutip
|
|
15
|
+
Requires-Dist: qutip>=5.0.0; extra == "qutip"
|
|
16
|
+
Provides-Extra: netket
|
|
17
|
+
Requires-Dist: netket>=3.10.0; extra == "netket"
|
|
18
|
+
Provides-Extra: full
|
|
19
|
+
Requires-Dist: mpc[netket,qutip]; extra == "full"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
23
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
24
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
25
|
+
|
|
26
|
+
# MPC — Metastable Propositional Calculus
|
|
27
|
+
|
|
28
|
+
> **Metastable Propositional Calculus (MPC) engine.** Analyzes the thermodynamic and physical feasibility of logical assertions across multi-step reasoning. Unlike standard Boolean logic, MPC detects *epistemic drift* and structural conflicts (k-states) by calculating the energetic holding costs of maintaining premises over time. Use this to rigorously verify whether a complex sequence of claims can be logically maintained together without collapsing into contradiction.
|
|
29
|
+
|
|
30
|
+
Truth values: **c** (committed) · **s** (suspended) · **k** (conflict) · **r** (reset)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## What's new in v0.3
|
|
35
|
+
|
|
36
|
+
| Feature | Detail |
|
|
37
|
+
|---|---|
|
|
38
|
+
| **FastMCP** | Replaced low-level MCP server with FastMCP for cleaner tool definitions and better client compatibility |
|
|
39
|
+
| **Five-provider routing** | Anthropic · Google · OpenAI · Kimi (Moonshot AI) · Ollama — all first-class |
|
|
40
|
+
| **Dynamic model listing** | Real-time queries to each provider's list-models endpoint; 5-minute TTL cache |
|
|
41
|
+
| **Zero env-var conflicts** | Each provider has its own variable: `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`, `OPENAI_API_KEY`, `KIMI_API_KEY`, `OLLAMA_HOST` |
|
|
42
|
+
| **Provider tab in UI** | Side-by-side key configuration, per-provider status, model counts |
|
|
43
|
+
| **`list_available_models` tool** | New MCP tool for dynamic model discovery |
|
|
44
|
+
| **Retry logic** | Transient errors retried up to 3× with exponential back-off |
|
|
45
|
+
| **`/status` + `/env` endpoints** | Provider health and env-var audit without exposing key values |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Providers
|
|
50
|
+
|
|
51
|
+
| Provider | SDK | Key Env Var | Notes |
|
|
52
|
+
|---|---|---|---|
|
|
53
|
+
| **Anthropic** | `anthropic` | `ANTHROPIC_API_KEY` | Claude claude-opus-4-6, claude-sonnet-4-6, Haiku |
|
|
54
|
+
| **Google** | `google-generativeai` | `GOOGLE_API_KEY` | Gemini 2.5 Pro, 2.0 Flash, 1.5 |
|
|
55
|
+
| **OpenAI** | `openai` | `OPENAI_API_KEY` | GPT-4o, o1, o3-mini, etc. |
|
|
56
|
+
| **Kimi** | `openai` (OpenAI-compatible) | `KIMI_API_KEY` | Moonshot AI · moonshot.cn |
|
|
57
|
+
| **Ollama** | stdlib `urllib` | `OLLAMA_HOST` | Local models, no key needed |
|
|
58
|
+
|
|
59
|
+
API keys are resolved in order: **explicit argument → environment variable → .env file**. No provider ever reads another provider's key variable.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Install
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Core — all five providers included
|
|
67
|
+
pip install -e .
|
|
68
|
+
|
|
69
|
+
# Add QuTiP for exact partition function (Ising Hamiltonian)
|
|
70
|
+
pip install qutip
|
|
71
|
+
|
|
72
|
+
# Add NetKet for spin-glass ground-state solver (requires JAX)
|
|
73
|
+
pip install "jax[cpu]" netket
|
|
74
|
+
|
|
75
|
+
# Full stack
|
|
76
|
+
pip install -e ".[full]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Requires **Python ≥ 3.11**.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Quick start
|
|
84
|
+
|
|
85
|
+
### Set API keys
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Any combination — only set what you have
|
|
89
|
+
export ANTHROPIC_API_KEY=sk-ant-…
|
|
90
|
+
export GOOGLE_API_KEY=AIza…
|
|
91
|
+
export OPENAI_API_KEY=sk-…
|
|
92
|
+
export KIMI_API_KEY=sk-… # Moonshot AI key
|
|
93
|
+
export OLLAMA_HOST=http://localhost:11434 # default; omit if standard
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or use the **Providers** tab in the browser UI to enter and persist keys to `.env`.
|
|
97
|
+
|
|
98
|
+
### Start the server
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
mpc-server
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Starts:
|
|
105
|
+
- **MCP server** on stdio (register in Claude Desktop or any MCP client)
|
|
106
|
+
- **Browser UI** on `http://localhost:7771`
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Claude Desktop configuration
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"mcpServers": {
|
|
115
|
+
"mpc": {
|
|
116
|
+
"command": "mpc-server",
|
|
117
|
+
"env": {
|
|
118
|
+
"ANTHROPIC_API_KEY": "sk-ant-…",
|
|
119
|
+
"GOOGLE_API_KEY": "AIza…",
|
|
120
|
+
"OPENAI_API_KEY": "sk-…",
|
|
121
|
+
"KIMI_API_KEY": "sk-…"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## MCP Tools
|
|
131
|
+
|
|
132
|
+
| Tool | Description | API call? |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `compile_text` | Full MPC analysis: hypotheses, phases, frustration matrix, free energy (QuTiP), spin-glass ground state, Theorem 6.1 bound | ✓ |
|
|
135
|
+
| `compile_sequence` | Multi-step trace with Entity Ledger — tracks epistemic drift and η_i accumulation | ✓ |
|
|
136
|
+
| `read_claims` | Per-claim phase assignment (c/s/k/r) with rationale | ✓ |
|
|
137
|
+
| `budget_estimate` | Theorem 6.1 N_max = O(√(2E*/αε_min d_avg)) — pure arithmetic | ✗ |
|
|
138
|
+
| `list_available_models` | Real-time model catalogue across all five providers | ✗ (cached) |
|
|
139
|
+
|
|
140
|
+
All tools accept `provider_api_key` as an optional parameter; omitting it reads from environment variables automatically.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Python API
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
import mpc_core
|
|
148
|
+
|
|
149
|
+
# Full analysis — Anthropic (default)
|
|
150
|
+
result = mpc_core.compile("Your text here…", api_key="sk-ant-…")
|
|
151
|
+
|
|
152
|
+
# Google Gemini
|
|
153
|
+
result = mpc_core.compile("…", model="gemini-2.0-flash", api_key="AIza…")
|
|
154
|
+
|
|
155
|
+
# OpenAI
|
|
156
|
+
result = mpc_core.compile("…", model="gpt-4o", api_key="sk-…")
|
|
157
|
+
|
|
158
|
+
# Kimi (Moonshot AI)
|
|
159
|
+
result = mpc_core.compile("…", model="moonshot-v1-32k", api_key="sk-…")
|
|
160
|
+
|
|
161
|
+
# Local Ollama (no key needed)
|
|
162
|
+
result = mpc_core.compile("…", model="llama3:8b")
|
|
163
|
+
|
|
164
|
+
print(result.energy_model.free_energy) # F = -kT ln Z
|
|
165
|
+
print(result.ground_state.energy) # Ising ground-state energy
|
|
166
|
+
print(result.ground_state.stable_ids) # most compatible hypothesis subset
|
|
167
|
+
print(result.analytical_summary)
|
|
168
|
+
|
|
169
|
+
# Per-claim phase assignment
|
|
170
|
+
phases = mpc_core.read_claims(
|
|
171
|
+
["All ravens are black.", "Some ravens are albino."],
|
|
172
|
+
api_key="sk-ant-…",
|
|
173
|
+
model="claude-sonnet-4-6",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# Budget theorem (no API call)
|
|
177
|
+
est = mpc_core.budget_estimate(N=8, d_avg=2.5, epsilon_min=1.2)
|
|
178
|
+
print(est.interpretation)
|
|
179
|
+
|
|
180
|
+
# Multi-step trace with Entity Ledger
|
|
181
|
+
seq = mpc_core.compile_sequence(
|
|
182
|
+
["Step 1 text…", "Step 2 text…", "Step 3 text…"],
|
|
183
|
+
api_key="sk-ant-…",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
# Dynamic model listing
|
|
187
|
+
from mpc_core.providers import list_models, ProviderID
|
|
188
|
+
models = list_models(ProviderID.ANTHROPIC, "sk-ant-…")
|
|
189
|
+
|
|
190
|
+
# Free-energy surface (no API call)
|
|
191
|
+
from mpc_core.thermodynamics import free_energy_surface
|
|
192
|
+
surface = free_energy_surface(my_epsilon_matrix, T_range=(0.2,5), E_star_range=(2,40))
|
|
193
|
+
# surface["F"][T_index][E_star_index] → F value
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Browser UI — tabs
|
|
199
|
+
|
|
200
|
+
| Tab | Description |
|
|
201
|
+
|---|---|
|
|
202
|
+
| **Analyse text** | Full MPC analysis with hypothesis cards, thermodynamic strip (Z, F, S), ground-state box |
|
|
203
|
+
| **Read claims** | One claim per line → instant phase assignment |
|
|
204
|
+
| **3D Free Energy** | Interactive Plotly F(T, E*) surface with N_max Theorem 6.1 contour |
|
|
205
|
+
| **Energy landscape** | Animated 2-D canvas with budget/temperature sliders |
|
|
206
|
+
| **Compatibility matrix** | Pairwise ε_ij frustration table |
|
|
207
|
+
| **Budget calculator** | Theorem 6.1 N_max — no API key needed |
|
|
208
|
+
| **Historical Heatmap** | η_i accumulation across a reasoning trace (Addendum V) |
|
|
209
|
+
| **Providers** | API key configuration, per-provider status and model counts |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## HTTP API (localhost:7771)
|
|
214
|
+
|
|
215
|
+
| Method | Path | Description |
|
|
216
|
+
|---|---|---|
|
|
217
|
+
| `GET` | `/` | Browser UI (index.html) |
|
|
218
|
+
| `GET` | `/models` | Model catalogue using env-var keys |
|
|
219
|
+
| `POST` | `/models` | Refresh catalogue with caller-supplied keys |
|
|
220
|
+
| `GET` | `/env` | Which env vars are set (values redacted) |
|
|
221
|
+
| `POST` | `/status` | Provider connectivity health check |
|
|
222
|
+
| `POST` | `/setenv` | Persist a key to `.env` |
|
|
223
|
+
| `POST` | `/` | MPC actions (`compile`, `compile_sequence`, `read_claims`, `budget_estimate`, `free_energy_surface`, `ground_state`) |
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Testing
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Arithmetic tests (no API key required)
|
|
231
|
+
pytest tests/ -v
|
|
232
|
+
|
|
233
|
+
# Live API tests — any provider combination
|
|
234
|
+
ANTHROPIC_API_KEY=sk-ant-… pytest tests/ -v
|
|
235
|
+
GOOGLE_API_KEY=AIza… pytest tests/ -v
|
|
236
|
+
OPENAI_API_KEY=sk-… pytest tests/ -v
|
|
237
|
+
KIMI_API_KEY=sk-… pytest tests/ -v
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Architecture
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
mpc_core/
|
|
246
|
+
providers.py NEW v0.3 — ProviderID enum, per-provider key resolution,
|
|
247
|
+
dynamic model listing with TTL cache, all_models_catalogue()
|
|
248
|
+
router.py REWRITTEN — five-backend dispatch, retry logic, auth-error fast-fail
|
|
249
|
+
compiler.py compile() · read_claims() · budget_estimate() · compile_sequence()
|
|
250
|
+
entity_ledger.py Cross-step entity registry (four-layer pipeline)
|
|
251
|
+
thermodynamics.py QuTiP partition function · NetKet spin-glass · free_energy_surface()
|
|
252
|
+
json_repair.py Best-effort repair of truncated LLM JSON
|
|
253
|
+
models.py MPCResult dataclass hierarchy
|
|
254
|
+
|
|
255
|
+
mpc_server/
|
|
256
|
+
server.py REWRITTEN — FastMCP application + HTTP UI proxy (port 7771)
|
|
257
|
+
New endpoints: GET /env, POST /status, POST /models
|
|
258
|
+
|
|
259
|
+
static/
|
|
260
|
+
index.html REWRITTEN — provider selector tabs, per-provider key inputs,
|
|
261
|
+
dynamic model dropdowns, /status integration
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Roadmap
|
|
267
|
+
|
|
268
|
+
- **v0.1** ✓ Core compiler, MCP server, reference UI
|
|
269
|
+
- **v0.2** ✓ Multi-backend routing · QuTiP · NetKet · 3D Plotly · Historical heatmap
|
|
270
|
+
- **v0.3** ✓ FastMCP · Five providers · Dynamic model listing · Provider UI · Retry logic
|
|
271
|
+
- **v0.4** Spectral Laplacian extension of Theorem 6.1, community-aware N_max bounds
|
|
272
|
+
- **v0.5** Streaming analysis; differential η_i display per hypothesis per step
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# MPC — Metastable Propositional Calculus
|
|
2
|
+
|
|
3
|
+
> **Metastable Propositional Calculus (MPC) engine.** Analyzes the thermodynamic and physical feasibility of logical assertions across multi-step reasoning. Unlike standard Boolean logic, MPC detects *epistemic drift* and structural conflicts (k-states) by calculating the energetic holding costs of maintaining premises over time. Use this to rigorously verify whether a complex sequence of claims can be logically maintained together without collapsing into contradiction.
|
|
4
|
+
|
|
5
|
+
Truth values: **c** (committed) · **s** (suspended) · **k** (conflict) · **r** (reset)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What's new in v0.3
|
|
10
|
+
|
|
11
|
+
| Feature | Detail |
|
|
12
|
+
|---|---|
|
|
13
|
+
| **FastMCP** | Replaced low-level MCP server with FastMCP for cleaner tool definitions and better client compatibility |
|
|
14
|
+
| **Five-provider routing** | Anthropic · Google · OpenAI · Kimi (Moonshot AI) · Ollama — all first-class |
|
|
15
|
+
| **Dynamic model listing** | Real-time queries to each provider's list-models endpoint; 5-minute TTL cache |
|
|
16
|
+
| **Zero env-var conflicts** | Each provider has its own variable: `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`, `OPENAI_API_KEY`, `KIMI_API_KEY`, `OLLAMA_HOST` |
|
|
17
|
+
| **Provider tab in UI** | Side-by-side key configuration, per-provider status, model counts |
|
|
18
|
+
| **`list_available_models` tool** | New MCP tool for dynamic model discovery |
|
|
19
|
+
| **Retry logic** | Transient errors retried up to 3× with exponential back-off |
|
|
20
|
+
| **`/status` + `/env` endpoints** | Provider health and env-var audit without exposing key values |
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Providers
|
|
25
|
+
|
|
26
|
+
| Provider | SDK | Key Env Var | Notes |
|
|
27
|
+
|---|---|---|---|
|
|
28
|
+
| **Anthropic** | `anthropic` | `ANTHROPIC_API_KEY` | Claude claude-opus-4-6, claude-sonnet-4-6, Haiku |
|
|
29
|
+
| **Google** | `google-generativeai` | `GOOGLE_API_KEY` | Gemini 2.5 Pro, 2.0 Flash, 1.5 |
|
|
30
|
+
| **OpenAI** | `openai` | `OPENAI_API_KEY` | GPT-4o, o1, o3-mini, etc. |
|
|
31
|
+
| **Kimi** | `openai` (OpenAI-compatible) | `KIMI_API_KEY` | Moonshot AI · moonshot.cn |
|
|
32
|
+
| **Ollama** | stdlib `urllib` | `OLLAMA_HOST` | Local models, no key needed |
|
|
33
|
+
|
|
34
|
+
API keys are resolved in order: **explicit argument → environment variable → .env file**. No provider ever reads another provider's key variable.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Core — all five providers included
|
|
42
|
+
pip install -e .
|
|
43
|
+
|
|
44
|
+
# Add QuTiP for exact partition function (Ising Hamiltonian)
|
|
45
|
+
pip install qutip
|
|
46
|
+
|
|
47
|
+
# Add NetKet for spin-glass ground-state solver (requires JAX)
|
|
48
|
+
pip install "jax[cpu]" netket
|
|
49
|
+
|
|
50
|
+
# Full stack
|
|
51
|
+
pip install -e ".[full]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requires **Python ≥ 3.11**.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
### Set API keys
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Any combination — only set what you have
|
|
64
|
+
export ANTHROPIC_API_KEY=sk-ant-…
|
|
65
|
+
export GOOGLE_API_KEY=AIza…
|
|
66
|
+
export OPENAI_API_KEY=sk-…
|
|
67
|
+
export KIMI_API_KEY=sk-… # Moonshot AI key
|
|
68
|
+
export OLLAMA_HOST=http://localhost:11434 # default; omit if standard
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Or use the **Providers** tab in the browser UI to enter and persist keys to `.env`.
|
|
72
|
+
|
|
73
|
+
### Start the server
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
mpc-server
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Starts:
|
|
80
|
+
- **MCP server** on stdio (register in Claude Desktop or any MCP client)
|
|
81
|
+
- **Browser UI** on `http://localhost:7771`
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Claude Desktop configuration
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcpServers": {
|
|
90
|
+
"mpc": {
|
|
91
|
+
"command": "mpc-server",
|
|
92
|
+
"env": {
|
|
93
|
+
"ANTHROPIC_API_KEY": "sk-ant-…",
|
|
94
|
+
"GOOGLE_API_KEY": "AIza…",
|
|
95
|
+
"OPENAI_API_KEY": "sk-…",
|
|
96
|
+
"KIMI_API_KEY": "sk-…"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## MCP Tools
|
|
106
|
+
|
|
107
|
+
| Tool | Description | API call? |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `compile_text` | Full MPC analysis: hypotheses, phases, frustration matrix, free energy (QuTiP), spin-glass ground state, Theorem 6.1 bound | ✓ |
|
|
110
|
+
| `compile_sequence` | Multi-step trace with Entity Ledger — tracks epistemic drift and η_i accumulation | ✓ |
|
|
111
|
+
| `read_claims` | Per-claim phase assignment (c/s/k/r) with rationale | ✓ |
|
|
112
|
+
| `budget_estimate` | Theorem 6.1 N_max = O(√(2E*/αε_min d_avg)) — pure arithmetic | ✗ |
|
|
113
|
+
| `list_available_models` | Real-time model catalogue across all five providers | ✗ (cached) |
|
|
114
|
+
|
|
115
|
+
All tools accept `provider_api_key` as an optional parameter; omitting it reads from environment variables automatically.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Python API
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import mpc_core
|
|
123
|
+
|
|
124
|
+
# Full analysis — Anthropic (default)
|
|
125
|
+
result = mpc_core.compile("Your text here…", api_key="sk-ant-…")
|
|
126
|
+
|
|
127
|
+
# Google Gemini
|
|
128
|
+
result = mpc_core.compile("…", model="gemini-2.0-flash", api_key="AIza…")
|
|
129
|
+
|
|
130
|
+
# OpenAI
|
|
131
|
+
result = mpc_core.compile("…", model="gpt-4o", api_key="sk-…")
|
|
132
|
+
|
|
133
|
+
# Kimi (Moonshot AI)
|
|
134
|
+
result = mpc_core.compile("…", model="moonshot-v1-32k", api_key="sk-…")
|
|
135
|
+
|
|
136
|
+
# Local Ollama (no key needed)
|
|
137
|
+
result = mpc_core.compile("…", model="llama3:8b")
|
|
138
|
+
|
|
139
|
+
print(result.energy_model.free_energy) # F = -kT ln Z
|
|
140
|
+
print(result.ground_state.energy) # Ising ground-state energy
|
|
141
|
+
print(result.ground_state.stable_ids) # most compatible hypothesis subset
|
|
142
|
+
print(result.analytical_summary)
|
|
143
|
+
|
|
144
|
+
# Per-claim phase assignment
|
|
145
|
+
phases = mpc_core.read_claims(
|
|
146
|
+
["All ravens are black.", "Some ravens are albino."],
|
|
147
|
+
api_key="sk-ant-…",
|
|
148
|
+
model="claude-sonnet-4-6",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Budget theorem (no API call)
|
|
152
|
+
est = mpc_core.budget_estimate(N=8, d_avg=2.5, epsilon_min=1.2)
|
|
153
|
+
print(est.interpretation)
|
|
154
|
+
|
|
155
|
+
# Multi-step trace with Entity Ledger
|
|
156
|
+
seq = mpc_core.compile_sequence(
|
|
157
|
+
["Step 1 text…", "Step 2 text…", "Step 3 text…"],
|
|
158
|
+
api_key="sk-ant-…",
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# Dynamic model listing
|
|
162
|
+
from mpc_core.providers import list_models, ProviderID
|
|
163
|
+
models = list_models(ProviderID.ANTHROPIC, "sk-ant-…")
|
|
164
|
+
|
|
165
|
+
# Free-energy surface (no API call)
|
|
166
|
+
from mpc_core.thermodynamics import free_energy_surface
|
|
167
|
+
surface = free_energy_surface(my_epsilon_matrix, T_range=(0.2,5), E_star_range=(2,40))
|
|
168
|
+
# surface["F"][T_index][E_star_index] → F value
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Browser UI — tabs
|
|
174
|
+
|
|
175
|
+
| Tab | Description |
|
|
176
|
+
|---|---|
|
|
177
|
+
| **Analyse text** | Full MPC analysis with hypothesis cards, thermodynamic strip (Z, F, S), ground-state box |
|
|
178
|
+
| **Read claims** | One claim per line → instant phase assignment |
|
|
179
|
+
| **3D Free Energy** | Interactive Plotly F(T, E*) surface with N_max Theorem 6.1 contour |
|
|
180
|
+
| **Energy landscape** | Animated 2-D canvas with budget/temperature sliders |
|
|
181
|
+
| **Compatibility matrix** | Pairwise ε_ij frustration table |
|
|
182
|
+
| **Budget calculator** | Theorem 6.1 N_max — no API key needed |
|
|
183
|
+
| **Historical Heatmap** | η_i accumulation across a reasoning trace (Addendum V) |
|
|
184
|
+
| **Providers** | API key configuration, per-provider status and model counts |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## HTTP API (localhost:7771)
|
|
189
|
+
|
|
190
|
+
| Method | Path | Description |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `GET` | `/` | Browser UI (index.html) |
|
|
193
|
+
| `GET` | `/models` | Model catalogue using env-var keys |
|
|
194
|
+
| `POST` | `/models` | Refresh catalogue with caller-supplied keys |
|
|
195
|
+
| `GET` | `/env` | Which env vars are set (values redacted) |
|
|
196
|
+
| `POST` | `/status` | Provider connectivity health check |
|
|
197
|
+
| `POST` | `/setenv` | Persist a key to `.env` |
|
|
198
|
+
| `POST` | `/` | MPC actions (`compile`, `compile_sequence`, `read_claims`, `budget_estimate`, `free_energy_surface`, `ground_state`) |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Testing
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Arithmetic tests (no API key required)
|
|
206
|
+
pytest tests/ -v
|
|
207
|
+
|
|
208
|
+
# Live API tests — any provider combination
|
|
209
|
+
ANTHROPIC_API_KEY=sk-ant-… pytest tests/ -v
|
|
210
|
+
GOOGLE_API_KEY=AIza… pytest tests/ -v
|
|
211
|
+
OPENAI_API_KEY=sk-… pytest tests/ -v
|
|
212
|
+
KIMI_API_KEY=sk-… pytest tests/ -v
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Architecture
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
mpc_core/
|
|
221
|
+
providers.py NEW v0.3 — ProviderID enum, per-provider key resolution,
|
|
222
|
+
dynamic model listing with TTL cache, all_models_catalogue()
|
|
223
|
+
router.py REWRITTEN — five-backend dispatch, retry logic, auth-error fast-fail
|
|
224
|
+
compiler.py compile() · read_claims() · budget_estimate() · compile_sequence()
|
|
225
|
+
entity_ledger.py Cross-step entity registry (four-layer pipeline)
|
|
226
|
+
thermodynamics.py QuTiP partition function · NetKet spin-glass · free_energy_surface()
|
|
227
|
+
json_repair.py Best-effort repair of truncated LLM JSON
|
|
228
|
+
models.py MPCResult dataclass hierarchy
|
|
229
|
+
|
|
230
|
+
mpc_server/
|
|
231
|
+
server.py REWRITTEN — FastMCP application + HTTP UI proxy (port 7771)
|
|
232
|
+
New endpoints: GET /env, POST /status, POST /models
|
|
233
|
+
|
|
234
|
+
static/
|
|
235
|
+
index.html REWRITTEN — provider selector tabs, per-provider key inputs,
|
|
236
|
+
dynamic model dropdowns, /status integration
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Roadmap
|
|
242
|
+
|
|
243
|
+
- **v0.1** ✓ Core compiler, MCP server, reference UI
|
|
244
|
+
- **v0.2** ✓ Multi-backend routing · QuTiP · NetKet · 3D Plotly · Historical heatmap
|
|
245
|
+
- **v0.3** ✓ FastMCP · Five providers · Dynamic model listing · Provider UI · Retry logic
|
|
246
|
+
- **v0.4** Spectral Laplacian extension of Theorem 6.1, community-aware N_max bounds
|
|
247
|
+
- **v0.5** Streaming analysis; differential η_i display per hypothesis per step
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
MIT
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mpc_core — Metastable Propositional Calculus core library.
|
|
3
|
+
|
|
4
|
+
Public API
|
|
5
|
+
----------
|
|
6
|
+
compile(text, api_key, *, model, …) → MPCResult
|
|
7
|
+
read_claims(claims, api_key, …) → list[dict]
|
|
8
|
+
budget_estimate(N, d_avg, …) → BudgetEstimate
|
|
9
|
+
compile_sequence(texts, api_key, …) → SequenceResult
|
|
10
|
+
"""
|
|
11
|
+
from .compiler import compile, read_claims, budget_estimate, compile_sequence # noqa: F401
|
|
12
|
+
from .entity_ledger import EntityLedger # noqa: F401
|
|
13
|
+
from .models import MPCResult # noqa: F401
|
|
14
|
+
from .providers import ( # noqa: F401
|
|
15
|
+
DEFAULT_MODEL,
|
|
16
|
+
ProviderID,
|
|
17
|
+
all_models_catalogue,
|
|
18
|
+
list_models,
|
|
19
|
+
provider_for_model,
|
|
20
|
+
resolve_api_key,
|
|
21
|
+
)
|
|
22
|
+
from .router import call_model # noqa: F401
|
|
23
|
+
from .thermodynamics import ( # noqa: F401
|
|
24
|
+
compute_thermodynamic_quantities,
|
|
25
|
+
find_ground_state,
|
|
26
|
+
free_energy_surface,
|
|
27
|
+
)
|