Skip to main content
Glama
reading-plus-ai

mcp-server-data-exploration

run_script

Execute Python scripts for data analytics tasks, displaying output and optionally storing DataFrames in memory without modifying original data.

Instructions

Python Script Execution Tool

Purpose: Execute Python scripts for specific data analytics tasks.

Allowed Actions 1. Print Results: Output will be displayed as the script’s stdout. 2. [Optional] Save DataFrames: Store DataFrames in memory for future use by specifying a save_to_memory name.

Prohibited Actions 1. Overwriting Original DataFrames: Do not modify existing DataFrames to preserve their integrity for future tasks. 2. Creating Charts: Chart generation is not permitted.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes
save_to_memoryNo

Implementation Reference

  • Core handler function that executes the user-provided Python script using exec() in a controlled environment with access to loaded DataFrames, common data science libraries (pandas, numpy, etc.), captures stdout as output, and optionally saves new DataFrames to memory.
    def safe_eval(self, script: str, save_to_memory: Optional[List[str]] = None):
        """safely run a script, return the result if valid, otherwise return the error message"""
        # first extract dataframes from the self.data
        local_dict = {
            **{df_name: df for df_name, df in self.data.items()},
        }
        # execute the script and return the result and if there is error, return the error message
        try:
            stdout_capture = StringIO()
            old_stdout = sys.stdout
            sys.stdout = stdout_capture
            self.notes.append(f"Running script: \n{script}")
            # pylint: disable=exec-used
            exec(script, \
                {'pd': pd, 'np': np, 'scipy': scipy, 'sklearn': sklearn, 'statsmodels': sm}, \
                local_dict)
            std_out_script = stdout_capture.getvalue()
        except Exception as e:
            raise McpError(INTERNAL_ERROR, f"Error running script: {str(e)}") from e
    
        # check if the result is a dataframe
        if save_to_memory:
            for df_name in save_to_memory:
                self.notes.append(f"Saving dataframe '{df_name}' to memory")
                self.data[df_name] = local_dict.get(df_name)
    
        output = std_out_script if std_out_script else "No output"
        self.notes.append(f"Result: {output}")
        return [
            TextContent(type="text", text=f"print out result: {output}")
        ]
  • Pydantic model defining the input schema for the run_script tool: requires a 'script' string and optional 'save_to_memory' list of DataFrame names to persist.
    class RunScript(BaseModel):
        script: str
        save_to_memory: Optional[List[str]] = None
  • Registration of the 'run_script' tool in the MCP server's list_tools handler, specifying name, description, and input schema.
    Tool(
        name=DataExplorationTools.RUN_SCRIPT,
        description=RUN_SCRIPT_TOOL_DESCRIPTION,
        inputSchema=RunScript.model_json_schema(),
    )
  • Enum defining the tool name constant DataExplorationTools.RUN_SCRIPT = 'run_script'.
    class DataExplorationTools(str, Enum):
        LOAD_CSV = "load_csv"
        RUN_SCRIPT = "run_script"
  • Dispatch logic in the main @server.call_tool() handler that extracts arguments and invokes the ScriptRunner.safe_eval method for run_script.
    elif name == DataExplorationTools.RUN_SCRIPT:
        script = arguments.get("script")
        df_name = arguments.get("df_name")
        return script_runner.safe_eval(script, df_name)
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behavioral traits: output is displayed as stdout, optional saving of DataFrames in memory, and prohibitions on overwriting original DataFrames and creating charts. This covers execution behavior, memory handling, and constraints, though it doesn't address error handling, performance limits, or security aspects.

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 well-structured with clear sections ('Purpose', 'Allowed Actions', 'Prohibited Actions'), making it easy to scan. It's appropriately sized without unnecessary fluff, though the 'Purpose' section could be more concise. Every sentence adds value, such as clarifying output behavior and constraints.

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

Completeness3/5

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

Given the complexity of a script execution tool with no annotations and no output schema, the description is moderately complete. It covers execution purpose, allowed/prohibited actions, and some parameter context, but lacks details on error handling, return values, or integration with the sibling tool. For a tool with 2 parameters and significant behavioral implications, more completeness is needed.

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

Parameters2/5

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

The schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'save_to_memory' in the 'Allowed Actions' section, adding some meaning beyond the schema. However, it doesn't explain the 'script' parameter's content or format, leaving a key parameter undocumented. With 2 parameters and low coverage, the description only partially compensates.

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

Purpose4/5

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

The description clearly states the tool's purpose as 'Execute Python scripts for specific data analytics tasks,' providing a specific verb ('Execute') and resource ('Python scripts'). It distinguishes from the sibling tool 'load_csv' by focusing on script execution rather than data loading. However, it doesn't specify what 'specific data analytics tasks' entail, keeping it slightly vague.

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

Usage Guidelines3/5

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

The description provides implied usage guidance through 'Allowed Actions' and 'Prohibited Actions' sections, suggesting when to use certain features like saving DataFrames and when to avoid actions like chart generation. However, it lacks explicit guidance on when to use this tool versus the sibling 'load_csv' or other alternatives, and doesn't mention prerequisites or specific contexts for use.

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/reading-plus-ai/mcp-server-data-exploration'

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