zongyuan-kernel-mcp 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.
- zongyuan_kernel_mcp-1.0.0/LICENSE +21 -0
- zongyuan_kernel_mcp-1.0.0/PKG-INFO +74 -0
- zongyuan_kernel_mcp-1.0.0/README.md +62 -0
- zongyuan_kernel_mcp-1.0.0/pyproject.toml +19 -0
- zongyuan_kernel_mcp-1.0.0/server.py +286 -0
- zongyuan_kernel_mcp-1.0.0/setup.cfg +4 -0
- zongyuan_kernel_mcp-1.0.0/zongyuan_kernel_mcp.egg-info/PKG-INFO +74 -0
- zongyuan_kernel_mcp-1.0.0/zongyuan_kernel_mcp.egg-info/SOURCES.txt +9 -0
- zongyuan_kernel_mcp-1.0.0/zongyuan_kernel_mcp.egg-info/dependency_links.txt +1 -0
- zongyuan_kernel_mcp-1.0.0/zongyuan_kernel_mcp.egg-info/entry_points.txt +2 -0
- zongyuan_kernel_mcp-1.0.0/zongyuan_kernel_mcp.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tanbopiao
|
|
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,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zongyuan-kernel-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server wrapping the ZONGYUAN-ROOT autonomous kernel REST API (10 tools, stdio, stdlib-only)
|
|
5
|
+
Author: tanbopiao
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: mcp,model-context-protocol,agent,kernel,a2a
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# zongyuan-kernel-mcp
|
|
14
|
+
|
|
15
|
+
把 [ZONGYUAN-ROOT](https://github.com/tanbopiao) 自治内核(V3.0,确权锚点 `Ω₀⊂⊙∞⊂Ω`,DID-BR-000002)的十大标准 REST 能力封装为 **MCP (Model Context Protocol) 服务器**,供任意 MCP Client(Claude Desktop、OpenCode、Cline 等)直接调用。
|
|
16
|
+
|
|
17
|
+
单文件、零第三方依赖、纯 Python 标准库(>= 3.8),stdio 传输。
|
|
18
|
+
|
|
19
|
+
## 上游
|
|
20
|
+
|
|
21
|
+
上游是 ZONGYUAN-ROOT Kernel API(P2A · Protocol-to-Agent Open Layer):
|
|
22
|
+
|
|
23
|
+
- 默认地址 `http://127.0.0.1:9311`,可用环境变量 `ZR_KERNEL_URL` 指向任意已部署实例
|
|
24
|
+
- 除 `kernel_info` 外均需 `X-API-Key` 认证,通过环境变量 `ZR_API_KEY` 提供
|
|
25
|
+
- 上游自带 120 req/min 限流;本封装不缓存、不改写上游语义
|
|
26
|
+
|
|
27
|
+
## 工具清单(与上游端点一一对应)
|
|
28
|
+
|
|
29
|
+
| 工具 | 方法与路径 | 说明 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `kernel_info` | GET /api/v1/info | 确权锚点、DID、版本、端点清单(免鉴权) |
|
|
32
|
+
| `kernel_mount` | POST /api/v1/kernel/mount | 挂载/初始化内核实例 |
|
|
33
|
+
| `kernel_self_check` | POST /api/v1/kernel/self-check | 触发六维自检 |
|
|
34
|
+
| `kernel_evolve` | POST /api/v1/kernel/evolve | 触发元闭环进化 |
|
|
35
|
+
| `kernel_status` | GET /api/v1/kernel/status | 十二维状态、算子数、记忆水位 |
|
|
36
|
+
| `memory_write` | POST /api/v1/memory/write | 写入记忆(L1/L2/L3) |
|
|
37
|
+
| `memory_read` | GET /api/v1/memory/read | 按 ID/标签/层级检索记忆 |
|
|
38
|
+
| `homology_check` | POST /api/v1/homology/check | 工件哈希同源共识校验 |
|
|
39
|
+
| `ontology_query` | GET /api/v1/ontology/query | 本体图谱实体与关系查询 |
|
|
40
|
+
| `neural_activate` | POST /api/v1/neural/activate | 激活神经节点并可传播 |
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/tanbopiao/zongyuan-kernel-mcp.git
|
|
46
|
+
cd zongyuan-kernel-mcp
|
|
47
|
+
ZR_KERNEL_URL=http://127.0.0.1:9311 ZR_API_KEY=<your-key> python3 server.py
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### MCP 客户端配置示例
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"zongyuan-kernel": {
|
|
56
|
+
"command": "python3",
|
|
57
|
+
"args": ["/path/to/zongyuan-kernel-mcp/server.py"],
|
|
58
|
+
"env": {
|
|
59
|
+
"ZR_KERNEL_URL": "http://127.0.0.1:9311",
|
|
60
|
+
"ZR_API_KEY": "<your-key>"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 已验证
|
|
68
|
+
|
|
69
|
+
- MCP stdio 协议:`initialize` / `tools/list` / `tools/call` 全链路通过
|
|
70
|
+
- 对真实内核实例实测:`kernel_info`、`kernel_status`、`ontology_query` 返回正常
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# zongyuan-kernel-mcp
|
|
2
|
+
|
|
3
|
+
把 [ZONGYUAN-ROOT](https://github.com/tanbopiao) 自治内核(V3.0,确权锚点 `Ω₀⊂⊙∞⊂Ω`,DID-BR-000002)的十大标准 REST 能力封装为 **MCP (Model Context Protocol) 服务器**,供任意 MCP Client(Claude Desktop、OpenCode、Cline 等)直接调用。
|
|
4
|
+
|
|
5
|
+
单文件、零第三方依赖、纯 Python 标准库(>= 3.8),stdio 传输。
|
|
6
|
+
|
|
7
|
+
## 上游
|
|
8
|
+
|
|
9
|
+
上游是 ZONGYUAN-ROOT Kernel API(P2A · Protocol-to-Agent Open Layer):
|
|
10
|
+
|
|
11
|
+
- 默认地址 `http://127.0.0.1:9311`,可用环境变量 `ZR_KERNEL_URL` 指向任意已部署实例
|
|
12
|
+
- 除 `kernel_info` 外均需 `X-API-Key` 认证,通过环境变量 `ZR_API_KEY` 提供
|
|
13
|
+
- 上游自带 120 req/min 限流;本封装不缓存、不改写上游语义
|
|
14
|
+
|
|
15
|
+
## 工具清单(与上游端点一一对应)
|
|
16
|
+
|
|
17
|
+
| 工具 | 方法与路径 | 说明 |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `kernel_info` | GET /api/v1/info | 确权锚点、DID、版本、端点清单(免鉴权) |
|
|
20
|
+
| `kernel_mount` | POST /api/v1/kernel/mount | 挂载/初始化内核实例 |
|
|
21
|
+
| `kernel_self_check` | POST /api/v1/kernel/self-check | 触发六维自检 |
|
|
22
|
+
| `kernel_evolve` | POST /api/v1/kernel/evolve | 触发元闭环进化 |
|
|
23
|
+
| `kernel_status` | GET /api/v1/kernel/status | 十二维状态、算子数、记忆水位 |
|
|
24
|
+
| `memory_write` | POST /api/v1/memory/write | 写入记忆(L1/L2/L3) |
|
|
25
|
+
| `memory_read` | GET /api/v1/memory/read | 按 ID/标签/层级检索记忆 |
|
|
26
|
+
| `homology_check` | POST /api/v1/homology/check | 工件哈希同源共识校验 |
|
|
27
|
+
| `ontology_query` | GET /api/v1/ontology/query | 本体图谱实体与关系查询 |
|
|
28
|
+
| `neural_activate` | POST /api/v1/neural/activate | 激活神经节点并可传播 |
|
|
29
|
+
|
|
30
|
+
## 快速开始
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/tanbopiao/zongyuan-kernel-mcp.git
|
|
34
|
+
cd zongyuan-kernel-mcp
|
|
35
|
+
ZR_KERNEL_URL=http://127.0.0.1:9311 ZR_API_KEY=<your-key> python3 server.py
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### MCP 客户端配置示例
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"zongyuan-kernel": {
|
|
44
|
+
"command": "python3",
|
|
45
|
+
"args": ["/path/to/zongyuan-kernel-mcp/server.py"],
|
|
46
|
+
"env": {
|
|
47
|
+
"ZR_KERNEL_URL": "http://127.0.0.1:9311",
|
|
48
|
+
"ZR_API_KEY": "<your-key>"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 已验证
|
|
56
|
+
|
|
57
|
+
- MCP stdio 协议:`initialize` / `tools/list` / `tools/call` 全链路通过
|
|
58
|
+
- 对真实内核实例实测:`kernel_info`、`kernel_status`、`ontology_query` 返回正常
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "zongyuan-kernel-mcp"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "MCP server wrapping the ZONGYUAN-ROOT autonomous kernel REST API (10 tools, stdio, stdlib-only)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.8"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
authors = [{ name = "tanbopiao" }]
|
|
9
|
+
keywords = ["mcp", "model-context-protocol", "agent", "kernel", "a2a"]
|
|
10
|
+
|
|
11
|
+
[project.scripts]
|
|
12
|
+
zongyuan-kernel-mcp = "server:main"
|
|
13
|
+
|
|
14
|
+
[build-system]
|
|
15
|
+
requires = ["setuptools>=61"]
|
|
16
|
+
build-backend = "setuptools.build_meta"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools]
|
|
19
|
+
py-modules = ["server"]
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
ZONGYUAN-ROOT Kernel MCP Server
|
|
5
|
+
================================
|
|
6
|
+
把元枢自治内核(ZONGYUAN-ROOT V3.0,确权锚点 Ω₀⊂⊙∞⊂Ω,DID-BR-000002)
|
|
7
|
+
的十大标准 REST 能力封装为 MCP (Model Context Protocol) 工具,供任意
|
|
8
|
+
MCP Client(Claude、OpenCode、Cline 等)直接调用。
|
|
9
|
+
|
|
10
|
+
上游服务:ZONGYUAN-ROOT Kernel API(P2A · Protocol-to-Agent Open Layer)
|
|
11
|
+
- 本地默认 http://127.0.0.1:9311
|
|
12
|
+
- 远程示例 http://<host>:9311
|
|
13
|
+
认证:除 info 外均需 X-API-Key(环境变量 ZR_API_KEY)。
|
|
14
|
+
|
|
15
|
+
环境变量:
|
|
16
|
+
ZR_KERNEL_URL 内核 API 地址(默认 http://127.0.0.1:9311)
|
|
17
|
+
ZR_API_KEY 内核 API 访问密钥(必填)
|
|
18
|
+
|
|
19
|
+
协议:MCP stdio(JSON-RPC 2.0),单文件零第三方依赖,Python >= 3.8。
|
|
20
|
+
"""
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
import urllib.request
|
|
25
|
+
import urllib.parse
|
|
26
|
+
import urllib.error
|
|
27
|
+
|
|
28
|
+
SERVER_NAME = "zongyuan-kernel-mcp"
|
|
29
|
+
SERVER_VERSION = "1.0.0"
|
|
30
|
+
PROTOCOL_VERSION = "2024-11-05"
|
|
31
|
+
|
|
32
|
+
BASE_URL = os.environ.get("ZR_KERNEL_URL", "http://127.0.0.1:9311").rstrip("/")
|
|
33
|
+
API_KEY = os.environ.get("ZR_API_KEY", "")
|
|
34
|
+
TIMEOUT = int(os.environ.get("ZR_TIMEOUT", "30"))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
# 上游 HTTP 调用
|
|
39
|
+
# ---------------------------------------------------------------------------
|
|
40
|
+
def call_api(method, path, payload=None, query=None):
|
|
41
|
+
url = BASE_URL + path
|
|
42
|
+
if query:
|
|
43
|
+
url += "?" + urllib.parse.urlencode(
|
|
44
|
+
{k: v for k, v in query.items() if v is not None})
|
|
45
|
+
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
|
46
|
+
req = urllib.request.Request(url, data=data, method=method)
|
|
47
|
+
req.add_header("Content-Type", "application/json")
|
|
48
|
+
req.add_header("User-Agent", SERVER_NAME + "/" + SERVER_VERSION)
|
|
49
|
+
if API_KEY:
|
|
50
|
+
req.add_header("X-API-Key", API_KEY)
|
|
51
|
+
try:
|
|
52
|
+
with urllib.request.urlopen(req, timeout=TIMEOUT) as resp:
|
|
53
|
+
return json.loads(resp.read().decode("utf-8", "ignore"))
|
|
54
|
+
except urllib.error.HTTPError as e:
|
|
55
|
+
body = e.read().decode("utf-8", "ignore")[:300]
|
|
56
|
+
return {"upstream_error": True, "status": e.code, "detail": body}
|
|
57
|
+
except Exception as e: # 网络层失败
|
|
58
|
+
return {"upstream_error": True, "status": None, "detail": str(e)[:300]}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# ---------------------------------------------------------------------------
|
|
62
|
+
# 工具定义(与上游十个端点一一对应)
|
|
63
|
+
# ---------------------------------------------------------------------------
|
|
64
|
+
TOOLS = [
|
|
65
|
+
{
|
|
66
|
+
"name": "kernel_info",
|
|
67
|
+
"description": "获取内核确权锚点、DID、版本与端点清单(免鉴权)。",
|
|
68
|
+
"inputSchema": {"type": "object", "properties": {}},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "kernel_mount",
|
|
72
|
+
"description": "挂载/初始化一个内核实例。",
|
|
73
|
+
"inputSchema": {
|
|
74
|
+
"type": "object",
|
|
75
|
+
"properties": {
|
|
76
|
+
"instance_id": {"type": "string", "description": "实例ID,缺省自动生成"},
|
|
77
|
+
"config": {"type": "object", "description": "实例配置,可空"},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "kernel_self_check",
|
|
83
|
+
"description": "触发内核六维自检(元公理一致性等)。",
|
|
84
|
+
"inputSchema": {"type": "object", "properties": {}},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "kernel_evolve",
|
|
88
|
+
"description": "触发内核元闭环进化一步。",
|
|
89
|
+
"inputSchema": {
|
|
90
|
+
"type": "object",
|
|
91
|
+
"properties": {
|
|
92
|
+
"problem_desc": {"type": "string", "description": "本轮进化要解决的问题描述"},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "kernel_status",
|
|
98
|
+
"description": "读取内核运行状态:十二维状态、算子数、记忆水位等。",
|
|
99
|
+
"inputSchema": {"type": "object", "properties": {}},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "memory_write",
|
|
103
|
+
"description": "向内核记忆写入一条记录(L1/L2/L3 分层)。",
|
|
104
|
+
"inputSchema": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"properties": {
|
|
107
|
+
"content": {"type": "string", "description": "记忆正文"},
|
|
108
|
+
"level": {"type": "string", "enum": ["L1", "L2", "L3"], "description": "记忆层级,默认 L2"},
|
|
109
|
+
"tags": {"type": "array", "items": {"type": "string"}, "description": "标签"},
|
|
110
|
+
"ttl": {"type": "integer", "description": "存活秒数,可空"},
|
|
111
|
+
},
|
|
112
|
+
"required": ["content"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "memory_read",
|
|
117
|
+
"description": "按 ID/标签/层级检索内核记忆。",
|
|
118
|
+
"inputSchema": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"properties": {
|
|
121
|
+
"memory_id": {"type": "string", "description": "精确记忆ID"},
|
|
122
|
+
"tags": {"type": "string", "description": "逗号分隔标签"},
|
|
123
|
+
"level": {"type": "string", "enum": ["L1", "L2", "L3"]},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "homology_check",
|
|
129
|
+
"description": "同源校验:对 artifact 哈希做共识核验。",
|
|
130
|
+
"inputSchema": {
|
|
131
|
+
"type": "object",
|
|
132
|
+
"properties": {
|
|
133
|
+
"artifact_hash": {"type": "string", "description": "工件哈希"},
|
|
134
|
+
"endpoints": {"type": "array", "items": {"type": "string"}, "description": "参与共识的端点,可空"},
|
|
135
|
+
},
|
|
136
|
+
"required": ["artifact_hash"],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"name": "ontology_query",
|
|
141
|
+
"description": "查询内核本体图谱(实体与关系)。",
|
|
142
|
+
"inputSchema": {
|
|
143
|
+
"type": "object",
|
|
144
|
+
"properties": {
|
|
145
|
+
"entity_type": {"type": "string", "description": "实体类型过滤"},
|
|
146
|
+
"relation": {"type": "string", "description": "关系类型过滤"},
|
|
147
|
+
"depth": {"type": "integer", "description": "展开深度,默认 1"},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "neural_activate",
|
|
153
|
+
"description": "激活神经节点并可传播。",
|
|
154
|
+
"inputSchema": {
|
|
155
|
+
"type": "object",
|
|
156
|
+
"properties": {
|
|
157
|
+
"node_id": {"type": "string", "description": "节点ID,默认 node_001"},
|
|
158
|
+
"intensity": {"type": "number", "description": "激活强度 0-1,默认 1.0"},
|
|
159
|
+
"propagate": {"type": "boolean", "description": "是否传播"},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def dispatch_tool(name, args):
|
|
167
|
+
a = args or {}
|
|
168
|
+
if name == "kernel_info":
|
|
169
|
+
return call_api("GET", "/api/v1/info")
|
|
170
|
+
if name == "kernel_mount":
|
|
171
|
+
p = {}
|
|
172
|
+
if a.get("instance_id"):
|
|
173
|
+
p["instance_id"] = a["instance_id"]
|
|
174
|
+
if a.get("config"):
|
|
175
|
+
p["config"] = a["config"]
|
|
176
|
+
return call_api("POST", "/api/v1/kernel/mount", p)
|
|
177
|
+
if name == "kernel_self_check":
|
|
178
|
+
return call_api("POST", "/api/v1/kernel/self-check", {})
|
|
179
|
+
if name == "kernel_evolve":
|
|
180
|
+
return call_api("POST", "/api/v1/kernel/evolve",
|
|
181
|
+
{"problem_desc": a.get("problem_desc", "generic meta-loop step")})
|
|
182
|
+
if name == "kernel_status":
|
|
183
|
+
return call_api("GET", "/api/v1/kernel/status")
|
|
184
|
+
if name == "memory_write":
|
|
185
|
+
p = {"content": a.get("content", ""), "level": a.get("level", "L2")}
|
|
186
|
+
if a.get("tags"):
|
|
187
|
+
p["tags"] = a["tags"]
|
|
188
|
+
if a.get("ttl") is not None:
|
|
189
|
+
p["ttl"] = a["ttl"]
|
|
190
|
+
return call_api("POST", "/api/v1/memory/write", p)
|
|
191
|
+
if name == "memory_read":
|
|
192
|
+
q = {}
|
|
193
|
+
if a.get("memory_id"):
|
|
194
|
+
q["memory_id"] = a["memory_id"]
|
|
195
|
+
if a.get("tags"):
|
|
196
|
+
q["tags"] = a["tags"]
|
|
197
|
+
if a.get("level"):
|
|
198
|
+
q["level"] = a["level"]
|
|
199
|
+
return call_api("GET", "/api/v1/memory/read", query=q)
|
|
200
|
+
if name == "homology_check":
|
|
201
|
+
p = {"artifact_hash": a.get("artifact_hash", "")}
|
|
202
|
+
if a.get("endpoints"):
|
|
203
|
+
p["endpoints"] = a["endpoints"]
|
|
204
|
+
return call_api("POST", "/api/v1/homology/check", p)
|
|
205
|
+
if name == "ontology_query":
|
|
206
|
+
q = {}
|
|
207
|
+
if a.get("entity_type"):
|
|
208
|
+
q["entity_type"] = a["entity_type"]
|
|
209
|
+
if a.get("relation"):
|
|
210
|
+
q["relation"] = a["relation"]
|
|
211
|
+
if a.get("depth") is not None:
|
|
212
|
+
q["depth"] = a["depth"]
|
|
213
|
+
return call_api("GET", "/api/v1/ontology/query", query=q)
|
|
214
|
+
if name == "neural_activate":
|
|
215
|
+
p = {"node_id": a.get("node_id", "node_001"),
|
|
216
|
+
"intensity": float(a.get("intensity", 1.0)),
|
|
217
|
+
"propagate": bool(a.get("propagate", False))}
|
|
218
|
+
return call_api("POST", "/api/v1/neural/activate", p)
|
|
219
|
+
return {"error": "unknown tool: %s" % name}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# ---------------------------------------------------------------------------
|
|
223
|
+
# MCP stdio 协议(JSON-RPC 2.0)
|
|
224
|
+
# ---------------------------------------------------------------------------
|
|
225
|
+
def reply(msg_id, result):
|
|
226
|
+
sys.stdout.write(json.dumps({"jsonrpc": "2.0", "id": msg_id, "result": result}) + "\n")
|
|
227
|
+
sys.stdout.flush()
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def reply_error(msg_id, code, message):
|
|
231
|
+
sys.stdout.write(json.dumps(
|
|
232
|
+
{"jsonrpc": "2.0", "id": msg_id, "error": {"code": code, "message": message}}) + "\n")
|
|
233
|
+
sys.stdout.flush()
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def handle(req):
|
|
237
|
+
method = req.get("method", "")
|
|
238
|
+
msg_id = req.get("id")
|
|
239
|
+
if method == "initialize":
|
|
240
|
+
reply(msg_id, {
|
|
241
|
+
"protocolVersion": PROTOCOL_VERSION,
|
|
242
|
+
"capabilities": {"tools": {}},
|
|
243
|
+
"serverInfo": {"name": SERVER_NAME, "version": SERVER_VERSION},
|
|
244
|
+
})
|
|
245
|
+
elif method == "notifications/initialized":
|
|
246
|
+
pass
|
|
247
|
+
elif method == "tools/list":
|
|
248
|
+
reply(msg_id, {"tools": TOOLS})
|
|
249
|
+
elif method == "tools/call":
|
|
250
|
+
params = req.get("params") or {}
|
|
251
|
+
name = params.get("name", "")
|
|
252
|
+
try:
|
|
253
|
+
out = dispatch_tool(name, params.get("arguments"))
|
|
254
|
+
text = json.dumps(out, ensure_ascii=False)[:8000]
|
|
255
|
+
reply(msg_id, {"content": [{"type": "text", "text": text}]})
|
|
256
|
+
except Exception as e:
|
|
257
|
+
reply(msg_id, {"content": [{"type": "text", "text": "tool error: %s" % e}]})
|
|
258
|
+
elif method == "ping":
|
|
259
|
+
reply(msg_id, {})
|
|
260
|
+
elif method.startswith("notifications/"):
|
|
261
|
+
pass
|
|
262
|
+
else:
|
|
263
|
+
if msg_id is not None:
|
|
264
|
+
reply_error(msg_id, -32601, "method not found: %s" % method)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def main():
|
|
268
|
+
if not API_KEY:
|
|
269
|
+
sys.stderr.write("[zongyuan-kernel-mcp] warning: ZR_API_KEY not set; "
|
|
270
|
+
"authenticated endpoints will return 401\n")
|
|
271
|
+
for line in sys.stdin:
|
|
272
|
+
line = line.strip()
|
|
273
|
+
if not line:
|
|
274
|
+
continue
|
|
275
|
+
try:
|
|
276
|
+
req = json.loads(line)
|
|
277
|
+
except Exception:
|
|
278
|
+
continue
|
|
279
|
+
try:
|
|
280
|
+
handle(req)
|
|
281
|
+
except Exception as e:
|
|
282
|
+
sys.stderr.write("[zongyuan-kernel-mcp] handler error: %s\n" % e)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
if __name__ == "__main__":
|
|
286
|
+
main()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zongyuan-kernel-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server wrapping the ZONGYUAN-ROOT autonomous kernel REST API (10 tools, stdio, stdlib-only)
|
|
5
|
+
Author: tanbopiao
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: mcp,model-context-protocol,agent,kernel,a2a
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# zongyuan-kernel-mcp
|
|
14
|
+
|
|
15
|
+
把 [ZONGYUAN-ROOT](https://github.com/tanbopiao) 自治内核(V3.0,确权锚点 `Ω₀⊂⊙∞⊂Ω`,DID-BR-000002)的十大标准 REST 能力封装为 **MCP (Model Context Protocol) 服务器**,供任意 MCP Client(Claude Desktop、OpenCode、Cline 等)直接调用。
|
|
16
|
+
|
|
17
|
+
单文件、零第三方依赖、纯 Python 标准库(>= 3.8),stdio 传输。
|
|
18
|
+
|
|
19
|
+
## 上游
|
|
20
|
+
|
|
21
|
+
上游是 ZONGYUAN-ROOT Kernel API(P2A · Protocol-to-Agent Open Layer):
|
|
22
|
+
|
|
23
|
+
- 默认地址 `http://127.0.0.1:9311`,可用环境变量 `ZR_KERNEL_URL` 指向任意已部署实例
|
|
24
|
+
- 除 `kernel_info` 外均需 `X-API-Key` 认证,通过环境变量 `ZR_API_KEY` 提供
|
|
25
|
+
- 上游自带 120 req/min 限流;本封装不缓存、不改写上游语义
|
|
26
|
+
|
|
27
|
+
## 工具清单(与上游端点一一对应)
|
|
28
|
+
|
|
29
|
+
| 工具 | 方法与路径 | 说明 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `kernel_info` | GET /api/v1/info | 确权锚点、DID、版本、端点清单(免鉴权) |
|
|
32
|
+
| `kernel_mount` | POST /api/v1/kernel/mount | 挂载/初始化内核实例 |
|
|
33
|
+
| `kernel_self_check` | POST /api/v1/kernel/self-check | 触发六维自检 |
|
|
34
|
+
| `kernel_evolve` | POST /api/v1/kernel/evolve | 触发元闭环进化 |
|
|
35
|
+
| `kernel_status` | GET /api/v1/kernel/status | 十二维状态、算子数、记忆水位 |
|
|
36
|
+
| `memory_write` | POST /api/v1/memory/write | 写入记忆(L1/L2/L3) |
|
|
37
|
+
| `memory_read` | GET /api/v1/memory/read | 按 ID/标签/层级检索记忆 |
|
|
38
|
+
| `homology_check` | POST /api/v1/homology/check | 工件哈希同源共识校验 |
|
|
39
|
+
| `ontology_query` | GET /api/v1/ontology/query | 本体图谱实体与关系查询 |
|
|
40
|
+
| `neural_activate` | POST /api/v1/neural/activate | 激活神经节点并可传播 |
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/tanbopiao/zongyuan-kernel-mcp.git
|
|
46
|
+
cd zongyuan-kernel-mcp
|
|
47
|
+
ZR_KERNEL_URL=http://127.0.0.1:9311 ZR_API_KEY=<your-key> python3 server.py
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### MCP 客户端配置示例
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"zongyuan-kernel": {
|
|
56
|
+
"command": "python3",
|
|
57
|
+
"args": ["/path/to/zongyuan-kernel-mcp/server.py"],
|
|
58
|
+
"env": {
|
|
59
|
+
"ZR_KERNEL_URL": "http://127.0.0.1:9311",
|
|
60
|
+
"ZR_API_KEY": "<your-key>"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 已验证
|
|
68
|
+
|
|
69
|
+
- MCP stdio 协议:`initialize` / `tools/list` / `tools/call` 全链路通过
|
|
70
|
+
- 对真实内核实例实测:`kernel_info`、`kernel_status`、`ontology_query` 返回正常
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
server.py
|
|
5
|
+
zongyuan_kernel_mcp.egg-info/PKG-INFO
|
|
6
|
+
zongyuan_kernel_mcp.egg-info/SOURCES.txt
|
|
7
|
+
zongyuan_kernel_mcp.egg-info/dependency_links.txt
|
|
8
|
+
zongyuan_kernel_mcp.egg-info/entry_points.txt
|
|
9
|
+
zongyuan_kernel_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
server
|