-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuri.py
More file actions
61 lines (49 loc) · 1.99 KB
/
uri.py
File metadata and controls
61 lines (49 loc) · 1.99 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
from typing import Any
from rdflib import URIRef
from rdflib.term import Node
from mcp import types
from web_algebra.operation import Operation
class URI(Operation):
"""
Converts any RDF term to a URI reference (like SPARQL's URI() function)
"""
@classmethod
def description(cls) -> str:
return "Converts any RDF term to a URI reference (like SPARQL's URI() function)"
@classmethod
def inputSchema(cls) -> dict:
return {
"type": "object",
"properties": {
"input": {"description": "The input value to convert to URI"},
},
"required": ["input"],
}
def execute(self, term: Node) -> URIRef:
"""Pure function: RDFLib term → URI reference"""
if not isinstance(term, Node):
raise TypeError(
f"URI operation expects input to be RDFLib term, got {type(term)}"
)
return URIRef(str(term))
def execute_json(self, arguments: dict, variable_stack: list = []) -> URIRef:
"""JSON execution: processes JSON args, returns RDFLib URI reference"""
# Process the input argument through the JSON system
input_data = Operation.process_json(
self.settings, arguments["input"], self.context, variable_stack
)
# Expect RDFLib term directly
if not isinstance(input_data, Node):
raise TypeError(
f"URI operation expects input to be RDFLib term, got {type(input_data)}"
)
# Call pure function
return self.execute(input_data)
def mcp_run(self, arguments: dict, context: Any = None) -> Any:
"""MCP execution: plain args → plain results"""
# Convert plain input to RDFLib term
rdflib_term = Operation.plain_to_rdflib(arguments["input"])
# Call pure function
result = self.execute(rdflib_term)
# Convert result to plain string for MCP
return [types.TextContent(type="text", text=str(result))]