Skip to main content
Glama
codefriar

Salesforce CLI MCP Server

sf_set_project_directory

Set the Salesforce project directory to establish the execution context for CLI commands, enabling operations within a specific project containing sfdx-project.json.

Instructions

Set a Salesforce project directory for command execution context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesThe absolute path to a directory containing an sfdx-project.json file
nameNoOptional name for this project root
descriptionNoOptional description for this project root
isDefaultNoSet this root as the default for command execution

Implementation Reference

  • src/index.ts:66-90 (registration)
    Registers the sf_set_project_directory MCP tool with Zod input schema and inline handler that delegates to setProjectDirectory helper
    server.tool('sf_set_project_directory', 'Set a Salesforce project directory for command execution context', {
        directory: z.string().describe('The absolute path to a directory containing an sfdx-project.json file'),
        name: z.string().optional().describe('Optional name for this project root'),
        description: z.string().optional().describe('Optional description for this project root'),
        isDefault: z.boolean().optional().describe('Set this root as the default for command execution')
    }, async (params) => {
        
        // Set the project directory with optional metadata
        const result = setProjectDirectory(params.directory, {
            name: params.name,
            description: params.description,
            isDefault: params.isDefault
        });
        
        return {
            content: [
                {
                    type: 'text',
                    text: result
                        ? `Successfully set Salesforce project root: ${params.directory}${params.name ? ` with name "${params.name}"` : ''}${params.isDefault ? ' (default)' : ''}`
                        : `Failed to set project directory. Make sure the path exists and contains an sfdx-project.json file.`,
                },
            ],
        };
    });
  • Core implementation of project directory setting: validates Salesforce project (sfdx-project.json), manages projectRoots array, handles updates/defaults
    export function setProjectDirectory(
        directory: string, 
        options: { name?: string; description?: string; isDefault?: boolean } = {}
    ): boolean {
        try {
            // Validate that the directory exists and contains an sfdx-project.json file
            if (!isValidSalesforceProject(directory)) {
                console.error(`Invalid Salesforce project: ${directory}`);
                return false;
            }
            
            // Check if this root already exists
            const existingIndex = projectRoots.findIndex(root => root.path === directory);
            
            if (existingIndex >= 0) {
                // Update existing root with new options
                projectRoots[existingIndex] = {
                    ...projectRoots[existingIndex],
                    ...options,
                    path: directory
                };
                
                // If this is now the default root, update defaultRootPath
                if (options.isDefault) {
                    // Remove default flag from other roots
                    projectRoots.forEach((root, idx) => {
                        if (idx !== existingIndex) {
                            root.isDefault = false;
                        }
                    });
                    defaultRootPath = directory;
                }
                
                console.error(`Updated Salesforce project root: ${directory}`);
            } else {
                // Add as new root
                const isDefault = options.isDefault ?? (projectRoots.length === 0);
                
                projectRoots.push({
                    path: directory,
                    name: options.name || path.basename(directory),
                    description: options.description,
                    isDefault
                });
                
                // If this is now the default root, update defaultRootPath
                if (isDefault) {
                    // Remove default flag from other roots
                    projectRoots.forEach((root, idx) => {
                        if (idx !== projectRoots.length - 1) {
                            root.isDefault = false;
                        }
                    });
                    defaultRootPath = directory;
                }
                
                console.error(`Added Salesforce project root: ${directory}`);
            }
            
            // Always ensure we have exactly one default root if any roots exist
            if (projectRoots.length > 0 && !projectRoots.some(root => root.isDefault)) {
                projectRoots[0].isDefault = true;
                defaultRootPath = projectRoots[0].path;
            }
            
            return true;
        } catch (error) {
            console.error('Error setting project directory:', error);
            return false;
        }
    }
  • Helper function to validate if a directory is a valid Salesforce project by checking for sfdx-project.json
    function isValidSalesforceProject(directory: string): boolean {
        const projectFilePath = path.join(directory, 'sfdx-project.json');
        return fs.existsSync(directory) && fs.existsSync(projectFilePath);
    }
  • Helper to retrieve list of configured project roots
    export function getProjectRoots(): ProjectRoot[] {
        return [...projectRoots];
    }
  • Type definition for project root configuration used by the tool
    interface ProjectRoot {
        path: string;
        name?: string;
        description?: string;
        isDefault?: boolean;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions setting a directory for 'command execution context,' which implies configuration/mutation, but doesn't specify whether this persists across sessions, requires specific permissions, or has side effects. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and efficient, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 4 parameters, no annotations, and no output schema, the description is minimally adequate but incomplete. It covers the basic purpose but lacks details on behavioral traits, usage context, and output expectations, which are crucial for a mutation tool in a set of related Salesforce commands.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description adds no additional semantic information about parameters beyond what's in the schema, such as usage examples or constraints. This meets the baseline for high schema coverage but doesn't provide extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Set') and the resource ('Salesforce project directory for command execution context'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like sf_detect_project_directory or sf_list_roots, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites (e.g., needing an sfdx-project.json file), when not to use it, or how it relates to sibling tools like sf_detect_project_directory. This leaves the agent with minimal context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/codefriar/sf-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server