Skip to main content
Glama
simonl77

Salesforce MCP Server

by simonl77

salesforce_manage_object

Create or modify custom Salesforce objects to organize business data, including setting fields, relationships, and sharing permissions.

Instructions

Create new custom objects or modify existing ones in Salesforce:

  • Create: New custom objects with fields, relationships, and settings

  • Update: Modify existing object settings, labels, sharing model Examples: Create Customer_Feedback__c object, Update object sharing settings Note: Changes affect metadata and require proper permissions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesWhether to create new object or update existing
objectNameYesAPI name for the object (without __c suffix)
labelNoLabel for the object
pluralLabelNoPlural label for the object
descriptionNoDescription of the object
nameFieldLabelNoLabel for the name field
nameFieldTypeNoType of the name field
nameFieldFormatNoDisplay format for AutoNumber field (e.g., 'A-{0000}')
sharingModelNoSharing model for the object

Implementation Reference

  • The core handler function `handleManageObject` that executes the tool logic: creates or updates Salesforce custom objects using the Metadata API, handles validation, metadata preparation, API calls, and error handling.
    export async function handleManageObject(conn: any, args: ManageObjectArgs) {
      const { operation, objectName, label, pluralLabel, description, nameFieldLabel, nameFieldType, nameFieldFormat, sharingModel } = args;
    
      try {
        if (operation === 'create') {
          if (!label || !pluralLabel) {
            throw new Error('Label and pluralLabel are required for object creation');
          }
    
          // Prepare metadata for the new object
          const metadata = {
            fullName: `${objectName}__c`,
            label,
            pluralLabel,
            nameField: {
              label: nameFieldLabel || `${label} Name`,
              type: nameFieldType || 'Text',
              ...(nameFieldType === 'AutoNumber' && nameFieldFormat ? { displayFormat: nameFieldFormat } : {})
            },
            deploymentStatus: 'Deployed',
            sharingModel: sharingModel || 'ReadWrite'
          } as MetadataInfo;
    
          if (description) {
            metadata.description = description;
          }
    
          // Create the object using Metadata API
          const result = await conn.metadata.create('CustomObject', metadata);
    
          if (result && (Array.isArray(result) ? result[0].success : result.success)) {
            return {
              content: [{
                type: "text",
                text: `Successfully created custom object ${objectName}__c`
              }],
              isError: false,
            };
          }
        } else {
          // For update, first get existing metadata
          const existingMetadata = await conn.metadata.read('CustomObject', [`${objectName}__c`]);
          const currentMetadata = Array.isArray(existingMetadata) ? existingMetadata[0] : existingMetadata;
    
          if (!currentMetadata) {
            throw new Error(`Object ${objectName}__c not found`);
          }
    
          // Prepare update metadata
          const metadata = {
            ...currentMetadata,
            label: label || currentMetadata.label,
            pluralLabel: pluralLabel || currentMetadata.pluralLabel,
            description: description !== undefined ? description : currentMetadata.description,
            sharingModel: sharingModel || currentMetadata.sharingModel
          } as MetadataInfo;
    
          // Update the object using Metadata API
          const result = await conn.metadata.update('CustomObject', metadata);
    
          if (result && (Array.isArray(result) ? result[0].success : result.success)) {
            return {
              content: [{
                type: "text",
                text: `Successfully updated custom object ${objectName}__c`
              }],
              isError: false,
            };
          }
        }
    
        return {
          content: [{
            type: "text",
            text: `Failed to ${operation} custom object ${objectName}__c`
          }],
          isError: true,
        };
    
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error ${operation === 'create' ? 'creating' : 'updating'} custom object: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true,
        };
      }
    }
  • The `MANAGE_OBJECT` tool definition containing the input schema for validating tool parameters like operation, objectName, labels, and sharing model.
    export const MANAGE_OBJECT: Tool = {
      name: "salesforce_manage_object",
      description: `Create new custom objects or modify existing ones in Salesforce:
      - Create: New custom objects with fields, relationships, and settings
      - Update: Modify existing object settings, labels, sharing model
      Examples: Create Customer_Feedback__c object, Update object sharing settings
      Note: Changes affect metadata and require proper permissions`,
      inputSchema: {
        type: "object",
        properties: {
          operation: {
            type: "string",
            enum: ["create", "update"],
            description: "Whether to create new object or update existing"
          },
          objectName: {
            type: "string",
            description: "API name for the object (without __c suffix)"
          },
          label: {
            type: "string",
            description: "Label for the object"
          },
          pluralLabel: {
            type: "string",
            description: "Plural label for the object"
          },
          description: {
            type: "string",
            description: "Description of the object",
            optional: true
          },
          nameFieldLabel: {
            type: "string",
            description: "Label for the name field",
            optional: true
          },
          nameFieldType: {
            type: "string",
            enum: ["Text", "AutoNumber"],
            description: "Type of the name field",
            optional: true
          },
          nameFieldFormat: {
            type: "string",
            description: "Display format for AutoNumber field (e.g., 'A-{0000}')",
            optional: true
          },
          sharingModel: {
            type: "string",
            enum: ["ReadWrite", "Read", "Private", "ControlledByParent"],
            description: "Sharing model for the object",
            optional: true
          }
        },
        required: ["operation", "objectName"]
      }
    };
  • src/index.ts:133-150 (registration)
    Registration in the main tool dispatch switch statement: validates input arguments and invokes the `handleManageObject` handler.
    case "salesforce_manage_object": {
      const objectArgs = args as Record<string, unknown>;
      if (!objectArgs.operation || !objectArgs.objectName) {
        throw new Error('operation and objectName are required for object management');
      }
      const validatedArgs: ManageObjectArgs = {
        operation: objectArgs.operation as 'create' | 'update',
        objectName: objectArgs.objectName as string,
        label: objectArgs.label as string | undefined,
        pluralLabel: objectArgs.pluralLabel as string | undefined,
        description: objectArgs.description as string | undefined,
        nameFieldLabel: objectArgs.nameFieldLabel as string | undefined,
        nameFieldType: objectArgs.nameFieldType as 'Text' | 'AutoNumber' | undefined,
        nameFieldFormat: objectArgs.nameFieldFormat as string | undefined,
        sharingModel: objectArgs.sharingModel as 'ReadWrite' | 'Read' | 'Private' | 'ControlledByParent' | undefined
      };
      return await handleManageObject(conn, validatedArgs);
    }
  • src/index.ts:45-52 (registration)
    The tool is registered in the listTools response by including `MANAGE_OBJECT` in the tools array, making it discoverable via MCP.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        SEARCH_OBJECTS, 
        DESCRIBE_OBJECT, 
        QUERY_RECORDS, 
        AGGREGATE_QUERY,
        DML_RECORDS,
        MANAGE_OBJECT,
  • src/index.ts:17-17 (registration)
    Import statement that brings in the tool definition, handler, and types from the implementation file.
    import { MANAGE_OBJECT, handleManageObject, ManageObjectArgs } from "./tools/manageObject.js";

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.7/5.0
Behavior3/5

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

The note 'Changes affect metadata and require proper permissions' discloses the mutation nature and permission requirement. However, the claim 'with fields, relationships, and settings' is not supported by the input schema (no fields or relationships parameters), which could mislead an agent about capabilities. This prevents a higher score.

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 compact and well-structured: a clear verb phrase, bulleted operations, illustrative examples, and a critical permission note. Every sentence contributes meaning without redundancy.

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

Completeness2/5

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

The tool has 9 parameters, no annotations, and no output schema, so the description must carry more weight. It gives high-level operations but fails to explain return behavior, error conditions, or the full scope of parameter usage. The unsupported 'relationships' claim further reduces completeness and trustworthiness.

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

Parameters2/5

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

Schema description coverage is 100%, so baseline would be 3. However, the description mentions creating objects 'with fields, relationships, and settings' but the schema offers no such parameters, adding misleading information. This overstates the tool's functionality and could lead to incorrect invocation, warranting a score below baseline.

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 uses a specific verb ('Create', 'modify') and resource ('custom objects in Salesforce'), clearly distinguishing this from sibling tools like search/query/describe. It states the two primary operations (create/update) with concrete examples, making the tool's purpose unmistakable.

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?

Provides clear context for when to use the tool (creating or updating objects) with examples and a permission note. However, it does not explicitly exclude alternatives or mention when to choose sibling tools like salesforce_manage_field or salesforce_describe_object, so it falls short of full 5.

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