Skip to main content
Glama
simonl77

Salesforce MCP Server

by simonl77

salesforce_search_objects

Search Salesforce standard and custom objects by name pattern to quickly locate specific data structures within your Salesforce instance.

Instructions

Search for Salesforce standard and custom objects by name pattern. Examples: 'Account' will find Account, AccountHistory; 'Order' will find WorkOrder, ServiceOrder__c etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchPatternYesSearch pattern to find objects (e.g., 'Account Coverage' will find objects like 'AccountCoverage__c')

Implementation Reference

  • The handler function that executes the salesforce_search_objects tool. It uses conn.describeGlobal() to get all objects, filters them based on the searchPattern by splitting into terms and checking name/label, formats results.
    export async function handleSearchObjects(conn: any, searchPattern: string) {
      // Get list of all objects
      const describeGlobal = await conn.describeGlobal();
      
      // Process search pattern to create a more flexible search
      const searchTerms = searchPattern.toLowerCase().split(' ').filter(term => term.length > 0);
      
      // Filter objects based on search pattern
      const matchingObjects = describeGlobal.sobjects.filter((obj: SalesforceObject) => {
        const objectName = obj.name.toLowerCase();
        const objectLabel = obj.label.toLowerCase();
        
        // Check if all search terms are present in either the API name or label
        return searchTerms.every(term => 
          objectName.includes(term) || objectLabel.includes(term)
        );
      });
    
      if (matchingObjects.length === 0) {
        return {
          content: [{
            type: "text",
            text: `No Salesforce objects found matching "${searchPattern}".`
          }],
          isError: false,
        };
      }
    
      // Format the output
      const formattedResults = matchingObjects.map((obj: SalesforceObject) => 
        `${obj.name}${obj.custom ? ' (Custom)' : ''}\n  Label: ${obj.label}`
      ).join('\n\n');
    
      return {
        content: [{
          type: "text",
          text: `Found ${matchingObjects.length} matching objects:\n\n${formattedResults}`
        }],
        isError: false,
      };
    }
  • The Tool object defining the schema for salesforce_search_objects, including name, description, and inputSchema with searchPattern parameter.
    export const SEARCH_OBJECTS: Tool = {
      name: "salesforce_search_objects",
      description: "Search for Salesforce standard and custom objects by name pattern. Examples: 'Account' will find Account, AccountHistory; 'Order' will find WorkOrder, ServiceOrder__c etc.",
      inputSchema: {
        type: "object",
        properties: {
          searchPattern: {
            type: "string",
            description: "Search pattern to find objects (e.g., 'Account Coverage' will find objects like 'AccountCoverage__c')"
          }
        },
        required: ["searchPattern"]
      }
    };
  • src/index.ts:73-77 (registration)
    Registration in the CallToolRequestSchema handler switch statement that extracts searchPattern from args and calls handleSearchObjects.
    case "salesforce_search_objects": {
      const { searchPattern } = args as { searchPattern: string };
      if (!searchPattern) throw new Error('searchPattern is required');
      return await handleSearchObjects(conn, searchPattern);
    }
  • src/index.ts:45-63 (registration)
    Registration in ListToolsRequestSchema handler that includes SEARCH_OBJECTS in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        SEARCH_OBJECTS, 
        DESCRIBE_OBJECT, 
        QUERY_RECORDS, 
        AGGREGATE_QUERY,
        DML_RECORDS,
        MANAGE_OBJECT,
        MANAGE_FIELD,
        MANAGE_FIELD_PERMISSIONS,
        SEARCH_ALL,
        READ_APEX,
        WRITE_APEX,
        READ_APEX_TRIGGER,
        WRITE_APEX_TRIGGER,
        EXECUTE_ANONYMOUS,
        MANAGE_DEBUG_LOGS
      ],
    }));
  • Import of the SEARCH_OBJECTS schema and handleSearchObjects handler from the search tool file.
    import { SEARCH_OBJECTS, handleSearchObjects } from "./tools/search.js";

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.9/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden of disclosing behavior. It explains the search action and gives examples of matches, but doesn't state whether the operation is read-only, its return format, or any limitations (e.g., case sensitivity, wildcard support). For a simple search tool, the core behavior is disclosed, but additional transparency is lacking.

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 extremely concise: one sentence stating the purpose and one sentence with examples. It is front-loaded with the verb and resource, and every word earns its place. No fluff or repetition.

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?

For a tool with one parameter and no output schema, the description covers the main purpose and gives examples. However, it omits specifics about how the pattern matching works (e.g., substring vs. whole word, case sensitivity) and what the output shape is (e.g., just names or full metadata). These gaps prevent it from being fully complete.

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 only parameter `searchPattern` has a 100% schema description coverage, including an example. The tool description reiterates and supplements with examples ('Account' will find Account, AccountHistory), but doesn't add significant new meaning beyond what the schema already provides. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the tool's function: 'Search for Salesforce standard and custom objects by name pattern.' It provides concrete examples ('Account' will find Account, AccountHistory), which further clarifies the scope and distinguishes it from sibling tools like describe or query.

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

Usage Guidelines4/5

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

The description gives a clear context of when to use this tool (searching objects by name pattern) and provides examples of the expected input/output. It doesn't explicitly mention alternative tools or exclusions, but the use case is unambiguous enough for an agent to decide when to call it.

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