From Raw SOQL to a Governed Semantic Layer: Four Ways I Connected Claude to Salesforce
Four ways I connected Claude to Salesforce with MCP, from a local server to Apex tools, and why agents should get business answers, not raw SOQL.
At Amplitude, the author experimented with four different ways to connect Claude to Salesforce. The goal was to provide Claude with live CRM data to answer sales-related questions without exposing sensitive information to unauthorized users. The four approaches were:
1. A local server for Claude Desktop: This server was a small Python application that Claude Desktop ran as a subprocess. It used a local .env file for credentials and called Salesforce through the simple-salesforce library. The server had four tools and initially had a mistake in its query creation using Python f-strings. To prevent writes, the server included validators, an allowlist, a wrapper around the Salesforce client, and an empty tool list. The lookup_records tool mapped common terms to tuned SOQL queries.
2. The same server in Claude Code: This approach used the same server.py with no changes but registered it with Claude Code instead of Claude Desktop. The author used the MCP Inspector to test the write guard and see what information Claude would receive.
3. A remote server on Cloud Run: When more people started using the local server, it became clear that the setup had limitations. The author moved the server to Google Cloud Run as a FastAPI and FastMCP app. Users added a URL under Settings, Connectors in claude.ai, signed in with their Salesforce account, and the server acted as a small OAuth server in front of Salesforce. Claude found its metadata at /.well-known/oauth-authorization-server and received access and refresh tokens with Salesforce session information.
4. Salesforce-hosted MCP and a semantic layer: The author found that the previous approaches gave Claude a raw query tool, which could result in inconsistent SOQL and poor conclusions. Salesforce now offers prebuilt MCP servers, such as sobject-reads for general queries. The author began treating each tool as a defined business question rather than a raw data window.
A tool like get_pipeline_intelligence invoked an Apex method that applied the company's risk rules and returned the result without exposing raw fields or allowing any data modifications.
Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.