get-associated-opportunities
Fetch sales opportunities linked to a specific account in Dynamics 365 to analyze customer potential and track business deals.
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: fetches opportunities via Dynamics365 client, formats as JSON text response or error message.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: requires 'accountId' as string.{ accountId: z.string() },
- src/tools.ts:72-101 (registration)Registers the MCP tool 'get-associated-opportunities' with description, schema, and handler.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)Dynamics365 helper: validates accountId, builds OData filter query for opportunities, delegates to makeApiRequest.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"); }