INNER CODE UNIT · Python

execute

Arthur-Ficial/apfel · mcp/calculator/server.py:136

def execute(name, args):
    """Execute a tool by name. Tolerates improvised argument keys."""
    nums = get_nums(args)
    a_raw = args.get("a", nums[0] if nums else 0)
    b_raw = args.get("b", nums[1] if len(nums) > 1 else 0)
    a = to_num(a_raw)
    b = to_num(b_raw)
    if a is None:
        return f"Error: non-numeric argument {a_raw!r}"
    if b is None:
        return f"Error: non-numeric argument {b_raw!r}"

    try:
        if name == "add":
            r = a + b
        elif name == "subtract":
            r = a - b
        elif name == "multiply":

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…