How salesforcecli/mcp works
1. Repository shape
This is a TypeScript monorepo centered on the Salesforce DX MCP server. The root packages/mcp package is the runtime entrypoint, while the packages/mcp-provider-* packages are domain-specific tool providers that plug into the server.
2. Top-level architecture
The system is organized as an MCP host plus many tool domains. The host exposes MCP capabilities to an external client, then loads and registers tool implementations from provider packages based on configured toolsets, individual tool flags, and org access settings.
3. Primary runtime path
An MCP client sends a tool request to the server. The server resolves whether the tool is enabled, selects the appropriate provider, applies auth and policy checks, then invokes the provider’s implementation. The result is returned through the MCP protocol, often with telemetry and error handling wrapped around the call.
4. packages/mcp as the server core
This package contains the CLI/server process (bin/run.js, bin/dev.js), tool registry, service wiring, telemetry, auth helpers, caching, and rate limiting. It also contains the logic for dynamic tool loading and tool enablement, which is what turns the monorepo’s many providers into a single configurable server.
5. Shared provider contract
packages/mcp-provider-api defines the cross-package interface for provider authors: tool metadata, prompts/resources/services, and shared types/enums. This is the contract boundary between the core server and all provider packages.
6. DX/core Salesforce operations
packages/mcp-provider-dx-core is the main Salesforce DX integration layer. Its tools cover org operations, metadata deployment/retrieval, SOQL querying, scratch org management, permission assignment, testing, and resumable operations. This package is the closest to the actual Salesforce CLI/org execution boundary.
7. DevOps automation domain
packages/mcp-provider-devops handles DevOps Center workflows such as work item checkout, commit, PR creation, conflict detection/resolution, pipeline queries, and promotion. It has substantial shared utilities for auth, git/path handling, org type detection, pipeline helpers, and SFDX service integration, which suggests this provider is a multi-step orchestration layer rather than a thin wrapper.
8. Static code analysis domain
packages/mcp-provider-code-analyzer is a self-contained analysis subsystem built around Salesforce Code Analyzer and PMD. It includes action modules, AST extraction and XML generation, engine adapters/strategies, rule metadata, telemetry listeners, and templates for rulesets/configuration. Its data flow is: source code or workspace input -> AST/engine processing -> analyzer result/query tools -> filtered findings or custom rule generation.
9. Apex performance and anti-pattern analysis
packages/mcp-provider-scale-products is another analysis pipeline, but focused on Apex anti-pattern detection and remediation guidance. It has detectors, runtime enrichers, recommenders, fix-instruction resources, telemetry services, and AST utilities. The architecture separates detection from recommendation, and enriches findings with runtime/severity data before surfacing them through the scan-apex-antipatterns tool.
10. Mobile, metadata enrichment, and example providers
packages/mcp-provider-mobile-web packages mobile-specific LWC guidance and native capability tooling, backed by schema/resource declarations and generated type definitions. packages/mcp-provider-metadata-enrichment is a single-purpose metadata enrichment provider. packages/EXAMPLE-MCP-PROVIDER demonstrates the provider pattern with a minimal tool and tests, acting as a reference implementation rather than a production subsystem.
11. Clients, tests, and quality gates
packages/mcp-test-client is a helper library for exercising MCP transport behavior. Tests are split per package, with Vitest used in most provider packages and Mocha/NYC in packages/mcp. GitHub Actions workflows drive unit, E2E, publishing, release, and validation pipelines, so the repo is structured for frequent package-level releases and CI-based verification.
12. Key architectural boundaries
The most important boundary is between the MCP host and provider packages: the host owns protocol, registration, selection, and policy, while providers own domain logic and external integrations. A second boundary exists between “tool orchestration” and “execution engines” inside providers, especially in code analysis and scale-products, where AST/PMD/detector pipelines are isolated from user-facing tool wrappers.
Main entry points: registry.ts Tool Registry · index.ts Provider API · sf-mcp-server.ts MCP Server · test.yml CI Workflows
Components 19
MCP Host
Runtime entrypoint, protocol handling, tool registration, policy, and execution services.
- Server CLI · Process launchers for running and developing the MCP server.
packages/mcp/bin/run.js - MCP Server · Core MCP server process and protocol surface.
packages/mcp/src/sf-mcp-server.ts - Tool Registry · Registers providers, resolves enabled tools, and coordinates selection.
packages/mcp/src/registry.ts - Host Services · Shared host services for auth, caching, rate limiting, telemetry, and helper utilities.
packages/mcp/src/services.ts - Tool Controls · Host-side commands for listing and enabling tools.
packages/mcp/src/tools/enable_tools.ts
Provider Contract
Shared interfaces used by the host and all provider packages.
- Provider API · Cross-package provider interfaces, metadata, prompts, resources, services, tools, and types.
packages/mcp-provider-api/src/index.ts
Tool Providers
Domain-specific MCP providers that implement tools and external integrations.
- DX Core · Primary Salesforce DX integration provider for org, metadata, query, and test operations.
packages/mcp-provider-dx-core/src/index.ts - DX Tools · Org, metadata, SOQL, scratch org, and test tools exposed by DX Core.
packages/mcp-provider-dx-core/src/tools/run_soql_query.ts - DevOps Provider · DevOps Center workflows for work items, commits, PRs, conflicts, and promotions.
packages/mcp-provider-devops/src/provider.ts - DevOps Tools · Tool wrappers around checkout, commit, conflict resolution, listing, and promotion flows.
packages/mcp-provider-devops/src/tools/sfDevopsCheckoutWorkItem.ts - Mobile Web · Mobile LWC native capability, offline analysis, and guidance tooling.
packages/mcp-provider-mobile-web/src/provider.ts - Metadata Enrichment · Single-purpose metadata enrichment provider.
packages/mcp-provider-metadata-enrichment/src/provider.ts - Example Provider · Minimal reference implementation of the provider pattern.
packages/EXAMPLE-MCP-PROVIDER/src/provider.ts
Analysis Providers
Providers that perform code or metadata analysis pipelines.
- Code Analyzer · Salesforce Code Analyzer and PMD-backed analysis provider with AST and rule tooling.
packages/mcp-provider-code-analyzer/src/provider.ts - Analysis Pipeline · AST extraction, engine adapters, strategies, telemetry, and query/result actions.
packages/mcp-provider-code-analyzer/src/ast/ast-node-pipeline.ts - Scale Products · Apex anti-pattern detection and remediation guidance provider.
packages/mcp-provider-scale-products/src/provider.ts - Detection Pipeline · Detectors, runtime enrichers, severity calculation, and fix recommendations.
packages/mcp-provider-scale-products/src/antipatterns/antipattern-registry.ts
Clients & QA
Test client, package tests, and repository quality gates.
- Test Client · Transport and utility library for exercising MCP server behavior.
packages/mcp-test-client/src/index.ts - CI Workflows · GitHub Actions for tests, release, publish, validation, and notifications.
.github/workflows/test.yml
Connections 28
- Server CLI → MCP Server: starts · Launches the server process.
- MCP Server → Tool Registry: routes tools · Delegates tool lookup and provider selection.
- MCP Server → Host Services: uses · Wraps calls with host services such as auth, caching, telemetry, and rate limiting.
- Tool Registry → Provider API: implements contract · Uses the shared provider interface to load packages consistently.
- Tool Controls → Tool Registry: controls · Enables and lists tools through the registry.
- Tool Registry → DX Core: loads · Registers the DX Core provider when enabled.
- Tool Registry → DevOps Provider: loads · Registers the DevOps provider when enabled.
- Tool Registry → Code Analyzer: loads · Registers the code analysis provider when enabled.
- Tool Registry → Scale Products: loads · Registers the Apex analysis provider when enabled.
- Tool Registry → Mobile Web: loads · Registers the mobile/web provider when enabled.
- Tool Registry → Metadata Enrichment: loads · Registers the metadata enrichment provider when enabled.
- Tool Registry → Example Provider: loads · Registers the example provider for reference/testing.
- DX Core → DX Tools: exposes · Publishes org, metadata, query, and test tools.
- DevOps Provider → DevOps Tools: exposes · Publishes DevOps workflow tools.
- Code Analyzer → Analysis Pipeline: delegates · Routes requests into AST and PMD analysis stages.
- Scale Products → Detection Pipeline: delegates · Routes scans through detector, enricher, and recommender stages.
- Code Analyzer → Provider API: depends on · Implements the shared provider contract.
- DevOps Provider → Provider API: depends on · Implements the shared provider contract.
- DX Core → Provider API: depends on · Implements the shared provider contract.
- Mobile Web → Provider API: depends on · Implements the shared provider contract.
- Metadata Enrichment → Provider API: depends on · Implements the shared provider contract.
- Scale Products → Provider API: depends on · Implements the shared provider contract.
- Example Provider → Provider API: depends on · Implements the shared provider contract.
- Test Client → MCP Server: exercises · Drives server transport behavior in tests and examples.
- CI Workflows → MCP Server: verifies · Builds and tests the host package in CI.
- CI Workflows → DX Core: verifies · Runs provider package validation and e2e tests.
- CI Workflows → Code Analyzer: verifies · Runs provider package validation and e2e tests.
- CI Workflows → DevOps Provider: verifies · Runs provider package validation and e2e tests.