Skip to main content
Glama

execute_arcpy_code

Run custom Python with arcpy inside the open ArcGIS Pro project to handle tasks no dedicated tool covers. Variables persist between calls, print output is captured, and final expression values are returned.

Instructions

Run Python inside ArcGIS Pro. arcpy is already imported and arcpy.mp.ArcGISProject('CURRENT') is the open project. Variables persist between calls, print() output is captured, and the value of a final expression is returned. Use this whenever no dedicated tool covers the task.

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": "execute_arcpy_code"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYesPython source to run.
reset_namespaceNoForget variables kept from earlier calls.
timeout_secondsNoStop the code after this many seconds (0 = no limit). A call blocked inside a tool or an external process stops when it returns.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.2.0
    • addedInput schema / properties / timeout_seconds
      Added value: +{
      +  "default": 600,
      +  "description": "Stop the code after this many seconds (0 = no limit). A call blocked inside a tool or an external process stops when it returns.",
      +  "title": "Timeout Seconds",
      +  "type": "integer"
      +}
  2. Changed2 schema fields changedv1.1.1
    • addedInput schema / properties / code / description
      Added value: +"Python source to run."
    • addedInput schema / properties / reset_namespace
      Added value: +{
      +  "default": false,
      +  "description": "Forget variables kept from earlier calls.",
      +  "title": "Reset Namespace",
      +  "type": "boolean"
      +}
  3. First observedv0.1.0

TDQS

A4.6/5.0
Behavior4/5

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

With no annotations, the description carries the whole behavioral burden, and it does disclose key traits: the namespace persists across calls, print() is captured, and the final expression's value is returned. It omits that executed code mutates the live project and datasets irreversibly, with no undo or confirmation, which is a meaningful gap 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.

Conciseness5/5

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

Four compact sentences with no filler, front-loading the environment facts an agent needs before writing code, then the routing rule. Every clause carries information the schema does not.

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?

The output schema covers return values and all three parameters are documented, so the description only needs to supply environment and state semantics, which it does well. The remaining shortfall is the absence of any warning about persistent side effects on the open project.

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?

Schema coverage is 100%, so the baseline is 3, but the description goes further by explaining that variables persist between calls, which gives reset_namespace concrete meaning, and that a final expression's value is returned, which clarifies the code argument's semantics. The timeout caveat lives only in the schema, so the gain is partial rather than complete.

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?

The definition uses a specific verb and resource ('Run Python inside ArcGIS Pro') and describes the execution environment: arcpy is pre-imported, arcpy.mp.ArcGISProject('CURRENT') resolves to the open project, and an enclosing escape-hatch role is stated. An agent can immediately tell this apart from the ~30 focused siblings like add_field or create_map.

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?

'Use this whenever no dedicated tool covers the task' is an explicit routing rule that both selects this tool and excludes it when a specialized sibling applies. It gives the agent a decision procedure instead of leaving route selection to inference.

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

Deploy Server

Other Tools