Skip to main content
Glama
FlowLLM-AI

Finance MCP

by FlowLLM-AI

execute_code

Run Python code for financial analysis and calculations to support research workflows, with results output via print statements.

Instructions

Execute python code can be used in scenarios such as analysis or calculation, and the final result can be printed using the print function.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYescode to be executed

Implementation Reference

  • The async_execute method is the main handler for the execute_code tool. It retrieves the 'code' from input_dict, executes it via exec_code, and sets the output.
    async def async_execute(self):
        """Execute the provided Python code asynchronously.
    
        The method reads the ``code`` field from ``input_dict``,
        delegates execution to :func:`exec_code`, and stores the
        textual result in the operation output.
        """
    
        self.set_output(exec_code(self.input_dict["code"]))
  • The build_tool_call method defines the input schema for the execute_code tool, requiring a 'code' string.
    def build_tool_call(self) -> ToolCall:
        """Build the tool call schema used by FlowLLM.
    
        Returns:
            ToolCall: The tool call definition including description and
            input schema.
        """
        return ToolCall(
            **{
                "description": self.get_prompt("tool_description"),
                "input_schema": {
                    "code": {
                        "type": "string",
                        "description": "code to be executed",
                        "required": True,
                    },
                },
            },
        )
  • The ExecuteCodeOp class is registered as a tool operation using the @C.register_op() decorator.
    @C.register_op()
    class ExecuteCodeOp(BaseAsyncToolOp):
  • The gallery __init__.py exports ExecuteCodeOp, making it available for import and use as the execute_code tool.
    from .execute_code_op import ExecuteCodeOp
    from .execute_shell_op import ExecuteShellOp
    
    __all__ = [
        "ExecuteCodeOp",
        "ExecuteShellOp",
  • The exec_code function provides the actual code execution logic, capturing stdout or returning exception messages.
    def exec_code(code: str) -> str:
        """Execute arbitrary Python code and capture its printed output.
    
        The code is executed in the current global context and any text written to
        ``stdout`` is captured and returned as a string. If an exception occurs,
        its string representation is returned instead.
    
        Args:
            code: Python source code to execute.
    
        Returns:
            Captured ``stdout`` output, or the exception message if execution fails.
        """
    
        try:
            redirected_output = StringIO()
            with contextlib.redirect_stdout(redirected_output):
                exec(code)
    
            return redirected_output.getvalue()
    
        except Exception as e:  # noqa: BLE001
            return str(e)
    
        except BaseException as e:
            return str(e)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions that results can be printed using `print`, but doesn't disclose critical behavioral traits such as execution environment, safety risks (e.g., code injection), permissions needed, timeouts, or output handling. This leaves significant gaps for a tool that executes arbitrary code.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that is reasonably concise and front-loaded with the main action. However, it could be more structured by separating usage guidance from behavioral details, and the phrasing 'can be used in scenarios such as' is slightly verbose without adding much clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing arbitrary code, no annotations, and no output schema, the description is incomplete. It lacks essential context such as execution environment, error handling, security implications, and what the return values or outputs look like beyond printing. This is inadequate for a tool with significant behavioral implications.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'code' parameter documented as 'code to be executed'. The description adds minimal value by implying Python code and the use of `print`, but doesn't provide additional syntax, format details, or constraints beyond what the schema already states. Baseline 3 is appropriate given high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Execute python code' and mentions scenarios like 'analysis or calculation', which provides a general purpose. However, it doesn't clearly distinguish this from sibling tools like 'execute_shell' or 'history_calculate', and the phrasing is somewhat vague rather than specific about what exactly gets executed or how.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions scenarios such as 'analysis or calculation' but provides no explicit guidance on when to use this tool versus alternatives like 'execute_shell' or 'history_calculate'. There's no mention of prerequisites, exclusions, or specific contexts that would help an agent choose correctly among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/FlowLLM-AI/finance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server