salesforce_search_objects
Search Salesforce standard and custom objects by name pattern to quickly find relevant data structures for integration or development tasks.
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
| Name | Required | Description | Default |
|---|---|---|---|
| searchPattern | Yes | Search pattern to find objects (e.g., 'Account Coverage' will find objects like 'AccountCoverage__c') |
Implementation Reference
- src/tools/search.ts:19-59 (handler)The handler function that performs the actual tool logic: fetches all Salesforce objects via describeGlobal, filters by search pattern in name or label, and 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, }; }
- src/tools/search.ts:4-17 (schema)Defines the tool's metadata including name, description, and input schema requiring 'searchPattern'.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:45-63 (registration)Registers SEARCH_OBJECTS in the MCP server's listTools response, making the tool discoverable.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 ], }));
- src/index.ts:73-77 (registration)Switch case in the main CallToolRequestSchema handler that dispatches to the specific handleSearchObjects function.case "salesforce_search_objects": { const { searchPattern } = args as { searchPattern: string }; if (!searchPattern) throw new Error('searchPattern is required'); return await handleSearchObjects(conn, searchPattern); }