---
schema_version: "1"
id: fa36fac976967ad1aba4bd5d10034967a37886c3f51f4de20acd8b37b01dd4e4
title: "Step 3 (Optional): Configure a Rule"
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_mcp_configure_rule.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_mcp_configure_rule.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: b03c71861ac1f76d0365d851d39fc2224b4fad337e905d1f916753045bfcd9a0
description: ​​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.
---
# 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.

\# Rule: Salesforce Metadata Generation

##Description: To guarantee the creation of accurate and deployable Salesforce metadata files, you must use these tools from the \`salesforce-api-context\` MCP server:
    - \`get\_metadata\_type\_sections\`
    - \`get\_metadata\_type\_context\`
    - \`get\_metadata\_type\_fields\`
    - \`get\_metadata\_type\_fields\_properties\`
    - \`search\_metadata\_types\`

These 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.

## Constraints
1. \*\*One metadata type at a time\*\* - finish one metadata type before starting the next one
3. \*\*One metadata type per tool call\*\* - don't batch metadata types when calling the MCP tools
4. \*\*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

## Workflow
### Step 1: Metadata loop - Execute for each metadata type
For each metadata type, use these tools from \`salesforce-api-context\` MCP server to get metadata type context:
- \`get\_metadata\_type\_sections\`
- \`get\_metadata\_type\_context\`
- \`get\_metadata\_type\_fields\`
- \`get\_metadata\_type\_fields\_properties\`
- \`search\_metadata\_types\`

### Step 2. Verify deployment
\`\`\`bash
sf project deploy start --dry-run -d "force-app/main/default" --target-org <alias> --test-level NoTestRun --wait 10 --json
\`\`\`
On failure: attempt to fix the errors and re-run, retrying up to a maximum of 3 times until it succeeds.

## Anti-patterns
| Don't | Why | Do |
|-------|-----|-----|
| Batch types in calls to MCP tools | Violates constraint | One type per call |

For more details about configuring AI rules, see:

- Agentforce Vibes Extension: [Agentforce Rules](https://developer.salesforce.com/docs/platform/einstein-for-devs/guide/devagent-rules.html)
- Cursor Docs: [Rules](https://cursor.com/docs/context/rules)