Guides building MCP servers for Salesforce Apex/org integration using Node/TypeScript SDK patterns: tools, resources, prompts, Zod validation, stdio vs Streamable HTTP transports.
npx claudepluginhub jiten-singh-shahi/salesforce-claude-code --plugin salesforce-claude-codeThis skill uses the workspace's default tool permissions.
The Model Context Protocol (MCP) lets AI assistants call tools, read resources, and use prompts from your server. Use this skill when building or maintaining MCP servers, or integrating with the official Salesforce MCP server. The SDK API evolves; check Context7 (query-docs for "MCP") or the official MCP documentation for current method names and signatures.
Builds MCP servers using Node/TypeScript SDK: register tools/resources/prompts, Zod schemas, stdio vs Streamable HTTP transports. For new implementations, upgrades, debugging.
Builds MCP servers with Node/TypeScript SDK: register tools/resources/prompts, Zod validation, stdio/Streamable HTTP transports, debugging.
Provides best practices for production MCP servers with TypeScript SDK: spec 2025-11-25, v1.28+/v2, Streamable HTTP/stdio transports, tool design, errors, security, performance, extensions, MCP Apps, Registry.
Share bugs, ideas, or general feedback.
The Model Context Protocol (MCP) lets AI assistants call tools, read resources, and use prompts from your server. Use this skill when building or maintaining MCP servers, or integrating with the official Salesforce MCP server. The SDK API evolves; check Context7 (query-docs for "MCP") or the official MCP documentation for current method names and signatures.
Use when: implementing a new MCP server, adding tools or resources, choosing stdio vs HTTP, integrating with @salesforce/mcp, upgrading the SDK, or debugging MCP registration and transport issues.
registerTool() or tool() depending on SDK version.registerResource() or resource(). Handlers typically receive a uri argument.registerPrompt() or equivalent.The Node/TypeScript SDK may expose tool() / resource() or registerTool() / registerResource(); the official SDK has changed over time. Always verify against the current MCP docs or Context7.
| Transport | Use When | Examples |
|---|---|---|
| stdio | Local client, same machine, Claude Desktop/Code | Development, local testing |
| Streamable HTTP | Remote clients, cloud deployment, multi-user | Cursor, production APIs |
| Legacy HTTP/SSE | Backward compatibility only | Older clients |
Keep server logic (tools + resources) independent of transport so you can plug in stdio or HTTP in the entrypoint.
npm install @modelcontextprotocol/sdk zod
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "my-server", version: "1.0.0" });
// Register a tool
server.tool(
"search-records",
"Search Salesforce records by keyword",
{ query: z.string(), objectType: z.string().default("Account") },
async ({ query, objectType }) => {
// Your implementation here
return { content: [{ type: "text", text: JSON.stringify(results) }] };
}
);
// Connect via stdio
const transport = new StdioServerTransport();
await server.connect(transport);
Note: Registration API varies by SDK version — some versions use positional args
server.tool(name, description, schema, handler), others use object syntax. Check the official MCP docs or Context7 for current@modelcontextprotocol/sdksignatures.
Use Zod (or the SDK's preferred schema format) for input validation.
MCP config is auto-installed by npx scc-universal install (.mcp.json for Claude Code, .cursor/mcp.json for Cursor). The official @salesforce/mcp server provides these toolsets:
| Toolset | What It Does |
|---|---|
orgs | Org management, auth, user info |
metadata | Deploy, retrieve, list metadata types |
data | SOQL queries, record CRUD, bulk operations |
users | User management, permission sets |
testing | Run Apex tests, get coverage results |
code-analysis | PMD/scanner, code quality checks |
lwc-experts | LWC development guidance |
devops | Source tracking, scratch org operations |
{
"mcpServers": {
"salesforce": {
"command": "npx",
"args": ["-y", "@salesforce/mcp@latest"],
"env": {
"SF_ORG_ALIAS": "my-org"
}
}
}
}
When @salesforce/mcp doesn't cover your use case (org-specific business logic, custom validation rules, internal APIs), build a custom MCP server:
import { execFileSync } from "child_process";
server.tool(
"validate-account-hierarchy",
"Check account hierarchy depth and circular references",
{ accountId: z.string().regex(/^[a-zA-Z0-9]{15,18}$/, "Must be a valid 15- or 18-char Salesforce ID") },
async ({ accountId }) => {
const result = execFileSync("sf", [
"data", "query",
"--sobject", "Account",
"--where", `Id='${accountId}'`,
"--fields", "Id,ParentId",
"--json"
], { timeout: 30000, encoding: "utf-8" });
return { content: [{ type: "text", text: result }] };
}
);
execSync/exec calls (e.g., { timeout: 30000 }) and on HTTP requests./^[a-zA-Z0-9]{15,18}$/) before passing to SF CLI.@modelcontextprotocol/sdk (npm). Use Context7 with library name "MCP" for current registration and transport patterns.modelcontextprotocol/go-sdk).@salesforce/mcp (npm) — official Salesforce MCP server.