get-entity-attributes
Retrieve attributes and fields of a PowerPlatform entity by specifying its logical name. Simplify metadata access for entity exploration and analysis.
Instructions
Get attributes/fields of a PowerPlatform entity
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityName | Yes | The logical name of the entity |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"entityName": {
"description": "The logical name of the entity",
"type": "string"
}
},
"required": [
"entityName"
],
"type": "object"
}
Implementation Reference
- src/index.ts:394-422 (handler)MCP tool handler for 'get-entity-attributes' that initializes the PowerPlatformService, calls getEntityAttributes, stringifies the result, and returns it as text content.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}`, }, ], }; } }
- src/index.ts:391-393 (schema)Zod schema defining the input parameter 'entityName' for the tool.{ entityName: z.string().describe("The logical name of the entity"), },
- src/index.ts:388-423 (registration)Registers the 'get-entity-attributes' tool with the MCP server using server.tool().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}`, }, ], }; } } );
- src/PowerPlatformService.ts:115-158 (helper)Core implementation of entity attributes retrieval: queries Dataverse metadata API, selects LogicalName, filters out Virtual attributes and specific naming patterns like 'yominame' or redundant 'name' suffixes.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; }