-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexecute.py
More file actions
56 lines (48 loc) · 2.09 KB
/
execute.py
File metadata and controls
56 lines (48 loc) · 2.09 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
from typing import Any
from mcp import types
from web_algebra.operation import Operation
class Execute(Operation):
"""
Execute a (potentially nested) operation from its JSON representation.
"""
@classmethod
def description(cls) -> str:
return "Executes a (potentially nested) operation from its JSON representation. The operation is expected to be an instance of the Operation class."
@classmethod
def inputSchema(cls) -> dict:
"""
Returns the JSON schema of the operation's input arguments.
"""
return {
"type": "object",
"properties": {
"operation": {
"type": "object",
"description": "An instance of an Operation to execute.",
"properties": {
"type": {
"type": "string",
"description": "Type of the operation",
},
},
"required": ["type"],
}
},
"required": ["operation"],
}
def execute(self, operation: Any) -> Any:
"""Pure function: execute operation with RDFLib terms"""
if not isinstance(operation, dict) or "@op" not in operation:
raise TypeError(
f"Execute.execute expects operation dict with '@op' key, got {type(operation)}"
)
# Delegate to Operation.process_json for nested operation execution
return Operation.process_json(self.settings, operation, self.context)
def execute_json(self, arguments: dict, variable_stack: list = []) -> Any:
"""JSON execution: pass raw operation to execute"""
# Don't process the operation argument - execute() expects raw operation dict
return self.execute(arguments["operation"])
def mcp_run(self, arguments: dict, context: Any = None) -> Any:
"""MCP execution: plain args → plain results"""
result = self.execute(arguments["operation"])
return [types.TextContent(type="text", text=str(result))]