Newer Version Available

This content describes an older version of this product. View Latest

Step 3 [Optional]: Configure a Rule

​​To help the MCP server function optimally, you can create a rule that guides your AI assistant, such as Agentforce Vibes or Cursor Agent, to call the Metadata API Context MCP tools. An AI rule is a plain-text file like markdown that provides specific instructions, context, or constraints to your AI assistant.

Use this example rule to make sure that the Metadata API Context MCP tools are called to provide AI with additional context when generating metadata XML files. This helps ensure the structural integrity of the metadata XML files generated, and minimize errors during deployment.

1# Rule: Salesforce Metadata Generation
2
3##Description: To guarantee the creation of accurate and deployable Salesforce metadata files, you must use these tools from the `salesforce-api-context` MCP server:
4    - `get_metadata_type_sections`
5    - `get_metadata_type_context`
6    - `get_metadata_type_fields`
7    - `get_metadata_type_fields_properties`
8    - `search_metadata_types`
9
10These tools provide comprehensive contextual information—including complete field definitions, valid values, and constraints—that's essential for correctly determining the required entity shape and creating a valid Salesforce metadata file structure.
11
12## Constraints
131. **One metadata type at a time** - finish one metadata type before starting the next one
143. **One metadata type per tool call** - don't batch metadata types when calling the MCP tools
154. **Child metadata types need their own context** - if adding any child metadata inside a parent metadata's file, treat the child metadata seperately; don't rely on the parent's schema for creating child metadata
16
17## Workflow
18### Step 1: Metadata loop - Execute for each metadata type
19For each metadata type, use these tools from `salesforce-api-context` MCP server to get metadata type context:
20- `get_metadata_type_sections`
21- `get_metadata_type_context`
22- `get_metadata_type_fields`
23- `get_metadata_type_fields_properties`
24- `search_metadata_types`
25
26### Step 2. Verify deployment
27```bash
28sf project deploy start --dry-run -d "force-app/main/default" --target-org <alias> --test-level NoTestRun --wait 10 --json
29```
30On failure: attempt to fix the errors and re-run, retrying up to a maximum of 3 times until it succeeds.
31
32## Anti-patterns
33| Don't | Why | Do |
34|-------|-----|-----|
35| Batch types in calls to MCP tools | Violates constraint | One type per call |

For more details about configuring AI rules, see: