-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbindings.py
More file actions
59 lines (50 loc) · 1.9 KB
/
bindings.py
File metadata and controls
59 lines (50 loc) · 1.9 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
from typing import Any, List, Dict
from mcp import types
from web_algebra.operation import Operation
from rdflib.query import Result
from rdflib.term import Node
class Bindings(Operation):
"""
Extracts the sequence of binding dictionaries from SPARQL Result.
Converts Result table format to sequence for use with ForEach.
"""
@classmethod
def description(cls) -> str:
return "Extracts the sequence of binding dictionaries from SPARQL Result"
@classmethod
def inputSchema(cls) -> dict:
return {
"type": "object",
"properties": {
"table": {"description": "SPARQL Result to extract bindings from"}
},
"required": ["table"],
}
def execute(self, table: Result) -> List[Dict[str, Node]]:
"""Pure function: extract bindings from Result"""
if not isinstance(table, Result):
raise TypeError(
f"Bindings operation expects table to be Result, got {type(table)}"
)
return table.bindings
def execute_json(
self, arguments: dict, variable_stack: list = []
) -> List[Dict[str, Node]]:
"""JSON execution: process arguments with strict type checking"""
# Process table
table_data = Operation.process_json(
self.settings, arguments["table"], self.context, variable_stack
)
if not isinstance(table_data, Result):
raise TypeError(
f"Bindings operation expects 'table' to be Result, got {type(table_data)}"
)
return self.execute(table_data)
def mcp_run(self, arguments: dict, context: Any = None) -> Any:
"""MCP execution: plain args → plain results"""
# For MCP, just return summary
return [
types.TextContent(
type="text", text="Extracted bindings from SPARQL results"
)
]