Skip to main content
Glama
advancedcommunities

Salesforce MCP Server

execute_anonymous_apex

Destructive

Execute Apex code against a specified Salesforce Org to test snippets, run batch jobs, or review debug logs. Results are returned in JSON.

Instructions

Execute Apex code in a Salesforce Org. This command allows you to run Apex code directly against a specified Salesforce Org. The code is executed in the context of the Org, and the results are returned in JSON format. You can use this command to test Apex code snippets, run batch jobs, or perform other Apex-related tasks. You can review the debug logs of the execution to see the results of the code execution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.7.0

TDQS

B3.1/5.0
Behavior3/5

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

Annotations already declare destructiveHint=true, idempotentHint=false and openWorldHint=true, so the safety profile is covered. The description adds the JSON return format and the availability of debug logs, which is genuinely useful since there is no output schema, but it never cautions that arbitrary Apex can mutate Org data.

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

Conciseness3/5

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

Four sentences that repeat the core idea ('Execute Apex code' then 'allows you to run Apex code directly') and close with vague filler about 'other Apex-related tasks.' Front-loading is decent but the padding dilutes it.

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?

For an arbitrary-code-execution tool with no output schema but strong destructive annotations, the description covers return format and debug logging but omits any caution about irreversible Org mutations and says nothing about the parameters. Adequate but with clear gaps.

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 description never mentions the code or targetOrg parameters in text, and reports 0% schema description coverage, so the description does not compensate for the gap. 'Against a specified Salesforce Org' only faintly hints at targetOrg, while the required code argument is not addressed at all.

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?

States a specific verb and resource ('Execute Apex code in a Salesforce Org') and clarifies that execution happens in the target Org context. It is clear on its own but never differentiates itself from the closely related sibling run_apex_tests, which an agent must choose between.

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?

Offers implied usage contexts ('test Apex code snippets, run batch jobs, or perform other Apex-related tasks') but gives no when-not guidance and never names an alternative tool for those cases. The agent is left to infer that this is for ad-hoc/anonymous scripts rather than tests.

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