Skip to main content
Glama
mwhesse

Dataverse MCP Server

by mwhesse

Create Dataverse Option Set

create_dataverse_optionset

Create global choice lists in Dataverse with predefined options to ensure consistent data entry and improve data quality across multiple tables and columns.

Instructions

Creates a new global option set (choice list) in Dataverse with predefined options. Use this to create reusable choice lists that can be used across multiple tables and columns. Option sets provide consistent data entry options and improve data quality.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoDescription of the option set
displayNameYesDisplay name for the option set
isGlobalNoWhether this is a global option set
nameYesName for the option set (e.g., 'new_priority')
optionsYesArray of options for the option set

Implementation Reference

  • The main handler function that executes the tool logic: validates input, builds the OptionSetMetadata payload using the helper, calls the Dataverse API to create the global option set, and returns success/error response.
    async (params) => {
      try {
        if (!params.options || params.options.length === 0) {
          throw new Error("At least one option is required");
        }
    
        const optionSetDefinition = {
          "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
          Name: params.name,
          DisplayName: createLocalizedLabel(params.displayName),
          Description: params.description ? createLocalizedLabel(params.description) : undefined,
          OptionSetType: "Picklist", // Use string instead of numeric
          IsGlobal: params.isGlobal,
          IsCustomOptionSet: true,
          Options: params.options.map(option => ({
            Value: option.value,
            Label: createLocalizedLabel(option.label),
            Description: option.description ? createLocalizedLabel(option.description) : undefined,
            Color: option.color,
            IsManaged: false
          }))
        };
    
        const result = await client.postMetadata("GlobalOptionSetDefinitions", optionSetDefinition);
    
        return {
          content: [
            {
              type: "text",
              text: `Successfully created option set '${params.name}' with ${params.options.length} options.\n\nResponse: ${JSON.stringify(result, null, 2)}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error creating option set: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the tool: name, displayName, optional description and isGlobal, and array of options with value, label, etc.
    inputSchema: {
      name: z.string().describe("Name for the option set (e.g., 'new_priority')"),
      displayName: z.string().describe("Display name for the option set"),
      description: z.string().optional().describe("Description of the option set"),
      isGlobal: z.boolean().default(true).describe("Whether this is a global option set"),
      options: z.array(z.object({
        value: z.number().describe("Numeric value for the option"),
        label: z.string().describe("Display label for the option"),
        description: z.string().optional().describe("Description for the option"),
        color: z.string().optional().describe("Color for the option (hex format, e.g., '#FF0000')")
      })).describe("Array of options for the option set")
    }
  • The createOptionSetTool function which registers the 'create_dataverse_optionset' tool on the MCP server, providing title, description, input schema, and handler.
    export function createOptionSetTool(server: McpServer, client: DataverseClient) {
      server.registerTool(
        "create_dataverse_optionset",
        {
          title: "Create Dataverse Option Set",
          description: "Creates a new global option set (choice list) in Dataverse with predefined options. Use this to create reusable choice lists that can be used across multiple tables and columns. Option sets provide consistent data entry options and improve data quality.",
          inputSchema: {
            name: z.string().describe("Name for the option set (e.g., 'new_priority')"),
            displayName: z.string().describe("Display name for the option set"),
            description: z.string().optional().describe("Description of the option set"),
            isGlobal: z.boolean().default(true).describe("Whether this is a global option set"),
            options: z.array(z.object({
              value: z.number().describe("Numeric value for the option"),
              label: z.string().describe("Display label for the option"),
              description: z.string().optional().describe("Description for the option"),
              color: z.string().optional().describe("Color for the option (hex format, e.g., '#FF0000')")
            })).describe("Array of options for the option set")
          }
        },
        async (params) => {
          try {
            if (!params.options || params.options.length === 0) {
              throw new Error("At least one option is required");
            }
    
            const optionSetDefinition = {
              "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
              Name: params.name,
              DisplayName: createLocalizedLabel(params.displayName),
              Description: params.description ? createLocalizedLabel(params.description) : undefined,
              OptionSetType: "Picklist", // Use string instead of numeric
              IsGlobal: params.isGlobal,
              IsCustomOptionSet: true,
              Options: params.options.map(option => ({
                Value: option.value,
                Label: createLocalizedLabel(option.label),
                Description: option.description ? createLocalizedLabel(option.description) : undefined,
                Color: option.color,
                IsManaged: false
              }))
            };
    
            const result = await client.postMetadata("GlobalOptionSetDefinitions", optionSetDefinition);
    
            return {
              content: [
                {
                  type: "text",
                  text: `Successfully created option set '${params.name}' with ${params.options.length} options.\n\nResponse: ${JSON.stringify(result, null, 2)}`
                }
              ]
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text",
                  text: `Error creating option set: ${error instanceof Error ? error.message : 'Unknown error'}`
                }
              ],
              isError: true
            };
          }
        }
      );
    }
  • Helper function to create standardized LocalizedLabel objects for option set metadata, used in DisplayName, Description, and Option Labels.
    function createLocalizedLabel(text: string, languageCode: number = 1033): LocalizedLabel {
      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"
        }
      };
    }
  • src/index.ts:159-159 (registration)
    Invocation of the registration function in the main server initialization file, passing the MCP server and Dataverse client instances.
    createOptionSetTool(server, dataverseClient);
Behavior2/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 behavioral disclosure. While it mentions that the tool creates a 'global option set' and describes its purpose, it lacks critical details such as required permissions, whether the operation is idempotent, error conditions, or what happens on success/failure. For a creation tool with zero annotation coverage, this is a significant gap.

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 efficiently structured in three sentences: the first states the core action, the second explains usage context, and the third highlights benefits. Each sentence adds value without redundancy, making it 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?

Given the tool's complexity (creation operation with 5 parameters) and lack of annotations and output schema, the description is adequate but has clear gaps. It explains the 'what' and 'why' but omits behavioral details like permissions, side effects, or response format. For a creation tool, this leaves the agent under-informed about critical operational aspects.

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 5 parameters thoroughly. The description adds no additional parameter-specific information beyond what the schema provides, such as examples or constraints not in the schema. The baseline score of 3 is appropriate when the schema does the heavy lifting.

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 specific action ('Creates a new global option set'), resource ('in Dataverse'), and purpose ('with predefined options'). It distinguishes this tool from siblings like 'update_dataverse_optionset' or 'get_dataverse_optionset' by emphasizing creation rather than modification or retrieval.

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 on when to use this tool ('to create reusable choice lists that can be used across multiple tables and columns'), explaining its benefits for data consistency and quality. However, it does not explicitly state when NOT to use it or mention alternatives like 'update_dataverse_optionset' for modifying existing option sets.

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