socratic-mcp 0.1.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.
- socratic_mcp-0.1.0/LICENSE +21 -0
- socratic_mcp-0.1.0/PKG-INFO +62 -0
- socratic_mcp-0.1.0/README.md +47 -0
- socratic_mcp-0.1.0/pyproject.toml +25 -0
- socratic_mcp-0.1.0/setup.cfg +4 -0
- socratic_mcp-0.1.0/socratic_mcp/__init__.py +5 -0
- socratic_mcp-0.1.0/socratic_mcp/server.py +76 -0
- socratic_mcp-0.1.0/socratic_mcp/tools.py +165 -0
- socratic_mcp-0.1.0/socratic_mcp.egg-info/PKG-INFO +62 -0
- socratic_mcp-0.1.0/socratic_mcp.egg-info/SOURCES.txt +12 -0
- socratic_mcp-0.1.0/socratic_mcp.egg-info/dependency_links.txt +1 -0
- socratic_mcp-0.1.0/socratic_mcp.egg-info/entry_points.txt +2 -0
- socratic_mcp-0.1.0/socratic_mcp.egg-info/top_level.txt +1 -0
- socratic_mcp-0.1.0/tests/test_server.py +62 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 socratic-tutor contributors
|
|
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,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socratic-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server exposing a Socratic sidecar (kb_search, chapters, review) to any agent host
|
|
5
|
+
Author: socratic-tutor contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: mcp,model-context-protocol,rag,citations,tutor
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Topic :: Education
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# socratic-mcp
|
|
17
|
+
|
|
18
|
+
把 Socratic sidecar 包成 **MCP server**:任何支持 MCP 的 agent host(DSH、Claude Desktop、Cursor…)都能直接调用,不需要为每个 host 写插件。
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
SOCRATIC_SIDECAR_URL=http://127.0.0.1:8765 python -m socratic_mcp.server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 工具
|
|
25
|
+
|
|
26
|
+
| 工具 | 作用 |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `kb_search` | 检索;返回 citation 与页图 URL;可带 `book`+`chapter` 收窄到章回 |
|
|
29
|
+
| `kb_read` | 按 chunk_id 读取 |
|
|
30
|
+
| `chapter_lookup` | 「卷3」「第7回」或标题片段 → 页码范围与页图;给 `page` 则反查所在章回 |
|
|
31
|
+
| `review_session` | 复盘一个教学会话 |
|
|
32
|
+
| `socratic_state` | 读教学状态机 |
|
|
33
|
+
| `socratic_health` | sidecar 是否可达 + 索引统计 |
|
|
34
|
+
|
|
35
|
+
## 配置
|
|
36
|
+
|
|
37
|
+
| 环境变量 | 默认 | 说明 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `SOCRATIC_SIDECAR_URL` | `http://127.0.0.1:8765` | sidecar 地址 |
|
|
40
|
+
| `SOCRATIC_TOKEN` | 空 | 非空时以 `Authorization: Bearer` 发送 |
|
|
41
|
+
|
|
42
|
+
sidecar 未启动时,工具返回 `{"error":"sidecar_unreachable",...}` 且 `isError: true`,连接不断。
|
|
43
|
+
|
|
44
|
+
## 挂到 DSH
|
|
45
|
+
|
|
46
|
+
`~/.dsh/dsh-mcp-plus/servers.json` 加一条:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"socratic": {
|
|
52
|
+
"command": "python",
|
|
53
|
+
"args": ["-m", "socratic_mcp.server"],
|
|
54
|
+
"env": { "SOCRATIC_SIDECAR_URL": "http://127.0.0.1:8765" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 协议实现范围
|
|
61
|
+
|
|
62
|
+
`initialize`、`ping`、`tools/list`、`tools/call`,stdio + newline-delimited JSON-RPC 2.0。没有 SDK 依赖(6 条测试,含一次真实 stdio 往返)。
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# socratic-mcp
|
|
2
|
+
|
|
3
|
+
把 Socratic sidecar 包成 **MCP server**:任何支持 MCP 的 agent host(DSH、Claude Desktop、Cursor…)都能直接调用,不需要为每个 host 写插件。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
SOCRATIC_SIDECAR_URL=http://127.0.0.1:8765 python -m socratic_mcp.server
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 工具
|
|
10
|
+
|
|
11
|
+
| 工具 | 作用 |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `kb_search` | 检索;返回 citation 与页图 URL;可带 `book`+`chapter` 收窄到章回 |
|
|
14
|
+
| `kb_read` | 按 chunk_id 读取 |
|
|
15
|
+
| `chapter_lookup` | 「卷3」「第7回」或标题片段 → 页码范围与页图;给 `page` 则反查所在章回 |
|
|
16
|
+
| `review_session` | 复盘一个教学会话 |
|
|
17
|
+
| `socratic_state` | 读教学状态机 |
|
|
18
|
+
| `socratic_health` | sidecar 是否可达 + 索引统计 |
|
|
19
|
+
|
|
20
|
+
## 配置
|
|
21
|
+
|
|
22
|
+
| 环境变量 | 默认 | 说明 |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `SOCRATIC_SIDECAR_URL` | `http://127.0.0.1:8765` | sidecar 地址 |
|
|
25
|
+
| `SOCRATIC_TOKEN` | 空 | 非空时以 `Authorization: Bearer` 发送 |
|
|
26
|
+
|
|
27
|
+
sidecar 未启动时,工具返回 `{"error":"sidecar_unreachable",...}` 且 `isError: true`,连接不断。
|
|
28
|
+
|
|
29
|
+
## 挂到 DSH
|
|
30
|
+
|
|
31
|
+
`~/.dsh/dsh-mcp-plus/servers.json` 加一条:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"socratic": {
|
|
37
|
+
"command": "python",
|
|
38
|
+
"args": ["-m", "socratic_mcp.server"],
|
|
39
|
+
"env": { "SOCRATIC_SIDECAR_URL": "http://127.0.0.1:8765" }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 协议实现范围
|
|
46
|
+
|
|
47
|
+
`initialize`、`ping`、`tools/list`、`tools/call`,stdio + newline-delimited JSON-RPC 2.0。没有 SDK 依赖(6 条测试,含一次真实 stdio 往返)。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "socratic-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MCP server exposing a Socratic sidecar (kb_search, chapters, review) to any agent host"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [{ name = "socratic-tutor contributors" }]
|
|
12
|
+
keywords = ["mcp", "model-context-protocol", "rag", "citations", "tutor"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Topic :: Education",
|
|
17
|
+
]
|
|
18
|
+
license = { text = "MIT" }
|
|
19
|
+
dependencies = []
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
socratic-mcp = "socratic_mcp.server:main"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
packages = ["socratic_mcp"]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Minimal MCP server over stdio (JSON-RPC 2.0, newline-delimited).
|
|
2
|
+
|
|
3
|
+
python -m socratic_mcp.server # uses SOCRATIC_SIDECAR_URL / SOCRATIC_TOKEN
|
|
4
|
+
|
|
5
|
+
Speaks just enough of the protocol for an agent host: initialize, tools/list,
|
|
6
|
+
tools/call, ping. No third-party dependencies.
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from . import tools
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _ok(mid, result):
|
|
15
|
+
return {"jsonrpc": "2.0", "id": mid, "result": result}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _err(mid, code, message):
|
|
19
|
+
return {"jsonrpc": "2.0", "id": mid, "error": {"code": code, "message": message}}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def handle(msg):
|
|
23
|
+
"""One request -> one response (or None for notifications)."""
|
|
24
|
+
method = msg.get("method")
|
|
25
|
+
mid = msg.get("id")
|
|
26
|
+
if mid is None: # notification
|
|
27
|
+
return None
|
|
28
|
+
if method == "initialize":
|
|
29
|
+
return _ok(mid, {
|
|
30
|
+
"protocolVersion": tools.PROTOCOL,
|
|
31
|
+
"capabilities": {"tools": {"listChanged": False}},
|
|
32
|
+
"serverInfo": {"name": "socratic-sidecar", "version": tools.VERSION},
|
|
33
|
+
})
|
|
34
|
+
if method == "ping":
|
|
35
|
+
return _ok(mid, {})
|
|
36
|
+
if method == "tools/list":
|
|
37
|
+
return _ok(mid, {"tools": tools.TOOLS})
|
|
38
|
+
if method == "tools/call":
|
|
39
|
+
params = msg.get("params") or {}
|
|
40
|
+
name = params.get("name")
|
|
41
|
+
args = params.get("arguments") or {}
|
|
42
|
+
if not any(t["name"] == name for t in tools.TOOLS):
|
|
43
|
+
return _err(mid, -32602, "unknown tool: %s" % name)
|
|
44
|
+
try:
|
|
45
|
+
result = tools.call_tool(name, args)
|
|
46
|
+
except KeyError as e:
|
|
47
|
+
return _err(mid, -32602, "bad arguments for %s: %s" % (name, e))
|
|
48
|
+
except Exception as e: # never crash the transport on one bad call
|
|
49
|
+
return _err(mid, -32603, str(e)[:200])
|
|
50
|
+
failed = isinstance(result, dict) and result.get("ok") is False
|
|
51
|
+
return _ok(mid, {"content": [{"type": "text",
|
|
52
|
+
"text": json.dumps(result, ensure_ascii=False)}],
|
|
53
|
+
"isError": bool(failed)})
|
|
54
|
+
return _err(mid, -32601, "method not found: %s" % method)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def main():
|
|
58
|
+
for line in sys.stdin:
|
|
59
|
+
line = line.strip()
|
|
60
|
+
if not line:
|
|
61
|
+
continue
|
|
62
|
+
try:
|
|
63
|
+
msg = json.loads(line)
|
|
64
|
+
except Exception:
|
|
65
|
+
sys.stdout.write(json.dumps(_err(None, -32700, "parse error")) + "\n")
|
|
66
|
+
sys.stdout.flush()
|
|
67
|
+
continue
|
|
68
|
+
out = handle(msg)
|
|
69
|
+
if out is not None:
|
|
70
|
+
sys.stdout.write(json.dumps(out, ensure_ascii=False) + "\n")
|
|
71
|
+
sys.stdout.flush()
|
|
72
|
+
return 0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
sys.exit(main())
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""MCP tools that expose a Socratic sidecar.
|
|
2
|
+
|
|
3
|
+
The contract is the sidecar's HTTP API (docs/SIDECAR-CONTRACT.md); this module
|
|
4
|
+
only translates MCP tool calls into requests and wraps the JSON back into
|
|
5
|
+
content blocks. No MCP SDK: the stdio protocol is small enough to speak
|
|
6
|
+
directly, which keeps the package dependency-free.
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import urllib.error
|
|
11
|
+
import urllib.parse
|
|
12
|
+
import urllib.request
|
|
13
|
+
|
|
14
|
+
PROTOCOL = "2024-11-05"
|
|
15
|
+
VERSION = "0.1.0"
|
|
16
|
+
|
|
17
|
+
TOOLS = [
|
|
18
|
+
{
|
|
19
|
+
"name": "kb_search",
|
|
20
|
+
"description": "Search the book library; returns citations and page-image URLs. "
|
|
21
|
+
"Use book+chapter to narrow to one chapter of a scanned book.",
|
|
22
|
+
"inputSchema": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"properties": {
|
|
25
|
+
"query": {"type": "string"},
|
|
26
|
+
"view": {"type": "string", "enum": ["student", "tutor"]},
|
|
27
|
+
"limit": {"type": "integer", "minimum": 1, "maximum": 20},
|
|
28
|
+
"source": {"type": "string"},
|
|
29
|
+
"lang": {"type": "string"},
|
|
30
|
+
"book": {"type": "string"},
|
|
31
|
+
"chapter": {"type": "string"},
|
|
32
|
+
},
|
|
33
|
+
"required": ["query"],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "kb_read",
|
|
38
|
+
"description": "Read one chunk by id (citation included).",
|
|
39
|
+
"inputSchema": {
|
|
40
|
+
"type": "object",
|
|
41
|
+
"properties": {"chunk_id": {"type": "integer"}, "view": {"type": "string"}},
|
|
42
|
+
"required": ["chunk_id"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "chapter_lookup",
|
|
47
|
+
"description": "Resolve '卷3' / '第7回' / a title fragment to a page range and page images; "
|
|
48
|
+
"pass page to find which chapter contains it.",
|
|
49
|
+
"inputSchema": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"properties": {
|
|
52
|
+
"book": {"type": "string"},
|
|
53
|
+
"chapter": {"type": "string"},
|
|
54
|
+
"page": {"type": "integer", "minimum": 1},
|
|
55
|
+
"source": {"type": "string"},
|
|
56
|
+
},
|
|
57
|
+
"required": ["book"],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "review_session",
|
|
62
|
+
"description": "Freeze a tutoring session and review it: claim verdicts, error classes, practice.",
|
|
63
|
+
"inputSchema": {
|
|
64
|
+
"type": "object",
|
|
65
|
+
"properties": {
|
|
66
|
+
"session_id": {"type": "string"},
|
|
67
|
+
"answers": {"type": "array", "items": {"type": "string"}},
|
|
68
|
+
},
|
|
69
|
+
"required": ["session_id"],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "socratic_state",
|
|
74
|
+
"description": "Read the teaching state machine state for a session.",
|
|
75
|
+
"inputSchema": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {"session_id": {"type": "string"}},
|
|
78
|
+
"required": ["session_id"],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "socratic_health",
|
|
83
|
+
"description": "Whether the sidecar is reachable, plus index statistics.",
|
|
84
|
+
"inputSchema": {"type": "object", "properties": {}},
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def base_url():
|
|
90
|
+
return os.environ.get("SOCRATIC_SIDECAR_URL", "http://127.0.0.1:8765").rstrip("/")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _headers():
|
|
94
|
+
token = os.environ.get("SOCRATIC_TOKEN", "")
|
|
95
|
+
return {"Authorization": "Bearer " + token} if token else {}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _get(path):
|
|
99
|
+
req = urllib.request.Request(base_url() + path, headers=_headers())
|
|
100
|
+
try:
|
|
101
|
+
with urllib.request.urlopen(req, timeout=60) as r:
|
|
102
|
+
return json.loads(r.read() or b"{}")
|
|
103
|
+
except urllib.error.HTTPError as e:
|
|
104
|
+
body = {}
|
|
105
|
+
try:
|
|
106
|
+
body = json.loads(e.read() or b"{}")
|
|
107
|
+
except Exception:
|
|
108
|
+
pass
|
|
109
|
+
return {"ok": False, "status": e.code, "body": body}
|
|
110
|
+
except Exception as e: # connection refused, DNS, timeout
|
|
111
|
+
return {"ok": False, "error": "sidecar_unreachable", "detail": str(e)[:200],
|
|
112
|
+
"base": base_url()}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _post(path, payload):
|
|
116
|
+
data = json.dumps(payload).encode("utf-8")
|
|
117
|
+
req = urllib.request.Request(base_url() + path, data=data, headers={
|
|
118
|
+
"Content-Type": "application/json", **_headers()})
|
|
119
|
+
try:
|
|
120
|
+
with urllib.request.urlopen(req, timeout=120) as r:
|
|
121
|
+
return json.loads(r.read() or b"{}")
|
|
122
|
+
except urllib.error.HTTPError as e:
|
|
123
|
+
body = {}
|
|
124
|
+
try:
|
|
125
|
+
body = json.loads(e.read() or b"{}")
|
|
126
|
+
except Exception:
|
|
127
|
+
pass
|
|
128
|
+
return {"ok": False, "status": e.code, "body": body}
|
|
129
|
+
except Exception as e:
|
|
130
|
+
return {"ok": False, "error": "sidecar_unreachable", "detail": str(e)[:200],
|
|
131
|
+
"base": base_url()}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def call_tool(name, args):
|
|
135
|
+
"""Map one MCP tool call to the sidecar and return a JSON-able result."""
|
|
136
|
+
if name == "kb_search":
|
|
137
|
+
q = {"q": str(args.get("query", "")),
|
|
138
|
+
"view": str(args.get("view", "student")),
|
|
139
|
+
"limit": str(args.get("limit", 8))}
|
|
140
|
+
for key in ("source", "lang", "book", "chapter"):
|
|
141
|
+
if args.get(key):
|
|
142
|
+
q[key] = str(args[key])
|
|
143
|
+
return _get("/v1/search?" + urllib.parse.urlencode(q))
|
|
144
|
+
if name == "kb_read":
|
|
145
|
+
q = {"view": str(args.get("view", "student"))}
|
|
146
|
+
return _get("/v1/chunks/%d?%s" % (int(args["chunk_id"]), urllib.parse.urlencode(q)))
|
|
147
|
+
if name == "chapter_lookup":
|
|
148
|
+
q = {"book": str(args["book"])}
|
|
149
|
+
if args.get("source"):
|
|
150
|
+
q["source"] = str(args["source"])
|
|
151
|
+
if args.get("chapter"):
|
|
152
|
+
q["q"] = str(args["chapter"])
|
|
153
|
+
if args.get("page"):
|
|
154
|
+
q["page"] = str(args["page"])
|
|
155
|
+
return _get("/v1/chapter?" + urllib.parse.urlencode(q))
|
|
156
|
+
if name == "review_session":
|
|
157
|
+
body = {"session_id": str(args["session_id"])}
|
|
158
|
+
if args.get("answers"):
|
|
159
|
+
body["answers"] = [str(a) for a in args["answers"]]
|
|
160
|
+
return _post("/v1/review", body)
|
|
161
|
+
if name == "socratic_state":
|
|
162
|
+
return _get("/v1/state/" + urllib.parse.quote(str(args["session_id"])))
|
|
163
|
+
if name == "socratic_health":
|
|
164
|
+
return _get("/health")
|
|
165
|
+
raise KeyError(name)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socratic-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server exposing a Socratic sidecar (kb_search, chapters, review) to any agent host
|
|
5
|
+
Author: socratic-tutor contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: mcp,model-context-protocol,rag,citations,tutor
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Topic :: Education
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# socratic-mcp
|
|
17
|
+
|
|
18
|
+
把 Socratic sidecar 包成 **MCP server**:任何支持 MCP 的 agent host(DSH、Claude Desktop、Cursor…)都能直接调用,不需要为每个 host 写插件。
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
SOCRATIC_SIDECAR_URL=http://127.0.0.1:8765 python -m socratic_mcp.server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 工具
|
|
25
|
+
|
|
26
|
+
| 工具 | 作用 |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `kb_search` | 检索;返回 citation 与页图 URL;可带 `book`+`chapter` 收窄到章回 |
|
|
29
|
+
| `kb_read` | 按 chunk_id 读取 |
|
|
30
|
+
| `chapter_lookup` | 「卷3」「第7回」或标题片段 → 页码范围与页图;给 `page` 则反查所在章回 |
|
|
31
|
+
| `review_session` | 复盘一个教学会话 |
|
|
32
|
+
| `socratic_state` | 读教学状态机 |
|
|
33
|
+
| `socratic_health` | sidecar 是否可达 + 索引统计 |
|
|
34
|
+
|
|
35
|
+
## 配置
|
|
36
|
+
|
|
37
|
+
| 环境变量 | 默认 | 说明 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `SOCRATIC_SIDECAR_URL` | `http://127.0.0.1:8765` | sidecar 地址 |
|
|
40
|
+
| `SOCRATIC_TOKEN` | 空 | 非空时以 `Authorization: Bearer` 发送 |
|
|
41
|
+
|
|
42
|
+
sidecar 未启动时,工具返回 `{"error":"sidecar_unreachable",...}` 且 `isError: true`,连接不断。
|
|
43
|
+
|
|
44
|
+
## 挂到 DSH
|
|
45
|
+
|
|
46
|
+
`~/.dsh/dsh-mcp-plus/servers.json` 加一条:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"socratic": {
|
|
52
|
+
"command": "python",
|
|
53
|
+
"args": ["-m", "socratic_mcp.server"],
|
|
54
|
+
"env": { "SOCRATIC_SIDECAR_URL": "http://127.0.0.1:8765" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 协议实现范围
|
|
61
|
+
|
|
62
|
+
`initialize`、`ping`、`tools/list`、`tools/call`,stdio + newline-delimited JSON-RPC 2.0。没有 SDK 依赖(6 条测试,含一次真实 stdio 往返)。
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
socratic_mcp/__init__.py
|
|
5
|
+
socratic_mcp/server.py
|
|
6
|
+
socratic_mcp/tools.py
|
|
7
|
+
socratic_mcp.egg-info/PKG-INFO
|
|
8
|
+
socratic_mcp.egg-info/SOURCES.txt
|
|
9
|
+
socratic_mcp.egg-info/dependency_links.txt
|
|
10
|
+
socratic_mcp.egg-info/entry_points.txt
|
|
11
|
+
socratic_mcp.egg-info/top_level.txt
|
|
12
|
+
tests/test_server.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
socratic_mcp
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import unittest
|
|
5
|
+
|
|
6
|
+
from socratic_mcp import server, tools
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TestProtocol(unittest.TestCase):
|
|
10
|
+
def test_initialize(self):
|
|
11
|
+
out = server.handle({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}})
|
|
12
|
+
self.assertEqual(out["result"]["protocolVersion"], tools.PROTOCOL)
|
|
13
|
+
self.assertIn("tools", out["result"]["capabilities"])
|
|
14
|
+
|
|
15
|
+
def test_tools_list(self):
|
|
16
|
+
out = server.handle({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
|
17
|
+
names = [t["name"] for t in out["result"]["tools"]]
|
|
18
|
+
for want in ("kb_search", "kb_read", "chapter_lookup", "review_session", "socratic_health"):
|
|
19
|
+
self.assertIn(want, names)
|
|
20
|
+
|
|
21
|
+
def test_unknown_tool(self):
|
|
22
|
+
out = server.handle({"jsonrpc": "2.0", "id": 3, "method": "tools/call",
|
|
23
|
+
"params": {"name": "nope", "arguments": {}}})
|
|
24
|
+
self.assertEqual(out["error"]["code"], -32602)
|
|
25
|
+
|
|
26
|
+
def test_notification_has_no_response(self):
|
|
27
|
+
self.assertIsNone(server.handle({"jsonrpc": "2.0", "method": "notifications/initialized"}))
|
|
28
|
+
|
|
29
|
+
def test_unreachable_sidecar_is_a_tool_error_not_a_crash(self):
|
|
30
|
+
old = tools.os.environ.get("SOCRATIC_SIDECAR_URL")
|
|
31
|
+
tools.os.environ["SOCRATIC_SIDECAR_URL"] = "http://127.0.0.1:9"
|
|
32
|
+
try:
|
|
33
|
+
out = server.handle({"jsonrpc": "2.0", "id": 4, "method": "tools/call",
|
|
34
|
+
"params": {"name": "socratic_health", "arguments": {}}})
|
|
35
|
+
self.assertTrue(out["result"]["isError"])
|
|
36
|
+
body = json.loads(out["result"]["content"][0]["text"])
|
|
37
|
+
self.assertEqual(body["error"], "sidecar_unreachable")
|
|
38
|
+
finally:
|
|
39
|
+
if old is None:
|
|
40
|
+
tools.os.environ.pop("SOCRATIC_SIDECAR_URL", None)
|
|
41
|
+
else:
|
|
42
|
+
tools.os.environ["SOCRATIC_SIDECAR_URL"] = old
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestStdio(unittest.TestCase):
|
|
46
|
+
def test_roundtrip_over_stdio(self):
|
|
47
|
+
proc = subprocess.Popen([sys.executable, "-m", "socratic_mcp.server"],
|
|
48
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
49
|
+
stderr=subprocess.DEVNULL, text=True)
|
|
50
|
+
try:
|
|
51
|
+
proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize"}) + "\n")
|
|
52
|
+
proc.stdin.flush()
|
|
53
|
+
line = proc.stdout.readline()
|
|
54
|
+
self.assertIn("protocolVersion", json.loads(line)["result"])
|
|
55
|
+
finally:
|
|
56
|
+
proc.kill()
|
|
57
|
+
for stream in (proc.stdin, proc.stdout):
|
|
58
|
+
try:
|
|
59
|
+
stream.close()
|
|
60
|
+
except Exception:
|
|
61
|
+
pass
|
|
62
|
+
proc.wait(timeout=5)
|