mcp-cognitive-substrate 1.0.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.
- mcp_cognitive_substrate-1.0.0/LICENSE +21 -0
- mcp_cognitive_substrate-1.0.0/PKG-INFO +145 -0
- mcp_cognitive_substrate-1.0.0/README.md +129 -0
- mcp_cognitive_substrate-1.0.0/pyproject.toml +27 -0
- mcp_cognitive_substrate-1.0.0/setup.cfg +4 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate/__init__.py +66 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate/cli.py +146 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate/memory.py +423 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate/substrate.py +250 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate/tools.py +157 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/PKG-INFO +145 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/SOURCES.txt +15 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/dependency_links.txt +1 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/entry_points.txt +2 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/requires.txt +5 -0
- mcp_cognitive_substrate-1.0.0/src/mcp_cognitive_substrate.egg-info/top_level.txt +1 -0
- mcp_cognitive_substrate-1.0.0/src/tests/test_package.py +192 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JaysonAIOnline
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-cognitive-substrate
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 28-layer cognitive substrate + cross-session ToT evolutionary memory + A2A tools for MCP agents
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/JaysonAIOnline/mcp-cognitive-substrate
|
|
7
|
+
Project-URL: Documentation, https://github.com/JaysonAIOnline/mcp-cognitive-substrate#readme
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: mcp>=2.0.0
|
|
12
|
+
Requires-Dist: pydantic>=2.0.0
|
|
13
|
+
Provides-Extra: test
|
|
14
|
+
Requires-Dist: pytest>=8.0.0; extra == "test"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# mcp-cognitive-substrate
|
|
18
|
+
|
|
19
|
+
A **28-layer cognitive substrate** with cross-session **Tree-of-Thoughts (ToT) evolutionary memory**, conditional self-telemetry, and **A2A tools** for MCP agents.
|
|
20
|
+
|
|
21
|
+
Lets agents reason through a validated 28-layer substrate, evolve memory across sessions, and communicate with peer agents — all in one pip-installable package.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **28-layer cognitive substrate with Pydantic validation** — `CognitiveSubstrate` validates reasoning through 6 families / 28 layers.
|
|
26
|
+
- **Cross-session ToT evolutionary memory** — SQLite-backed tree-of-thoughts nodes + substrate history; pruned branches become lessons for future sessions.
|
|
27
|
+
- **Robust stack-based JSON parser** — no regex; handles nested brackets, escaped strings, embedded code fences (`robust_slice` / `robust_json_slice`).
|
|
28
|
+
- **Self-telemetry tool** — `get_cognitive_tree_state` returns active paths and pruned branches for a session.
|
|
29
|
+
- **Post-execution storage loop** — `store_5key_telemetry` auto-saves compact 5-key telemetry (foundations, metacognition, defensive, resource, utility).
|
|
30
|
+
- **7 reasoning paradigms** — deductive, inductive, abductive, analogical, causal, syllogistic, falsification.
|
|
31
|
+
- **A2A tools** — list, discover, call, and orchestrate peer agents.
|
|
32
|
+
- **MCP server** — exposes everything as tools via the `cognitive-substrate` CLI.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install mcp-cognitive-substrate
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or install from source:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/JaysonAIOnline/mcp-cognitive-substrate.git
|
|
44
|
+
cd mcp-cognitive-substrate
|
|
45
|
+
pip install -e .[test]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Requires Python **>= 3.11**.
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from mcp_cognitive_substrate.substrate import CognitiveSubstrate
|
|
54
|
+
from mcp_cognitive_substrate.memory import get_cognitive_tree_state, store_5key_telemetry
|
|
55
|
+
|
|
56
|
+
substrate = CognitiveSubstrate()
|
|
57
|
+
response = substrate.run("Your user prompt here")
|
|
58
|
+
print(response["layers_applied"], "layers applied")
|
|
59
|
+
print(response["substrate_verdict"])
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### 28-layer substrate
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from mcp_cognitive_substrate import substrate
|
|
68
|
+
|
|
69
|
+
# Layer count and schema
|
|
70
|
+
print(substrate.layer_count()) # 28
|
|
71
|
+
print(substrate.SUBSTRATE_SCHEMA) # the full 6-family schema
|
|
72
|
+
|
|
73
|
+
# Validate a prompt through the substrate
|
|
74
|
+
result = substrate.CognitiveSubstrate(session_id="s1").run("deploy safely")
|
|
75
|
+
print(result["substrate_verdict"]) # heuristic pruning verdict
|
|
76
|
+
|
|
77
|
+
# Run a single paradigm
|
|
78
|
+
from mcp_cognitive_substrate import run_paradigm
|
|
79
|
+
print(run_paradigm("14_idempotency_side_effect_audit", {"evaluate_branch": True}))
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Cross-session ToT evolutionary memory
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from mcp_cognitive_substrate.memory import (
|
|
86
|
+
store_5key_telemetry,
|
|
87
|
+
get_cognitive_tree_state,
|
|
88
|
+
prune_failed_approach,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
node_id = store_5key_telemetry(
|
|
92
|
+
session_id="session-a",
|
|
93
|
+
payload={
|
|
94
|
+
"foundations": {"premise_validation": "assuming deps", "state_hash": "h", "falsification_notes": "deps missing"},
|
|
95
|
+
"defensive": {"blast_radius": "unpredictable", "is_idempotent": True, "invariant_rule": "r"},
|
|
96
|
+
"resource": {"big_o": "o(n)", "latency_bottleneck": "none"},
|
|
97
|
+
"utility": {"load_summary": "pin versions to deploy", "checklist_verified": True},
|
|
98
|
+
"metacognition": {"self_critique": "c", "drift_pct": 0.1},
|
|
99
|
+
},
|
|
100
|
+
score_delta=-110.0,
|
|
101
|
+
)
|
|
102
|
+
prune_failed_approach(node_id)
|
|
103
|
+
state = get_cognitive_tree_state("session-a", include_pruned=True)
|
|
104
|
+
print(state["active_path_count"], state["pruned_branch_count"])
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Stack-based JSON parser
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from mcp_cognitive_substrate.memory import robust_slice, robust_json_slice
|
|
111
|
+
|
|
112
|
+
cleaned, payload = robust_slice('prefix {"a": {"b": [1, 2]}, "c": "x"} suffix')
|
|
113
|
+
# payload == {"a": {"b": [1, 2]}, "c": "x"}; cleaned == "prefix suffix"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 7 reasoning paradigms + A2A
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from mcp_cognitive_substrate import reason, a2a_list, a2a_call, a2a_orchestrate
|
|
120
|
+
|
|
121
|
+
print(reason("Solve X", reasoning_type="abductive", depth=3)["steps"])
|
|
122
|
+
print(a2a_list())
|
|
123
|
+
print(a2a_call("peer-agent", "hello"))
|
|
124
|
+
print(a2a_orchestrate("hi", capability="memory"))
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### As an MCP server
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cognitive-substrate # starts stdio MCP server
|
|
131
|
+
cognitive-substrate --info # prints package summary
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
All of the above — substrate paradigms, extraction/evaluation, memory store/recall, ToT lessons, tree-state telemetry, JSON parsing, reasoning plans, and A2A — are exposed as MCP tools.
|
|
135
|
+
|
|
136
|
+
## Testing
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install -e .[test]
|
|
140
|
+
python -m pytest src/tests -q # 16 tests
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# mcp-cognitive-substrate
|
|
2
|
+
|
|
3
|
+
A **28-layer cognitive substrate** with cross-session **Tree-of-Thoughts (ToT) evolutionary memory**, conditional self-telemetry, and **A2A tools** for MCP agents.
|
|
4
|
+
|
|
5
|
+
Lets agents reason through a validated 28-layer substrate, evolve memory across sessions, and communicate with peer agents — all in one pip-installable package.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **28-layer cognitive substrate with Pydantic validation** — `CognitiveSubstrate` validates reasoning through 6 families / 28 layers.
|
|
10
|
+
- **Cross-session ToT evolutionary memory** — SQLite-backed tree-of-thoughts nodes + substrate history; pruned branches become lessons for future sessions.
|
|
11
|
+
- **Robust stack-based JSON parser** — no regex; handles nested brackets, escaped strings, embedded code fences (`robust_slice` / `robust_json_slice`).
|
|
12
|
+
- **Self-telemetry tool** — `get_cognitive_tree_state` returns active paths and pruned branches for a session.
|
|
13
|
+
- **Post-execution storage loop** — `store_5key_telemetry` auto-saves compact 5-key telemetry (foundations, metacognition, defensive, resource, utility).
|
|
14
|
+
- **7 reasoning paradigms** — deductive, inductive, abductive, analogical, causal, syllogistic, falsification.
|
|
15
|
+
- **A2A tools** — list, discover, call, and orchestrate peer agents.
|
|
16
|
+
- **MCP server** — exposes everything as tools via the `cognitive-substrate` CLI.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install mcp-cognitive-substrate
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or install from source:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/JaysonAIOnline/mcp-cognitive-substrate.git
|
|
28
|
+
cd mcp-cognitive-substrate
|
|
29
|
+
pip install -e .[test]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Requires Python **>= 3.11**.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from mcp_cognitive_substrate.substrate import CognitiveSubstrate
|
|
38
|
+
from mcp_cognitive_substrate.memory import get_cognitive_tree_state, store_5key_telemetry
|
|
39
|
+
|
|
40
|
+
substrate = CognitiveSubstrate()
|
|
41
|
+
response = substrate.run("Your user prompt here")
|
|
42
|
+
print(response["layers_applied"], "layers applied")
|
|
43
|
+
print(response["substrate_verdict"])
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### 28-layer substrate
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from mcp_cognitive_substrate import substrate
|
|
52
|
+
|
|
53
|
+
# Layer count and schema
|
|
54
|
+
print(substrate.layer_count()) # 28
|
|
55
|
+
print(substrate.SUBSTRATE_SCHEMA) # the full 6-family schema
|
|
56
|
+
|
|
57
|
+
# Validate a prompt through the substrate
|
|
58
|
+
result = substrate.CognitiveSubstrate(session_id="s1").run("deploy safely")
|
|
59
|
+
print(result["substrate_verdict"]) # heuristic pruning verdict
|
|
60
|
+
|
|
61
|
+
# Run a single paradigm
|
|
62
|
+
from mcp_cognitive_substrate import run_paradigm
|
|
63
|
+
print(run_paradigm("14_idempotency_side_effect_audit", {"evaluate_branch": True}))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Cross-session ToT evolutionary memory
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from mcp_cognitive_substrate.memory import (
|
|
70
|
+
store_5key_telemetry,
|
|
71
|
+
get_cognitive_tree_state,
|
|
72
|
+
prune_failed_approach,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
node_id = store_5key_telemetry(
|
|
76
|
+
session_id="session-a",
|
|
77
|
+
payload={
|
|
78
|
+
"foundations": {"premise_validation": "assuming deps", "state_hash": "h", "falsification_notes": "deps missing"},
|
|
79
|
+
"defensive": {"blast_radius": "unpredictable", "is_idempotent": True, "invariant_rule": "r"},
|
|
80
|
+
"resource": {"big_o": "o(n)", "latency_bottleneck": "none"},
|
|
81
|
+
"utility": {"load_summary": "pin versions to deploy", "checklist_verified": True},
|
|
82
|
+
"metacognition": {"self_critique": "c", "drift_pct": 0.1},
|
|
83
|
+
},
|
|
84
|
+
score_delta=-110.0,
|
|
85
|
+
)
|
|
86
|
+
prune_failed_approach(node_id)
|
|
87
|
+
state = get_cognitive_tree_state("session-a", include_pruned=True)
|
|
88
|
+
print(state["active_path_count"], state["pruned_branch_count"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Stack-based JSON parser
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from mcp_cognitive_substrate.memory import robust_slice, robust_json_slice
|
|
95
|
+
|
|
96
|
+
cleaned, payload = robust_slice('prefix {"a": {"b": [1, 2]}, "c": "x"} suffix')
|
|
97
|
+
# payload == {"a": {"b": [1, 2]}, "c": "x"}; cleaned == "prefix suffix"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 7 reasoning paradigms + A2A
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from mcp_cognitive_substrate import reason, a2a_list, a2a_call, a2a_orchestrate
|
|
104
|
+
|
|
105
|
+
print(reason("Solve X", reasoning_type="abductive", depth=3)["steps"])
|
|
106
|
+
print(a2a_list())
|
|
107
|
+
print(a2a_call("peer-agent", "hello"))
|
|
108
|
+
print(a2a_orchestrate("hi", capability="memory"))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### As an MCP server
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
cognitive-substrate # starts stdio MCP server
|
|
115
|
+
cognitive-substrate --info # prints package summary
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
All of the above — substrate paradigms, extraction/evaluation, memory store/recall, ToT lessons, tree-state telemetry, JSON parsing, reasoning plans, and A2A — are exposed as MCP tools.
|
|
119
|
+
|
|
120
|
+
## Testing
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install -e .[test]
|
|
124
|
+
python -m pytest src/tests -q # 16 tests
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-cognitive-substrate"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "28-layer cognitive substrate + cross-session ToT evolutionary memory + A2A tools for MCP agents"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = {text = "MIT"}
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"mcp>=2.0.0",
|
|
10
|
+
"pydantic>=2.0.0",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project.optional-dependencies]
|
|
14
|
+
test = [
|
|
15
|
+
"pytest>=8.0.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
cognitive-substrate = "mcp_cognitive_substrate.cli:main"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/JaysonAIOnline/mcp-cognitive-substrate"
|
|
23
|
+
Documentation = "https://github.com/JaysonAIOnline/mcp-cognitive-substrate#readme"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
include = ["mcp_cognitive_substrate*"]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""mcp-cognitive-substrate.
|
|
2
|
+
|
|
3
|
+
28-layer cognitive substrate + cross-session ToT evolutionary memory
|
|
4
|
+
+ A2A tools for MCP agents.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "1.0.0"
|
|
8
|
+
|
|
9
|
+
from . import memory, substrate, tools
|
|
10
|
+
from .memory import (
|
|
11
|
+
ToTMemory,
|
|
12
|
+
ensure_schema,
|
|
13
|
+
get_cognitive_tree_state,
|
|
14
|
+
prune_failed_approach,
|
|
15
|
+
recall,
|
|
16
|
+
robust_json_slice,
|
|
17
|
+
robust_slice,
|
|
18
|
+
store,
|
|
19
|
+
store_5key_telemetry,
|
|
20
|
+
)
|
|
21
|
+
from .substrate import (
|
|
22
|
+
PARADIGMS,
|
|
23
|
+
SUBSTRATE_SCHEMA,
|
|
24
|
+
CognitiveSubstrate,
|
|
25
|
+
evaluate_substrate,
|
|
26
|
+
extract_substrate,
|
|
27
|
+
run_paradigm,
|
|
28
|
+
)
|
|
29
|
+
from .tools import (
|
|
30
|
+
A2ARegistry,
|
|
31
|
+
REASONING_PARADIGMS,
|
|
32
|
+
a2a_call,
|
|
33
|
+
a2a_discover,
|
|
34
|
+
a2a_list,
|
|
35
|
+
a2a_orchestrate,
|
|
36
|
+
reason,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"__version__",
|
|
41
|
+
"memory",
|
|
42
|
+
"substrate",
|
|
43
|
+
"tools",
|
|
44
|
+
"ToTMemory",
|
|
45
|
+
"ensure_schema",
|
|
46
|
+
"get_cognitive_tree_state",
|
|
47
|
+
"prune_failed_approach",
|
|
48
|
+
"recall",
|
|
49
|
+
"robust_json_slice",
|
|
50
|
+
"robust_slice",
|
|
51
|
+
"store",
|
|
52
|
+
"store_5key_telemetry",
|
|
53
|
+
"PARADIGMS",
|
|
54
|
+
"SUBSTRATE_SCHEMA",
|
|
55
|
+
"CognitiveSubstrate",
|
|
56
|
+
"evaluate_substrate",
|
|
57
|
+
"extract_substrate",
|
|
58
|
+
"run_paradigm",
|
|
59
|
+
"A2ARegistry",
|
|
60
|
+
"REASONING_PARADIGMS",
|
|
61
|
+
"a2a_call",
|
|
62
|
+
"a2a_discover",
|
|
63
|
+
"a2a_list",
|
|
64
|
+
"a2a_orchestrate",
|
|
65
|
+
"reason",
|
|
66
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""MCP server entrypoint for mcp-cognitive-substrate.
|
|
2
|
+
|
|
3
|
+
Run with::
|
|
4
|
+
|
|
5
|
+
cognitive-substrate
|
|
6
|
+
|
|
7
|
+
or ``python -m mcp_cognitive_substrate.cli``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import sys
|
|
14
|
+
from typing import Any, Dict, List
|
|
15
|
+
|
|
16
|
+
from . import __version__, memory, substrate, tools
|
|
17
|
+
|
|
18
|
+
try: # mcp is optional at import time; CLI requires it
|
|
19
|
+
from mcp.server.fastmcp import FastMCP
|
|
20
|
+
_MCP_AVAILABLE = True
|
|
21
|
+
except Exception: # pragma: no cover - only when mcp is missing
|
|
22
|
+
_MCP_AVAILABLE = False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _make_server() -> Any:
|
|
26
|
+
mcp = FastMCP("cognitive-substrate")
|
|
27
|
+
|
|
28
|
+
# -- substrate tools -----------------------------------------------------
|
|
29
|
+
@mcp.tool()
|
|
30
|
+
def substrate_paradigms() -> Dict[str, Any]:
|
|
31
|
+
"""Return the 28-layer cognitive substrate schema and layer count."""
|
|
32
|
+
return {
|
|
33
|
+
"layer_count": substrate.layer_count(),
|
|
34
|
+
"families": list(substrate.SUBSTRATE_SCHEMA.keys()),
|
|
35
|
+
"schema": substrate.SUBSTRATE_SCHEMA,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@mcp.tool()
|
|
39
|
+
def substrate_run_paradigm(paradigm_id: str, data: Dict[str, Any] = None) -> Dict[str, Any]:
|
|
40
|
+
"""Run a single 28-layer paradigm against provided data."""
|
|
41
|
+
return substrate.run_paradigm(paradigm_id, data or {})
|
|
42
|
+
|
|
43
|
+
@mcp.tool()
|
|
44
|
+
def substrate_extract(raw_text: str) -> Dict[str, Any]:
|
|
45
|
+
"""Extract the substrate JSON payload from raw text."""
|
|
46
|
+
substrate_dict, cleaned = substrate.extract_substrate(raw_text)
|
|
47
|
+
return {"substrate": substrate_dict, "cleaned": cleaned}
|
|
48
|
+
|
|
49
|
+
@mcp.tool()
|
|
50
|
+
def substrate_evaluate(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
51
|
+
"""Score a substrate instance. Returns (score_delta, is_pruned)."""
|
|
52
|
+
score_delta, is_pruned = substrate.evaluate_substrate(payload)
|
|
53
|
+
return {"score_delta": score_delta, "is_pruned": is_pruned, "accepted": is_pruned == 0}
|
|
54
|
+
|
|
55
|
+
# -- ToT memory tools -----------------------------------------------------
|
|
56
|
+
@mcp.tool()
|
|
57
|
+
def memory_store(content: str, topic: str = "general", tags: str = "", session_id: str = "default") -> Dict[str, Any]:
|
|
58
|
+
"""Store a memory for cross-session recall."""
|
|
59
|
+
mid = memory.store(content, topic=topic, tags=tags, session_id=session_id)
|
|
60
|
+
return {"id": mid}
|
|
61
|
+
|
|
62
|
+
@mcp.tool()
|
|
63
|
+
def memory_recall(query: str, k: int = 8, session_id: str = "") -> Dict[str, Any]:
|
|
64
|
+
"""Recall memories ranked by relevance."""
|
|
65
|
+
kw = {"k": k}
|
|
66
|
+
if session_id:
|
|
67
|
+
kw["session_id"] = session_id
|
|
68
|
+
return {"results": memory.recall(query, **kw)}
|
|
69
|
+
|
|
70
|
+
@mcp.tool()
|
|
71
|
+
def tot_historical_lessons(problem_context: str, max_lessons: int = 3) -> Dict[str, Any]:
|
|
72
|
+
"""Pull pruned/penalized branches from past sessions as lessons."""
|
|
73
|
+
lessons = memory._get_default().historical_lessons(problem_context, max_lessons)
|
|
74
|
+
return {"lessons": lessons}
|
|
75
|
+
|
|
76
|
+
@mcp.tool()
|
|
77
|
+
def memory_store_5key_telemetry(session_id: str, payload: Dict[str, Any], score_delta: float = 0.0) -> Dict[str, Any]:
|
|
78
|
+
"""Store 5-key compact substrate telemetry (post-execution storage loop)."""
|
|
79
|
+
node_id = memory.store_5key_telemetry(session_id, payload, score_delta)
|
|
80
|
+
return {"node_id": node_id}
|
|
81
|
+
|
|
82
|
+
@mcp.tool()
|
|
83
|
+
def memory_tree_state(session_id: str, include_pruned: bool = True) -> Dict[str, Any]:
|
|
84
|
+
"""Get persistent cognitive-tree telemetry for a session."""
|
|
85
|
+
return memory.get_cognitive_tree_state(session_id, include_pruned)
|
|
86
|
+
|
|
87
|
+
@mcp.tool()
|
|
88
|
+
def json_parse_stack(raw: str) -> Dict[str, Any]:
|
|
89
|
+
"""Parse the first top-level JSON object with the stack-based parser."""
|
|
90
|
+
cleaned, payload = memory.robust_slice(raw)
|
|
91
|
+
return {"cleaned": cleaned, "payload": payload}
|
|
92
|
+
|
|
93
|
+
# -- reasoning + A2A tools ------------------------------------------------
|
|
94
|
+
@mcp.tool()
|
|
95
|
+
def reasoning_paradigms() -> Dict[str, Any]:
|
|
96
|
+
"""Return the 7 reasoning paradigms."""
|
|
97
|
+
return tools.REASONING_PARADIGMS
|
|
98
|
+
|
|
99
|
+
@mcp.tool()
|
|
100
|
+
def reason_plan(problem: str, reasoning_type: str = "deductive", depth: int = 5) -> Dict[str, Any]:
|
|
101
|
+
"""Produce a structured reasoning plan for a problem."""
|
|
102
|
+
return tools.reason(problem, reasoning_type=reasoning_type, depth=depth)
|
|
103
|
+
|
|
104
|
+
@mcp.tool()
|
|
105
|
+
def a2a_list_agents() -> Dict[str, Any]:
|
|
106
|
+
"""List registered peer agents."""
|
|
107
|
+
return {"agents": tools.a2a_list()}
|
|
108
|
+
|
|
109
|
+
@mcp.tool()
|
|
110
|
+
def a2a_call_agent(name: str, message: str) -> Dict[str, Any]:
|
|
111
|
+
"""Call a peer agent by name."""
|
|
112
|
+
return tools.a2a_call(name, message)
|
|
113
|
+
|
|
114
|
+
@mcp.tool()
|
|
115
|
+
def a2a_orchestrate(capability: str, message: str, mode: str = "parallel") -> Dict[str, Any]:
|
|
116
|
+
"""Fan out a message to agents with a given capability."""
|
|
117
|
+
return tools.a2a_orchestrate(message, capability=capability, mode=mode)
|
|
118
|
+
|
|
119
|
+
return mcp
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
123
|
+
parser = argparse.ArgumentParser(prog="cognitive-substrate")
|
|
124
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
125
|
+
parser.add_argument("--info", action="store_true", help="Print package summary and exit.")
|
|
126
|
+
args = parser.parse_args(argv)
|
|
127
|
+
|
|
128
|
+
if args.info:
|
|
129
|
+
print(f"mcp-cognitive-substrate v{__version__}")
|
|
130
|
+
print(f"28-layer substrate: {substrate.layer_count()} layers")
|
|
131
|
+
print(f"Reasoning paradigms: {list(tools.REASONING_PARADIGMS.keys())}")
|
|
132
|
+
print(f"Registered agents: {[a['name'] for a in tools.a2a_list()]}")
|
|
133
|
+
print("ToT memory db:", memory._DEFAULT_DB_PATH)
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
if not _MCP_AVAILABLE:
|
|
137
|
+
print("mcp is not installed. Run: pip install mcp", file=sys.stderr)
|
|
138
|
+
return 1
|
|
139
|
+
|
|
140
|
+
server = _make_server()
|
|
141
|
+
server.run(transport="stdio")
|
|
142
|
+
return 0
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
raise SystemExit(main())
|