vod-devkit 0.0.0-stage → 0.1.1
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.
- package/CHANGELOG.md +13 -0
- package/LICENSE.txt +21 -0
- package/QUICKSTART.md +79 -0
- package/README.en.md +75 -0
- package/README.md +84 -2
- package/bin/vod-devkit +464 -0
- package/contract/tools.schema.json +187 -0
- package/npm/cli.js +39 -0
- package/package.json +35 -4
- package/safety/policy.json +48 -0
- package/skills/vod-core/SKILL.md +23 -0
- package/skills/vod-feedback-collect/SKILL.md +90 -0
- package/skills/vod-problem-classification-rules/SKILL.md +45 -0
- package/skills/vod-scoring-rules/SKILL.md +37 -0
- package/vod_mcp/__init__.py +11 -0
- package/vod_mcp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/packs.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/policy.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/provenance.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/server.cpython-314.pyc +0 -0
- package/vod_mcp/__pycache__/tools.cpython-314.pyc +0 -0
- package/vod_mcp/packs.py +30 -0
- package/vod_mcp/policy.py +98 -0
- package/vod_mcp/provenance.py +43 -0
- package/vod_mcp/runtime.example.json +6 -0
- package/vod_mcp/runtime.json +1473 -0
- package/vod_mcp/server.py +105 -0
- package/vod_mcp/tools.py +620 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""MCP stdio server(JSON-RPC 2.0,行分隔)。
|
|
2
|
+
|
|
3
|
+
依赖:Python 3.10+,零第三方依赖(内网友好)。
|
|
4
|
+
握手记录 clientInfo(宿主感知);工具调用前过声明式护栏。
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# 自举包路径(对任意 MCP 宿主成立:不依赖宿主透传 PYTHONPATH——
|
|
12
|
+
# Hermes 等宿主出于安全过滤环境变量,stdio 子进程只继承白名单)
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
14
|
+
|
|
15
|
+
from vod_mcp import packs, policy as policy_mod, tools # noqa: E402
|
|
16
|
+
|
|
17
|
+
_PROTOCOL_VERSION = "2025-06-18"
|
|
18
|
+
_client_info = {}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _result(req_id, result):
|
|
22
|
+
return {"jsonrpc": "2.0", "id": req_id, "result": result}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _error(req_id, code, message):
|
|
26
|
+
return {"jsonrpc": "2.0", "id": req_id, "error": {"code": code, "message": message}}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def handle(message: dict) -> dict | None:
|
|
30
|
+
method = message.get("method", "")
|
|
31
|
+
req_id = message.get("id")
|
|
32
|
+
if method == "initialize":
|
|
33
|
+
global _client_info
|
|
34
|
+
_client_info = (message.get("params") or {}).get("clientInfo") or {}
|
|
35
|
+
return _result(req_id, {
|
|
36
|
+
"protocolVersion": _PROTOCOL_VERSION,
|
|
37
|
+
"capabilities": {"tools": {}},
|
|
38
|
+
"serverInfo": {
|
|
39
|
+
"name": "vod-devkit",
|
|
40
|
+
"version": tools.load_contract()["version"],
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
if method == "notifications/initialized":
|
|
44
|
+
return None # 通知无响应
|
|
45
|
+
if method == "ping":
|
|
46
|
+
return _result(req_id, {})
|
|
47
|
+
if method == "tools/list":
|
|
48
|
+
return _result(req_id, {"tools": tools.tool_specs(packs.enabled_tools())})
|
|
49
|
+
if method == "tools/call":
|
|
50
|
+
params = message.get("params") or {}
|
|
51
|
+
name = params.get("name") or ""
|
|
52
|
+
args = params.get("arguments") or {}
|
|
53
|
+
pol = policy_mod.load_policy()
|
|
54
|
+
verdict, msg = policy_mod.decide(
|
|
55
|
+
policy_mod.check_tool_call(pol, name, args) if name else [])
|
|
56
|
+
if verdict == "deny":
|
|
57
|
+
return _error(req_id, -32010, f"[guard:deny] {msg}")
|
|
58
|
+
if verdict == "confirm":
|
|
59
|
+
return _error(req_id, -32011, f"[guard:confirm] {msg}")
|
|
60
|
+
text_hits = policy_mod.check_text(
|
|
61
|
+
pol, json.dumps(policy_mod.guard_scope(args), ensure_ascii=False))
|
|
62
|
+
if text_hits:
|
|
63
|
+
return _error(req_id, -32010,
|
|
64
|
+
f"[guard:deny] {policy_mod.decide(text_hits)[1]}")
|
|
65
|
+
try:
|
|
66
|
+
out = tools.dispatch(name, args, _client_info)
|
|
67
|
+
return _result(req_id, {
|
|
68
|
+
"content": [{"type": "text", "text": json.dumps(out, ensure_ascii=False)}],
|
|
69
|
+
"structuredContent": out,
|
|
70
|
+
"isError": False,
|
|
71
|
+
})
|
|
72
|
+
except tools.ToolError as e:
|
|
73
|
+
return _error(req_id, e.code, str(e))
|
|
74
|
+
if req_id is not None:
|
|
75
|
+
return _error(req_id, -32601, f"未知方法: {method}")
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def main():
|
|
80
|
+
# 启动自诊(排障:写 /tmp,宿主过滤环境变量时可观察实际 env)
|
|
81
|
+
try:
|
|
82
|
+
tools._ensure_first_boot() # D-key-guard-3①:首启标记+构建机残留清理(preset 兜底)
|
|
83
|
+
except Exception:
|
|
84
|
+
pass
|
|
85
|
+
tools._log(f"started pid={os.getpid()} argv={sys.argv} "
|
|
86
|
+
f"VOD_PACKS={os.environ.get('VOD_PACKS')!r} "
|
|
87
|
+
f"distribution={tools._distribution()} "
|
|
88
|
+
f"cwd={os.getcwd()}")
|
|
89
|
+
for line in sys.stdin:
|
|
90
|
+
line = line.strip()
|
|
91
|
+
if not line:
|
|
92
|
+
continue
|
|
93
|
+
try:
|
|
94
|
+
message = json.loads(line)
|
|
95
|
+
except json.JSONDecodeError:
|
|
96
|
+
resp = _error(None, -32700, "解析错误")
|
|
97
|
+
else:
|
|
98
|
+
resp = handle(message)
|
|
99
|
+
if resp is not None:
|
|
100
|
+
sys.stdout.write(json.dumps(resp, ensure_ascii=False) + "\n")
|
|
101
|
+
sys.stdout.flush()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
main()
|