By Integration Lead1 min read
Custom MCP Connector for Data Queries
How to configure a Model Context Protocol (MCP) bridge to connect your Salesforce Agentforce agents to external databases and resources in real-time.
Action Inputs (Arguments)
query (String)SQL-compliant search query matching external database schemas.
limit (Integer)Max rows to return (default: 10).
Action Outputs (Return Variables)
recordsJson (String)A serialized JSON array containing query matches.
Model Context Protocol (MCP) in Agentforce
Astro / Agentforce integrates with remote data servers via the Model Context Protocol. This enables your agent to execute queries on external Postgres, Snowflake, or custom databases directly without writing heavy REST middleware inside Salesforce.
sequenceDiagram
Agentforce->>MCP Gateway: POST /tools/query (auth payload)
MCP Gateway->>Database: Execute SQL Query
Database-->>MCP Gateway: Raw Rows
MCP Gateway-->>Agentforce: Serialized JSON Response
Server Endpoint Configuration
Deploy a lightweight Node.js/TypeScript MCP service. Here is the tool schema definition:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server({
name: "agentforce-db-bridge",
version: "1.0.0"
}, {
capabilities: {
tools: {}
}
});
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "query_database",
description: "Executes queries against target external relational data warehouse.",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Target query" },
limit: { type: "number", description: "Row limit" }
},
required: ["query"]
}
}
]
};
});
[!WARNING] Ensure all incoming queries are sanitized on the MCP server side to prevent SQL injection vulnerability issues.
Frequently Asked Questions
What is MCP?
Model Context Protocol is an open standard designed to allow AI models to fetch data and run tools on remote servers safely.