Skip to main content
Glama

query-records

Retrieve PowerPlatform records by applying OData filter expressions to specific entities like accounts or contacts.

Instructions

Query records using an OData filter expression

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityNamePluralYesThe plural name of the entity (e.g., 'accounts', 'contacts')
filterYesOData filter expression (e.g., "name eq 'test'" or "createdon gt 2023-01-01")
maxRecordsNoMaximum number of records to retrieve (default: 50)

Implementation Reference

  • src/index.ts:580-618 (registration)
    Full registration of the 'query-records' tool, including schema definition and handler function that delegates to PowerPlatformService.queryRecords.
    server.tool( "query-records", "Query records using an OData filter expression", { entityNamePlural: z.string().describe("The plural name of the entity (e.g., 'accounts', 'contacts')"), filter: z.string().describe("OData filter expression (e.g., \"name eq 'test'\" or \"createdon gt 2023-01-01\")"), maxRecords: z.number().optional().describe("Maximum number of records to retrieve (default: 50)"), }, async ({ entityNamePlural, filter, maxRecords }) => { try { // Get or initialize PowerPlatformService const service = getPowerPlatformService(); const records = await service.queryRecords(entityNamePlural, filter, maxRecords || 50); // Format the records as a string for text display const recordsStr = JSON.stringify(records, null, 2); const recordCount = records.value?.length || 0; return { content: [ { type: "text", text: `Retrieved ${recordCount} records from '${entityNamePlural}' with filter '${filter}':\n\n${recordsStr}`, }, ], }; } catch (error: any) { console.error("Error querying records:", error); return { content: [ { type: "text", text: `Failed to query records: ${error.message}`, }, ], }; } } );
  • Zod schema defining input parameters for the 'query-records' tool: entityNamePlural, filter, and optional maxRecords.
    { entityNamePlural: z.string().describe("The plural name of the entity (e.g., 'accounts', 'contacts')"), filter: z.string().describe("OData filter expression (e.g., \"name eq 'test'\" or \"createdon gt 2023-01-01\")"), maxRecords: z.number().optional().describe("Maximum number of records to retrieve (default: 50)"), },
  • The handler function for executing the 'query-records' tool logic, formatting results as text content.
    async ({ entityNamePlural, filter, maxRecords }) => { try { // Get or initialize PowerPlatformService const service = getPowerPlatformService(); const records = await service.queryRecords(entityNamePlural, filter, maxRecords || 50); // Format the records as a string for text display const recordsStr = JSON.stringify(records, null, 2); const recordCount = records.value?.length || 0; return { content: [ { type: "text", text: `Retrieved ${recordCount} records from '${entityNamePlural}' with filter '${filter}':\n\n${recordsStr}`, }, ], }; } catch (error: any) { console.error("Error querying records:", error); return { content: [ { type: "text", text: `Failed to query records: ${error.message}`, }, ], }; } }
  • Supporting helper method in PowerPlatformService that performs the actual OData API request for querying records.
    async queryRecords(entityNamePlural: string, filter: string, maxRecords: number = 50): Promise<ApiCollectionResponse<any>> { return this.makeRequest<ApiCollectionResponse<any>>(`api/data/v9.2/${entityNamePlural}?$filter=${encodeURIComponent(filter)}&$top=${maxRecords}`); }

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