-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_server.py
More file actions
80 lines (67 loc) · 2.42 KB
/
Copy pathmcp_server.py
File metadata and controls
80 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
MCP Server for Agent Belief Revision Contradiction Pruner Skill.
"""
import json
import sys
from client import BeliefRevisionEngine
ENGINE = BeliefRevisionEngine()
def handle_request(req: dict) -> dict:
method = req.get("method")
params = req.get("params", {})
if method == "tools/list":
return {
"tools": [
{
"name": "assert_belief",
"description": "Incorporate a propositional belief with epistemic entrenchment",
"inputSchema": {
"type": "object",
"properties": {
"key": {"type": "string"},
"value": {},
"entrenchment": {"type": "number", "default": 1.0},
"source": {"type": "string", "default": "agent"}
},
"required": ["key", "value"]
}
},
{
"name": "get_world_state",
"description": "Retrieve currently held consistent world beliefs",
"inputSchema": {
"type": "object"
}
}
]
}
elif method == "tools/call":
tool_name = params.get("name")
args = params.get("arguments", {})
if tool_name == "assert_belief":
res = ENGINE.assert_belief(
args["key"],
args["value"],
args.get("entrenchment", 1.0),
args.get("source", "agent")
)
return {"content": [{"type": "text", "text": json.dumps(res)}]}
elif tool_name == "get_world_state":
res = ENGINE.get_world_state()
return {"content": [{"type": "text", "text": json.dumps(res)}]}
return {"error": f"Unknown tool: {tool_name}"}
return {"error": f"Unknown method: {method}"}
def main():
for line in sys.stdin:
if not line.strip():
continue
try:
req = json.loads(line)
resp = handle_request(req)
resp["id"] = req.get("id")
sys.stdout.write(json.dumps(resp) + "\n")
sys.stdout.flush()
except Exception as e:
sys.stdout.write(json.dumps({"error": str(e)}) + "\n")
sys.stdout.flush()
if __name__ == "__main__":
main()