Skip to main content
Glama
michsob

PowerPlatform MCP

get-entity-relationships

Retrieve one-to-many and many-to-many relationships for PowerPlatform entities to understand data connections and dependencies.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityNameYesThe logical name of the entity

Implementation Reference

  • Handler function that executes the tool: initializes PowerPlatformService, calls getEntityRelationships(entityName), formats as JSON string in text content, handles errors.
    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: requires entityName as string.
    {
      entityName: z.string().describe("The logical name of the entity"),
    },
  • src/index.ts:465-500 (registration)
    Registration of the 'get-entity-relationships' tool on the MCP server with name, description, schema, and handler.
    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}`,
              },
            ],
          };
        }
      }
    );
  • Helper method in PowerPlatformService that fetches both one-to-many and many-to-many relationships in parallel using sub-methods.
    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 to fetch and filter one-to-many relationships, excluding certain system relationships.
    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;
    }

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