Skip to main content
Glama

Stat Run Code

stat_run_code

Run custom Python in the statistical session namespace to perform analyses not covered by structured tools, using preloaded Pingouin, pandas, NumPy, Matplotlib, and Seaborn; plots save automatically.

Instructions

Execute arbitrary Python against the session namespace — the escape hatch.

Use this for anything the structured tools do not cover: custom recoding, a Pingouin function not exposed as a tool, or a bespoke plot.

Pre-bound names: pg (pingouin), pd (pandas), np (numpy), plt (matplotlib), sns (seaborn), plus every loaded object by name.

The value of a trailing expression is returned. Matplotlib figures are saved automatically and their paths returned.

WHEN TO USE: beyond the structured tools. WHEN NOT TO USE: for routine analyses — the structured tools report assumptions and effect sizes that a bare call would omit.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "code": "<code>"
    },
    "name": "stat_run_code"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYes

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.5/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and does well: it discloses the pre-bound names (`pg`, `pd`, `np`, `plt`, `sns`, plus loaded objects), that a trailing expression's value is returned, and that matplotlib figures are auto-saved with paths returned. It stops short of stating sandbox/security limits, error behavior, or explicitly that namespace state persists across calls, which matter for arbitrary code execution.

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?

Front-loaded with the core statement, then structured with labeled WHEN TO USE / WHEN NOT TO USE sections that make scanning easy. Minor waste: 'WHEN TO USE: beyond the structured tools' restates the opening sentence's framing rather than adding new routing information.

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

Completeness4/5

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

An output schema exists, so return values needn't be explained, yet the description still clarifies trailing-expression semantics and figure-path returns. Given this is arbitrary code execution with no annotations, the remaining gaps are failure modes and whether namespace state persists between calls.

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

Parameters4/5

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

The single `code` parameter has 0% schema description coverage, so the description must compensate, and it largely does: it explains the execution context (session namespace), what names are pre-bound, and how output is produced. It still doesn't state the language/version constraints or whether imports of other libraries are permitted.

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

Purpose5/5

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

States a specific verb and resource — 'Execute arbitrary Python against the session namespace' — and explicitly frames itself as 'the escape hatch' relative to the structured tools. An agent can distinguish it from every stat_* sibling without opening a schema.

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

Usage Guidelines5/5

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

Has explicit WHEN TO USE and WHEN NOT TO USE blocks, with concrete motivating cases (custom recoding, an unexposed Pingouin function, a bespoke plot). The exclusion names the tradeoff — structured tools report assumptions and effect sizes that a bare call omits — which is exactly the kind of disambiguation an agent needs to route correctly.

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