run_soql_query
Execute SOQL queries to retrieve Salesforce data efficiently using the MCP Salesforce Connector, enabling direct interaction with Salesforce records for streamlined data access.
Instructions
Executes a SOQL query against Salesforce
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SOQL query to execute |
Implementation Reference
- src/salesforce/server.py:317-328 (handler)The handler logic within the call_tool function that parses the query argument, executes it using the Salesforce client's query_all method, and returns the results as formatted JSON text content.if name == "run_soql_query": query = arguments.get("query") if not query: raise ValueError("Missing 'query' argument") results = sf_client.sf.query_all(query) return [ types.TextContent( type="text", text=f"SOQL Query Results (JSON):\n{json.dumps(results, indent=2)}", ) ]
- src/salesforce/server.py:107-120 (registration)The registration of the 'run_soql_query' tool in the list_tools handler, including its name, description, and input schema requiring a 'query' string.types.Tool( name="run_soql_query", description="Executes a SOQL query against Salesforce", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The SOQL query to execute", }, }, "required": ["query"], }, ),
- src/salesforce/server.py:111-119 (schema)The JSON schema definition for the input arguments of the 'run_soql_query' tool, specifying an object with a required 'query' string property."type": "object", "properties": { "query": { "type": "string", "description": "The SOQL query to execute", }, }, "required": ["query"], },