Skip to main content
Glama

get-entity-relationships

Retrieve one-to-many and many-to-many relationships for a PowerPlatform entity by specifying its logical name. Facilitates entity exploration and metadata access.

Instructions

Get relationships (one-to-many and many-to-many) for a PowerPlatform entity

Input Schema

NameRequiredDescriptionDefault
entityNameYesThe 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:465-500 (registration)
    Full MCP server.tool registration block for the 'get-entity-relationships' tool, including schema and complete handler implementation that fetches and returns entity relationships as formatted JSON text.
    server.tool( "get-entity-relationships", "Get relationships (one-to-many and many-to-many) for a PowerPlatform entity", { entityName: z.string().describe("The logical name of the entity"), }, async ({ entityName }) => { try { // Get or initialize PowerPlatformService const service = getPowerPlatformService(); const relationships = await service.getEntityRelationships(entityName); // Format the relationships as a string for text display const relationshipsStr = JSON.stringify(relationships, null, 2); return { content: [ { type: "text", text: `Relationships for entity '${entityName}':\n\n${relationshipsStr}`, }, ], }; } catch (error: any) { console.error("Error getting entity relationships:", error); return { content: [ { type: "text", text: `Failed to get entity relationships: ${error.message}`, }, ], }; } } );
  • Zod input schema for the tool, defining the 'entityName' parameter.
    { entityName: z.string().describe("The logical name of the entity"), },
  • Inline handler function of the tool that initializes the service, calls getEntityRelationships, stringifies the result, and returns it as text content.
    async ({ entityName }) => { try { // Get or initialize PowerPlatformService const service = getPowerPlatformService(); const relationships = await service.getEntityRelationships(entityName); // Format the relationships as a string for text display const relationshipsStr = JSON.stringify(relationships, null, 2); return { content: [ { type: "text", text: `Relationships for entity '${entityName}':\n\n${relationshipsStr}`, }, ], }; } catch (error: any) { console.error("Error getting entity relationships:", error); return { content: [ { type: "text", text: `Failed to get entity relationships: ${error.message}`, }, ], }; } }
  • Core helper method in PowerPlatformService that concurrently retrieves one-to-many and many-to-many relationships for the given entity.
    async getEntityRelationships(entityName: string): Promise<{oneToMany: ApiCollectionResponse<any>, manyToMany: ApiCollectionResponse<any>}> { const [oneToMany, manyToMany] = await Promise.all([ this.getEntityOneToManyRelationships(entityName), this.getEntityManyToManyRelationships(entityName) ]); return { oneToMany, manyToMany }; }
  • Helper method that fetches and filters one-to-many relationships from the Dataverse API, excluding certain system entities.
    async getEntityOneToManyRelationships(entityName: string): Promise<ApiCollectionResponse<any>> { const selectProperties = [ 'SchemaName', 'RelationshipType', 'ReferencedAttribute', 'ReferencedEntity', 'ReferencingAttribute', 'ReferencingEntity', 'ReferencedEntityNavigationPropertyName', 'ReferencingEntityNavigationPropertyName' ].join(','); // Only filter by ReferencingAttribute in the OData query since startswith isn't supported const response = await this.makeRequest<ApiCollectionResponse<any>>(`api/data/v9.2/EntityDefinitions(LogicalName='${entityName}')/OneToManyRelationships?$select=${selectProperties}&$filter=ReferencingAttribute ne 'regardingobjectid'`); // Filter the response to exclude relationships with ReferencingEntity starting with 'msdyn_' or 'adx_' if (response && response.value) { response.value = response.value.filter((relationship: any) => { const referencingEntity = relationship.ReferencingEntity || ''; return !(referencingEntity.startsWith('msdyn_') || referencingEntity.startsWith('adx_')); }); } return response; }

Other Tools

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

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