get-associated-opportunities
Retrieve opportunities linked to a specific account in Dynamics 365 using the provided account ID. Facilitates efficient account-related opportunity management.
Instructions
Fetch opportunities for a given account from Dynamics 365
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes |
Implementation Reference
- src/tools.ts:76-100 (handler)MCP tool handler function that extracts accountId from request, calls Dynamics365.getAssociatedOpportunities, formats response as text content, handles errors.async (req) => { try { const response = await d365.getAssociatedOpportunities(req.accountId); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your input and try again.`, }, ], isError: true, }; } }
- src/tools.ts:75-75 (schema)Input schema using Zod: requires 'accountId' as string.{ accountId: z.string() },
- src/tools.ts:72-101 (registration)Registration of the 'get-associated-opportunities' tool via server.tool() with name, description, schema, and handler function.server.tool( "get-associated-opportunities", "Fetch opportunities for a given account from Dynamics 365", { accountId: z.string() }, async (req) => { try { const response = await d365.getAssociatedOpportunities(req.accountId); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your input and try again.`, }, ], isError: true, }; } } );
- src/main.ts:202-209 (helper)Helper method in Dynamics365 class implementing the core logic: OData query to fetch opportunities associated with the given accountId via _customerid_value filter.public async getAssociatedOpportunities(accountId: string): Promise<any> { if (!accountId) { throw new Error("Account ID is required to fetch opportunities."); } const endpoint = `api/data/v9.2/opportunities?$filter=_customerid_value eq ${accountId}`; return this.makeApiRequest(endpoint, "GET"); }