fetch-accounts
Retrieve account data from Dynamics 365 to access customer information and business details for analysis and management.
Instructions
Fetch accounts from Dynamics 365
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:43-69 (handler)The inline async handler function for the "fetch-accounts" tool. It calls d365.getAccounts() to fetch accounts, stringifies the response.value as JSON, and returns it as text content. Includes try-catch error handling returning an error message.async () => { try { const response = await d365.getAccounts(); const accounts = JSON.stringify(response.value, null, 2); return { content: [ { type: "text", text: accounts, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your credentials and try again.`, }, ], isError: true, }; } } );
- src/tools.ts:39-69 (registration)The server.tool() call that registers the "fetch-accounts" tool with the MCP server, including name, description, empty input schema ({}), and the handler function.server.tool( "fetch-accounts", "Fetch accounts from Dynamics 365", {}, async () => { try { const response = await d365.getAccounts(); const accounts = JSON.stringify(response.value, null, 2); return { content: [ { type: "text", text: accounts, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your credentials and try again.`, }, ], isError: true, }; } } );
- src/main.ts:180-182 (helper)The getAccounts() method in the Dynamics365 class, which performs a GET request to the /api/data/v9.2/accounts endpoint using the private makeApiRequest method, handling authentication.public async getAccounts(): Promise<any> { return this.makeApiRequest("api/data/v9.2/accounts", "GET"); }