skills/mcp-server-patterns/SKILL.md
Use when building MCP servers for Salesforce Apex or org integration. Node/TypeScript SDK patterns — tools, resources, prompts, Zod validation, stdio vs Streamable HTTP. Do NOT use for Apex class writing or deployment.
npx skillsauth add jiten-singh-shahi/salesforce-claude-code mcp-server-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.development
Update Salesforce platform reference docs with latest release features and deprecation announcements. Use when SessionStart hook warns docs are outdated or a new Salesforce release has shipped. Do NOT use for Apex or LWC development.
development
Use when syncing documentation after Salesforce Apex code changes. Update README, API docs, and deploy metadata references to match the current org codebase.
development
Use when managing context during long Salesforce Apex development sessions. Suggests manual compaction at logical intervals to preserve deploy and org context across phases.
tools
Visualforce development — pages, controllers, extensions, ViewState, JS Remoting, LWC migration. Use when maintaining VF pages, building PDFs, or planning VF-to-LWC migration. Do NOT use for LWC, Aura, or Flow.