Your Org as an AI Tool: The Salesforce DX MCP Server

Let your AI assistant query records, deploy metadata and run tests against your org — safely. A hands-on AI Projects Lab build.

The scenario

You're mid-debug: a test class fails after a pull. The old loop — run tests in terminal, read the stack trace, open the class, query some records to check data, fix, redeploy — is five tools and twenty context switches. With the Salesforce DX MCP server, your AI assistant does that loop with you: "run ContactTriggerTest, show me the failure, and query the contacts it created" becomes one instruction.

For beginners: MCP (Model Context Protocol) is a standard that lets AI assistants call tools. The DX MCP server, open-sourced by Salesforce as @salesforce/mcp, exposes your familiar SFDX capabilities — org queries, deploys, test runs — as tools any MCP-capable assistant can use (Agentforce Vibes, Claude, Cursor, VS Code agent mode).

Setup in two minutes

Requirements: Node.js 18+, Salesforce CLI authenticated to at least one org.

// MCP client config (e.g. .mcp.json in your project,
// or claude_desktop_config.json / VS Code settings)
{
  "mcpServers": {
    "salesforce": {
      "command": "npx",
      "args": [
        "-y", "@salesforce/mcp",
        "--orgs", "DEFAULT_TARGET_ORG",
        "--toolsets", "all"
      ]
    }
  }
}
Safety model: the server runs locally, reuses your existing CLI auth (no new credentials), and only exposes the orgs and toolsets you pass. Point it at scratch orgs and sandboxes — not production — while you build the habit.

The real workflow: agentic test-and-fix

  1. You: "Run the Apex tests for ContactTriggerTest and summarize any failures."
  2. Assistant → MCP: invokes the test tool against your scratch org, reads results.
  3. Assistant: "2 failures — both null pointer on Account.OwnerId. The test data factory doesn't set an owner. Want me to look at the factory class?"
  4. You: "Yes, and check whether any org data actually has null owners."
  5. Assistant → MCP: runs a SOQL query tool, confirms the edge case is real, proposes the fix, and re-runs the tests after you apply it.

The difference from copy-pasting into a chatbot: the assistant is working against your real org state, not its imagination.

Where this fits in the bigger picture

Sources: Introducing MCP Support Across Salesforce · @salesforce/mcp on npm