-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvariable.py
More file actions
53 lines (44 loc) · 1.85 KB
/
variable.py
File metadata and controls
53 lines (44 loc) · 1.85 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
from typing import Any
from mcp import types
from web_algebra.operation import Operation
class Variable(Operation):
"""
Sets a variable in the current scope, similar to XSLT's <xsl:variable>.
Variables follow lexical scoping rules like XSLT.
"""
@classmethod
def description(cls) -> str:
return "Sets a variable in the current scope, similar to XSLT's <xsl:variable>"
@classmethod
def inputSchema(cls) -> dict:
return {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The variable name to assign to.",
},
"value": {
"description": "The expression/operation to evaluate and assign to the variable."
},
},
"required": ["name", "value"],
"additionalProperties": False,
}
def execute(self, name: str, value: Any, variable_stack: list) -> None:
"""Pure function: store name/value in variable stack"""
self.set_variable(name, value, variable_stack)
return None
def execute_json(self, arguments: dict, variable_stack: list = []) -> None:
"""JSON execution: evaluate value expression and store variable"""
name: str = arguments["name"]
value_expr = arguments["value"]
# Evaluate the value expression in the current context
value = Operation.process_json(
self.settings, value_expr, self.context, variable_stack
)
# Call pure function to store the variable
return self.execute(name, value, variable_stack)
def mcp_run(self, arguments: dict, context: Any = None) -> Any:
"""MCP execution: plain args → confirmation"""
return [types.TextContent(type="text", text="Variable set successfully")]