Skip to main content
Glama
semwalajay83-sem

salesforce-metadata-mcp

Create Apex Class

sf_create_apex_class
Idempotent

Create and deploy an Apex class to Salesforce via Metadata API. Accepts full source code, supports service, batch, schedulable, queueable, and test classes, including Agentforce actions with @InvocableMethod.

Instructions

Creates and deploys an Apex class to the Salesforce org using the Metadata API. Accepts the full Apex source code including the class declaration. Use for any type of Apex class: service classes, controllers, batch classes, schedulable classes, queueable classes, test utilities, etc. IMPORTANT — If this class will be used as an Agentforce agent action: it MUST contain a public static method annotated with @InvocableMethod. Classes without @InvocableMethod cannot be invoked by agents and will silently fail at runtime. Example minimum structure: public class MyClass { @InvocableMethod(label='Do Thing' description='Does the thing') public static List doThing(List input) { ... } }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
classBodyYesFull Apex class source code including the class declaration
classNameYesApex class name, e.g. 'AccountService'
apiVersionNoAPI version for this class, e.g. '66.0'66.0
Behavior4/5

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

The description discloses a critical behavioral trait: classes used as Agentforce actions must have an @InvocableMethod, otherwise they 'will silently fail at runtime.' It also specifies that deployment is via the Metadata API, adding context beyond annotations. Annotations already indicate idempotency, and there is no contradiction.

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 moderately long but every sentence earns its place: purpose, use cases, a critical IMPORTANT warning, and an example. It is well-structured with a clear flag and code block, making it easy to scan. Slightly verbose but justified by the important Agentforce guidance.

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?

The description covers creation and deployment, but does not explain what the tool returns on success or failure, nor does it mention whether it overwrites an existing class. Given the absence of an output schema, these gaps are noticeable. The Agentforce example adds depth, but deployment outcomes and side effects are left unspecified.

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 baseline is 3. The description adds value by providing a concrete example of a valid classBody for Agentforce actions, including @InvocableMethod details, which clarifies the expected source code format beyond the schema's generic 'Full Apex class source code including the class declaration.' No additional detail for className or apiVersion, but the example is meaningful.

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 description clearly states the tool's function: 'Creates and deploys an Apex class to the Salesforce org using the Metadata API.' It also distinguishes from siblings by explicitly enumerating supported class types (service, controller, batch, etc.) and noting 'any type of Apex class', which separates it from tools like sf_create_apex_trigger or sf_create_apex_email_service.

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

Usage Guidelines4/5

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

Provides explicit when-to-use guidance: 'Use for any type of Apex class: service classes, controllers, batch classes, ...' and includes a special case for Agentforce agent actions. However, it does not mention alternatives or exclusions (e.g., when to use sf_create_apex_test_class or sf_create_apex_trigger instead), so it lacks explicit when-not-to-use context.

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/semwalajay83-sem/salesforce-metadata-mcp'

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