# salesforcecli/mcp architecture

> Architecture diagram of the GitHub repository salesforcecli/mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/salesforcecli/mcp
- Repository: https://github.com/salesforcecli/mcp

## Overview

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: [`packages/mcp/src/registry.ts`](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/registry.ts) (Tool Registry), [`packages/mcp-provider-api/src/index.ts`](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-api/src/index.ts) (Provider API), [`packages/mcp/src/sf-mcp-server.ts`](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/sf-mcp-server.ts) (MCP Server), [`.github/workflows/test.yml`](https://github.com/salesforcecli/mcp/blob/main/.github/workflows/test.yml) (CI Workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["MCP Host"]
  node_mcp_bin_run["Server CLI<br/>entrypoint<br/>[run.js]"]
  node_mcp_server["MCP Server<br/>runtime<br/>[sf-mcp-server.ts]"]
  node_mcp_registry["Tool Registry<br/>orchestration<br/>[registry.ts]"]
  node_mcp_services["Host Services<br/>platform services<br/>[services.ts]"]
  node_mcp_tooling["Tool Controls<br/>tooling<br/>[enable_tools.ts]"]
end

subgraph group_contract["Provider Contract"]
  node_provider_api["Provider API<br/>shared contract<br/>[index.ts]"]
end

subgraph group_providers["Tool Providers"]
  node_dx_core["DX Core<br/>salesforce dx provider<br/>[index.ts]"]
  node_dx_tools["DX Tools<br/>tool set<br/>[run_soql_query.ts]"]
  node_devops_provider["DevOps Provider<br/>devops orchestration<br/>[provider.ts]"]
  node_devops_tools["DevOps Tools<br/>workflow tools"]
  node_mobile_web["Mobile Web<br/>mobile guidance provider<br/>[provider.ts]"]
  node_metadata_enrich["Metadata Enrichment<br/>metadata provider<br/>[provider.ts]"]
  node_example_provider["Example Provider<br/>sample provider<br/>[provider.ts]"]
end

subgraph group_analysis["Analysis Providers"]
  node_code_analyzer["Code Analyzer<br/>analysis provider<br/>[provider.ts]"]
  node_code_pipeline["Analysis Pipeline<br/>AST/PMD pipeline"]
  node_scale_products["Scale Products<br/>apex analysis provider<br/>[provider.ts]"]
  node_scale_pipeline["Detection Pipeline<br/>detectors/recommenders"]
end

subgraph group_clients["Clients & QA"]
  node_test_client["Test Client<br/>mcp client helper<br/>[index.ts]"]
  node_ci_workflows["CI Workflows<br/>automation<br/>[test.yml]"]
end

node_mcp_bin_run -->|"starts"| node_mcp_server
node_mcp_server -->|"routes tools"| node_mcp_registry
node_mcp_server -->|"uses"| node_mcp_services
node_mcp_registry -->|"implements contract"| node_provider_api
node_mcp_tooling -->|"controls"| node_mcp_registry
node_mcp_registry -->|"loads"| node_dx_core
node_mcp_registry -->|"loads"| node_devops_provider
node_mcp_registry -->|"loads"| node_code_analyzer
node_mcp_registry -->|"loads"| node_scale_products
node_mcp_registry -->|"loads"| node_mobile_web
node_mcp_registry -->|"loads"| node_metadata_enrich
node_mcp_registry -->|"loads"| node_example_provider
node_dx_core -->|"exposes"| node_dx_tools
node_devops_provider -->|"exposes"| node_devops_tools
node_code_analyzer -->|"delegates"| node_code_pipeline
node_scale_products -->|"delegates"| node_scale_pipeline
node_code_analyzer -->|"depends on"| node_provider_api
node_devops_provider -->|"depends on"| node_provider_api
node_dx_core -->|"depends on"| node_provider_api
node_mobile_web -->|"depends on"| node_provider_api
node_metadata_enrich -->|"depends on"| node_provider_api
node_scale_products -->|"depends on"| node_provider_api
node_example_provider -->|"depends on"| node_provider_api
node_test_client -.->|"exercises"| node_mcp_server
node_ci_workflows -.->|"verifies"| node_mcp_server
node_ci_workflows -.->|"verifies"| node_dx_core
node_ci_workflows -.->|"verifies"| node_code_analyzer
node_ci_workflows -.->|"verifies"| node_devops_provider

click node_mcp_bin_run "https://github.com/salesforcecli/mcp/blob/main/packages/mcp/bin/run.js"
click node_mcp_server "https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/sf-mcp-server.ts"
click node_mcp_registry "https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/registry.ts"
click node_mcp_services "https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/services.ts"
click node_mcp_tooling "https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/tools/enable_tools.ts"
click node_provider_api "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-api/src/index.ts"
click node_dx_core "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-dx-core/src/index.ts"
click node_dx_tools "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-dx-core/src/tools/run_soql_query.ts"
click node_devops_provider "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-devops/src/provider.ts"
click node_devops_tools "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-devops/src/tools/sfDevopsCheckoutWorkItem.ts"
click node_code_analyzer "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-code-analyzer/src/provider.ts"
click node_code_pipeline "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-code-analyzer/src/ast/ast-node-pipeline.ts"
click node_scale_products "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-scale-products/src/provider.ts"
click node_scale_pipeline "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-scale-products/src/antipatterns/antipattern-registry.ts"
click node_mobile_web "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-mobile-web/src/provider.ts"
click node_metadata_enrich "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-metadata-enrichment/src/provider.ts"
click node_example_provider "https://github.com/salesforcecli/mcp/blob/main/packages/EXAMPLE-MCP-PROVIDER/src/provider.ts"
click node_test_client "https://github.com/salesforcecli/mcp/blob/main/packages/mcp-test-client/src/index.ts"
click node_ci_workflows "https://github.com/salesforcecli/mcp/blob/main/.github/workflows/test.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mcp_bin_run,node_mcp_server,node_mcp_registry,node_mcp_services,node_mcp_tooling toneBlue
class node_provider_api toneAmber
class node_dx_core,node_dx_tools,node_devops_provider,node_devops_tools,node_mobile_web,node_metadata_enrich,node_example_provider toneMint
class node_code_analyzer,node_code_pipeline,node_scale_products,node_scale_pipeline toneRose
class node_test_client,node_ci_workflows toneIndigo
```

## Components

### MCP Host

Runtime entrypoint, protocol handling, tool registration, policy, and execution services.

- [Server CLI](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/bin/run.js): entrypoint · Process launchers for running and developing the MCP server. · `packages/mcp/bin/run.js`
- [MCP Server](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/sf-mcp-server.ts): runtime · Core MCP server process and protocol surface. · `packages/mcp/src/sf-mcp-server.ts`
- [Tool Registry](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/registry.ts): orchestration · Registers providers, resolves enabled tools, and coordinates selection. · `packages/mcp/src/registry.ts`
- [Host Services](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/services.ts): platform services · Shared host services for auth, caching, rate limiting, telemetry, and helper utilities. · `packages/mcp/src/services.ts`
- [Tool Controls](https://github.com/salesforcecli/mcp/blob/main/packages/mcp/src/tools/enable_tools.ts): tooling · 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](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-api/src/index.ts): shared contract · 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](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-dx-core/src/index.ts): salesforce dx provider · Primary Salesforce DX integration provider for org, metadata, query, and test operations. · `packages/mcp-provider-dx-core/src/index.ts`
- [DX Tools](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-dx-core/src/tools/run_soql_query.ts): tool set · 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](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-devops/src/provider.ts): devops orchestration · DevOps Center workflows for work items, commits, PRs, conflicts, and promotions. · `packages/mcp-provider-devops/src/provider.ts`
- [DevOps Tools](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-devops/src/tools/sfDevopsCheckoutWorkItem.ts): workflow tools · Tool wrappers around checkout, commit, conflict resolution, listing, and promotion flows. · `packages/mcp-provider-devops/src/tools/sfDevopsCheckoutWorkItem.ts`
- [Mobile Web](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-mobile-web/src/provider.ts): mobile guidance provider · Mobile LWC native capability, offline analysis, and guidance tooling. · `packages/mcp-provider-mobile-web/src/provider.ts`
- [Metadata Enrichment](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-metadata-enrichment/src/provider.ts): metadata provider · Single-purpose metadata enrichment provider. · `packages/mcp-provider-metadata-enrichment/src/provider.ts`
- [Example Provider](https://github.com/salesforcecli/mcp/blob/main/packages/EXAMPLE-MCP-PROVIDER/src/provider.ts): sample 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](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-code-analyzer/src/provider.ts): analysis provider · Salesforce Code Analyzer and PMD-backed analysis provider with AST and rule tooling. · `packages/mcp-provider-code-analyzer/src/provider.ts`
- [Analysis Pipeline](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-code-analyzer/src/ast/ast-node-pipeline.ts): AST/PMD pipeline · AST extraction, engine adapters, strategies, telemetry, and query/result actions. · `packages/mcp-provider-code-analyzer/src/ast/ast-node-pipeline.ts`
- [Scale Products](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-scale-products/src/provider.ts): apex analysis provider · Apex anti-pattern detection and remediation guidance provider. · `packages/mcp-provider-scale-products/src/provider.ts`
- [Detection Pipeline](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-provider-scale-products/src/antipatterns/antipattern-registry.ts): detectors/recommenders · 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](https://github.com/salesforcecli/mcp/blob/main/packages/mcp-test-client/src/index.ts): mcp client helper · Transport and utility library for exercising MCP server behavior. · `packages/mcp-test-client/src/index.ts`
- [CI Workflows](https://github.com/salesforcecli/mcp/blob/main/.github/workflows/test.yml): automation · GitHub Actions for tests, release, publish, validation, and notifications. · `.github/workflows/test.yml`

## Connections

- 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.
