Skip to main content
Glama
michsob

PowerPlatform MCP

get-entity-attributes

Retrieve attributes and fields for a PowerPlatform entity to understand its data structure and metadata.

Instructions

Get attributes/fields of a PowerPlatform entity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityNameYesThe logical name of the entity

Implementation Reference

  • Inline asynchronous handler function for the 'get-entity-attributes' tool. It retrieves the PowerPlatformService, calls getEntityAttributes on it, formats the result as JSON string, and returns it as text content. Handles errors gracefully.
    async ({ entityName }) => {
      try {
        // Get or initialize PowerPlatformService
        const service = getPowerPlatformService();
        const attributes = await service.getEntityAttributes(entityName);
        
        // Format the attributes as a string for text display
        const attributesStr = JSON.stringify(attributes, null, 2);
        
        return {
          content: [
            {
              type: "text",
              text: `Attributes for entity '${entityName}':\n\n${attributesStr}`,
            },
          ],
        };
      } catch (error: any) {
        console.error("Error getting entity attributes:", error);
        return {
          content: [
            {
              type: "text",
              text: `Failed to get entity attributes: ${error.message}`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the tool: a required 'entityName' string.
    {
      entityName: z.string().describe("The logical name of the entity"),
    },
  • src/index.ts:388-423 (registration)
    Registration of the 'get-entity-attributes' MCP tool on the McpServer instance, specifying name, description, input schema, and handler function.
    server.tool(
      "get-entity-attributes",
      "Get attributes/fields of a PowerPlatform entity",
      {
        entityName: z.string().describe("The logical name of the entity"),
      },
      async ({ entityName }) => {
        try {
          // Get or initialize PowerPlatformService
          const service = getPowerPlatformService();
          const attributes = await service.getEntityAttributes(entityName);
          
          // Format the attributes as a string for text display
          const attributesStr = JSON.stringify(attributes, null, 2);
          
          return {
            content: [
              {
                type: "text",
                text: `Attributes for entity '${entityName}':\n\n${attributesStr}`,
              },
            ],
          };
        } catch (error: any) {
          console.error("Error getting entity attributes:", error);
          return {
            content: [
              {
                type: "text",
                text: `Failed to get entity attributes: ${error.message}`,
              },
            ],
          };
        }
      }
    );
  • Supporting method in PowerPlatformService class that implements the core logic for fetching entity attributes from the Power Platform API. It queries EntityDefinitions/Attributes, selects LogicalName, filters out Virtual attributes and specific patterns (yominame, duplicate 'name' attributes), and returns the filtered collection.
    async getEntityAttributes(entityName: string): Promise<ApiCollectionResponse<any>> {
      const selectProperties = [
        'LogicalName',
      ].join(',');
      
      // Make the request to get attributes
      const response = await this.makeRequest<ApiCollectionResponse<any>>(`api/data/v9.2/EntityDefinitions(LogicalName='${entityName}')/Attributes?$select=${selectProperties}&$filter=AttributeType ne 'Virtual'`);
      
      if (response && response.value) {
        // First pass: Filter out attributes that end with 'yominame'
        response.value = response.value.filter((attribute: any) => {
          const logicalName = attribute.LogicalName || '';
          return !logicalName.endsWith('yominame');
        });
        
        // Filter out attributes that end with 'name' if there is another attribute with the same name without the 'name' suffix
        const baseNames = new Set<string>();
        const namesAttributes = new Map<string, any>();
        
        for (const attribute of response.value) {
          const logicalName = attribute.LogicalName || '';
        
          if (logicalName.endsWith('name') && logicalName.length > 4) {
            const baseName = logicalName.slice(0, -4); // Remove 'name' suffix
            namesAttributes.set(baseName, attribute);
          } else {
            // This is a potential base attribute
            baseNames.add(logicalName);
          }
        }
        
        // Find attributes to remove that match the pattern
        const attributesToRemove = new Set<any>();
        for (const [baseName, nameAttribute] of namesAttributes.entries()) {
          if (baseNames.has(baseName)) {
            attributesToRemove.add(nameAttribute);
          }
        }
    
        response.value = response.value.filter(attribute => !attributesToRemove.has(attribute));
      }
      
      return response;
    }

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/michsob/powerplatform-mcp'

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