Skip to content

kranthinb/salesforce-code-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

salesforce-code-context

A local-first MCP server that gives AI coding agents deep understanding of Salesforce codebases. Index your SFDX, Copado, or MDAPI project once — then search Apex classes, LWC components, Flows, triggers, and more using natural language.

Zero external dependencies. No Docker, no cloud database, no API keys. Everything runs locally in SQLite.

Quick Start

Add to Claude Code

claude mcp add sfcontext -- npx @sfcontext/mcp-server

Or install from source

git clone https://github.com/kranthinb/salesforce-code-context.git
cd salesforce-code-context
npm install && npm run build

claude mcp add sfcontext -- node /path/to/salesforce-code-context/packages/mcp-server/dist/index.js

Use it

Open your Salesforce project in Claude Code and ask:

"Index my codebase at /path/to/my-sfdx-project"
"Search for account trigger handler"
"Find the LWC component that calls AccountService"
"What depends on the Account object?"

MCP Tools

Tool Description
index_codebase Index a Salesforce project. Auto-detects SFDX/Copado/MDAPI. Incremental — only re-processes changed files.
search_code Search indexed code with natural language. Returns source code snippets with file paths and line numbers.
clear_index Remove the index for a project.
get_indexing_status Check if a project is indexed and whether the index is up-to-date.

What Gets Parsed

Metadata Type What's Extracted
Apex Classes Methods, properties, annotations, sharing model, inheritance, interfaces, SOQL references
Apex Triggers SObject, DML events, class references
LWC @api properties, @wire adapters, Apex imports, child components (from JS + HTML)
Aura Attributes, events, controller references, child components
Flows Process type, trigger object, elements, Apex actions, subflows, variables
Custom Objects/Fields Field types, lookups, validation rules, record types
Permission Sets/Profiles Object permissions, field permissions, class access, tab settings

Architecture

salesforce-code-context/
├── packages/
│   ├── core/                    # Core engine (no server dependencies)
│   │   ├── src/
│   │   │   ├── detector/        # SFDX / Copado / MDAPI project detection
│   │   │   ├── parsers/         # 6 Salesforce metadata parsers
│   │   │   ├── indexer/         # Chunking pipeline
│   │   │   ├── embeddings/      # Embedding providers (OpenAI, NoOp)
│   │   │   ├── storage/         # SQLite FTS5 (local) + ChromaDB (optional)
│   │   │   ├── graph/           # SQLite dependency graph + traversal
│   │   │   └── sync/            # Merkle tree file sync + snapshots
│   │   └── package.json
│   └── mcp-server/              # MCP server (stdio transport)
│       ├── src/
│       │   ├── index.ts         # Server entry point
│       │   ├── config.ts        # Auto-configured from env vars
│       │   └── handlers.ts      # Tool implementations
│       └── package.json
├── turbo.json
└── package.json

How It Works

  1. Detect — Scans for sfdx-project.json, .copado, or package.xml to identify the project type and source directories
  2. Parse — Reads each Salesforce source file and extracts structured metadata (classes, methods, fields, references, dependencies)
  3. Chunk — Splits parsed metadata into searchable units with actual source code attached (class-level, method-level, field-level)
  4. Index — Stores chunks in SQLite with FTS5 full-text indexing for fast keyword search
  5. Sync — Tracks file changes via SHA-256 Merkle hashing so re-indexing only processes changed files
  6. Search — Matches natural language queries against indexed chunks and returns ranked source code results

Dependency Graph

The core engine also builds a full dependency graph in SQLite:

  • Impact analysis — "What depends on AccountService?" → returns triggers, LWC components, Flows, permission sets that reference it
  • Dependency chain — "What does myComponent depend on?" → returns Apex classes, objects, child components
  • Cross-cutting queries — "Show all trigger-to-object relationships"

Configuration

The MCP server works with zero configuration. For advanced setups:

Env Variable Default Description
SFCONTEXT_DB_PATH ~/.sfcontext/search.db Custom SQLite database path
CHROMA_URL Enable ChromaDB backend (e.g., http://localhost:8000)
OPENAI_API_KEY Enable OpenAI embeddings for semantic vector search
EMBEDDING_MODEL text-embedding-3-small OpenAI embedding model
COLLECTION_NAME sf-context ChromaDB collection name

Local mode (default): SQLite FTS5 full-text search. No API keys needed.

Cloud mode (opt-in): Set CHROMA_URL + OPENAI_API_KEY to enable vector-based semantic search via ChromaDB + OpenAI embeddings.

Using as a Library

You can use the core engine directly in your own tools:

import {
  detectProject,
  parseFile,
  IndexingPipeline,
  NoOpEmbedder,
  SqliteStore,
  GraphStore,
  GraphBuilder,
} from '@sfcontext/core';

// Detect project type
const detection = await detectProject('/path/to/sfdx-project');
console.log(detection.project?.type); // 'sfdx' | 'sfdx2' | 'copado' | 'mdapi'

// Index and search
const store = new SqliteStore();
const pipeline = new IndexingPipeline(new NoOpEmbedder(), store);
await pipeline.index({ rootPath: '/path/to/project', skipEmbeddings: true });
const results = await store.searchText('account trigger handler', 5);

// Build dependency graph
const graph = new GraphStore();
const builder = new GraphBuilder(graph);
// ... parse files and add to builder
const impact = graph.impactAnalysis('ApexClass:AccountService');

Development

npm install
npm run build       # Build all packages
npm run dev         # Watch mode
npm run lint        # Lint

Data Storage

All data is stored locally:

  • Search index: ~/.sfcontext/search.db (SQLite)
  • File snapshots: ~/.sfcontext/snapshots/ (JSON, for incremental indexing)

No data is sent to any external service in the default local mode.

License

MIT

About

Local-first MCP server that gives AI coding agents deep understanding of Salesforce codebases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors