Skip to main content
Glama
mwhesse

Dataverse MCP Server

by mwhesse

Update AutoNumber Format

update_autonumber_format

Modify the AutoNumber format for a Dataverse column to control how future sequential values are generated, using customizable placeholders for prefixes, sequences, dates, and random strings.

Instructions

Updates the AutoNumberFormat of an existing AutoNumber column. This changes how future values will be generated but does not affect existing records.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
autoNumberFormatYesNew AutoNumber format using placeholders like "PREFIX-{SEQNUM:4}-{RANDSTRING:3}-{DATETIMEUTC:yyyyMMdd}"
columnLogicalNameYesLogical name of the AutoNumber column to update
descriptionNoNew description for the column
displayNameNoNew display name for the column
entityLogicalNameYesLogical name of the table containing the AutoNumber column
maxLengthNoNew maximum length (ensure enough room for format expansion)

Implementation Reference

  • Core handler logic for the 'update_autonumber_format' tool. Retrieves existing AutoNumber attribute metadata, updates the AutoNumberFormat and optional properties (displayName, description, maxLength), then performs a PUT request to the Dataverse metadata endpoint with MSCRM.MergeLabels header to merge labels.
    async (params) => {
      try {
        // First, retrieve the current attribute definition
        const currentAttribute = await client.getMetadata(
          `EntityDefinitions(LogicalName='${params.entityLogicalName}')/Attributes(LogicalName='${params.columnLogicalName}')`
        );
    
        // Create the updated attribute definition
        const updatedAttribute: any = {
          ...currentAttribute,
          "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
          "AutoNumberFormat": params.autoNumberFormat
        };
    
        // Add optional fields if provided
        if (params.displayName) {
          updatedAttribute.DisplayName = createLocalizedLabel(params.displayName);
        }
    
        if (params.description) {
          updatedAttribute.Description = createLocalizedLabel(params.description);
        }
    
        if (params.maxLength) {
          updatedAttribute.MaxLength = params.maxLength;
        }
    
        // Use PUT method with MSCRM.MergeLabels header
        await client.putMetadata(
          `EntityDefinitions(LogicalName='${params.entityLogicalName}')/Attributes(LogicalName='${params.columnLogicalName}')`,
          updatedAttribute,
          {
            'MSCRM.MergeLabels': 'true'
          }
        );
    
        return {
          content: [
            {
              type: "text",
              text: `Successfully updated AutoNumber format for column '${params.columnLogicalName}' in table '${params.entityLogicalName}'.\n\nNew AutoNumber Format: ${params.autoNumberFormat}${params.displayName ? `\nNew Display Name: ${params.displayName}` : ''}${params.maxLength ? `\nNew Max Length: ${params.maxLength}` : ''}`
            }
          ]
        };
    
      } catch (error: any) {
        let errorMessage = `Error updating AutoNumber format: ${error instanceof Error ? error.message : 'Unknown error'}`;
        
        if (error.message?.includes('Invalid Argument')) {
          errorMessage += '\n\nTip: Check AutoNumber format syntax. Use {SEQNUM:length}, {RANDSTRING:1-6}, {DATETIMEUTC:format}';
        }
        
        return {
          content: [
            {
              type: "text",
              text: errorMessage
            }
          ],
          isError: true
        };
      }
    }
  • Zod validation schema for AutoNumber format strings. Validates placeholders {SEQNUM:length}, {RANDSTRING:1-6}, {DATETIMEUTC:format} and provides detailed error messaging. Reused across multiple AutoNumber tools.
    const autoNumberFormatSchema = z.string().refine((format) => {
      // Validate AutoNumber format placeholders
      const validPlaceholders = /^[^{}]*(\{(SEQNUM|RANDSTRING|DATETIMEUTC):[0-9]+\}[^{}]*)*$/;
      const hasValidPlaceholders = validPlaceholders.test(format);
      
      // Check RANDSTRING length constraints (1-6)
      const randStringMatches = format.match(/\{RANDSTRING:(\d+)\}/g);
      if (randStringMatches) {
        for (const match of randStringMatches) {
          const length = parseInt(match.match(/\{RANDSTRING:(\d+)\}/)![1]);
          if (length < 1 || length > 6) {
            return false;
          }
        }
      }
      
      // Check SEQNUM length constraints (minimum 1)
      const seqNumMatches = format.match(/\{SEQNUM:(\d+)\}/g);
      if (seqNumMatches) {
        for (const match of seqNumMatches) {
          const length = parseInt(match.match(/\{SEQNUM:(\d+)\}/)![1]);
          if (length < 1) {
            return false;
          }
        }
      }
      
      return hasValidPlaceholders;
    }, {
      message: "Invalid AutoNumber format. Use placeholders like {SEQNUM:4}, {RANDSTRING:3} (1-6), {DATETIMEUTC:yyyyMMdd}"
    });
  • Registration of the 'update_autonumber_format' MCP tool via server.registerTool(). Includes tool name, title, description, full inputSchema using autoNumberFormatSchema, and the handler function.
    export function updateAutoNumberFormatTool(server: McpServer, client: DataverseClient) {
      server.registerTool(
        'update_autonumber_format',
        {
          title: 'Update AutoNumber Format',
          description: 'Updates the AutoNumberFormat of an existing AutoNumber column. This changes how future values will be generated but does not affect existing records.',
          inputSchema: {
            entityLogicalName: z.string().describe('Logical name of the table containing the AutoNumber column'),
            columnLogicalName: z.string().describe('Logical name of the AutoNumber column to update'),
            autoNumberFormat: autoNumberFormatSchema.describe('New AutoNumber format using placeholders like "PREFIX-{SEQNUM:4}-{RANDSTRING:3}-{DATETIMEUTC:yyyyMMdd}"'),
            displayName: z.string().optional().describe('New display name for the column'),
            description: z.string().optional().describe('New description for the column'),
            maxLength: z.number().min(1).max(4000).optional().describe('New maximum length (ensure enough room for format expansion)')
          }
        },
        async (params) => {
          try {
            // First, retrieve the current attribute definition
            const currentAttribute = await client.getMetadata(
              `EntityDefinitions(LogicalName='${params.entityLogicalName}')/Attributes(LogicalName='${params.columnLogicalName}')`
            );
    
            // Create the updated attribute definition
            const updatedAttribute: any = {
              ...currentAttribute,
              "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
              "AutoNumberFormat": params.autoNumberFormat
            };
    
            // Add optional fields if provided
            if (params.displayName) {
              updatedAttribute.DisplayName = createLocalizedLabel(params.displayName);
            }
    
            if (params.description) {
              updatedAttribute.Description = createLocalizedLabel(params.description);
            }
    
            if (params.maxLength) {
              updatedAttribute.MaxLength = params.maxLength;
            }
    
            // Use PUT method with MSCRM.MergeLabels header
            await client.putMetadata(
              `EntityDefinitions(LogicalName='${params.entityLogicalName}')/Attributes(LogicalName='${params.columnLogicalName}')`,
              updatedAttribute,
              {
                'MSCRM.MergeLabels': 'true'
              }
            );
    
            return {
              content: [
                {
                  type: "text",
                  text: `Successfully updated AutoNumber format for column '${params.columnLogicalName}' in table '${params.entityLogicalName}'.\n\nNew AutoNumber Format: ${params.autoNumberFormat}${params.displayName ? `\nNew Display Name: ${params.displayName}` : ''}${params.maxLength ? `\nNew Max Length: ${params.maxLength}` : ''}`
                }
              ]
            };
    
          } catch (error: any) {
            let errorMessage = `Error updating AutoNumber format: ${error instanceof Error ? error.message : 'Unknown error'}`;
            
            if (error.message?.includes('Invalid Argument')) {
              errorMessage += '\n\nTip: Check AutoNumber format syntax. Use {SEQNUM:length}, {RANDSTRING:1-6}, {DATETIMEUTC:format}';
            }
            
            return {
              content: [
                {
                  type: "text",
                  text: errorMessage
                }
              ],
              isError: true
            };
          }
        }
      );
    }
  • src/index.ts:241-241 (registration)
    Invocation of updateAutoNumberFormatTool to register the tool during MCP server initialization in main entry point.
    updateAutoNumberFormatTool(server, dataverseClient);
  • Utility function to create standardized localized label objects for Dataverse metadata (used in displayName and description updates).
    function createLocalizedLabel(text: string, languageCode: number = 1033) {
      return {
        LocalizedLabels: [
          {
            Label: text,
            LanguageCode: languageCode,
            IsManaged: false,
            MetadataId: "00000000-0000-0000-0000-000000000000"
          }
        ],
        UserLocalizedLabel: {
          Label: text,
          LanguageCode: languageCode,
          IsManaged: false,
          MetadataId: "00000000-0000-0000-0000-000000000000"
        }
      };
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the update only affects future values (a key behavioral trait) and implies mutation. However, it lacks details on permissions, error handling, or response format, leaving gaps for a mutation tool.

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 two sentences with zero waste: the first states the purpose and scope, and the second clarifies the impact on existing vs. future records. It is front-loaded and appropriately sized.

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 mutation tool with no annotations and no output schema, the description is adequate but incomplete. It covers the core purpose and behavioral nuance (future-only effect), but lacks details on permissions, side effects, or error conditions that would be helpful for an agent.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description does not add any parameter-specific information beyond what the schema provides, such as examples or constraints, meeting the baseline for high coverage.

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 verb ('Updates'), resource ('AutoNumberFormat of an existing AutoNumber column'), and scope ('changes how future values will be generated but does not affect existing records'). It distinguishes from sibling tools like 'create_autonumber_column' (creation vs. update) and 'set_autonumber_seed' (format vs. seed).

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 provides clear context by specifying that it updates an existing column and only affects future values, implying it should be used for modifying format rather than creating new columns or altering existing records. However, it does not explicitly mention when not to use it or name specific alternatives among siblings.

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/mwhesse/mcp-dataverse'

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