Skip to main content
Glama

get-associated-opportunities

Fetch sales opportunities linked to a specific account in Dynamics 365 to track potential deals and manage customer relationships.

Instructions

Fetch opportunities for a given account from Dynamics 365

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYes

Implementation Reference

  • src/tools.ts:72-101 (registration)
    Registration of the 'get-associated-opportunities' tool, including input schema { accountId: z.string() } and inline handler function that calls d365.getAssociatedOpportunities and returns formatted JSON response or error.
    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,
          };
        }
      }
    );
  • Core handler logic in Dynamics365 class: validates accountId, constructs OData endpoint to filter opportunities by _customerid_value eq accountId, and calls makeApiRequest to fetch from Dynamics 365 API.
    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");
    }
  • Helper method in Dynamics365 class that handles authentication, constructs full API URL, sets headers, makes fetch request to Dynamics 365 API, and processes response or error.
    private async makeApiRequest(
      endpoint: string,
      method: string,
      body?: any,
      additionalHeaders?: Record<string, string>
    ): Promise<any> {
      const token = await this.authenticate();
      const baseUrl = this.d365Url.endsWith("/")
        ? this.d365Url
        : `${this.d365Url}/`;
      const url = `${baseUrl}${endpoint}`;
    
      const headers: Record<string, string> = {
        Authorization: `Bearer ${token}`,
        Accept: "application/json",
        "Content-Type": "application/json",
        "OData-MaxVersion": "4.0",
        "OData-Version": "4.0",
        ...additionalHeaders,
      };
    
      try {
        const response = await fetch(url, {
          method,
          headers,
          body: body ? JSON.stringify(body) : undefined,
        });
    
        if (!response.ok) {
          throw new Error(
            `API request failed with status: ${
              response.status
            }, message: ${await response.text()}`
          );
        }
    
        return await response.json();
      } catch (error) {
        console.error(`API request to ${url} failed:`, error);
        throw new Error(
          `Failed to make API request: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool fetches data, implying a read-only operation, but lacks details on permissions, rate limits, error handling, or output format. This is a significant gap for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and appropriately sized for a simple tool, earning full marks for conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations, output schema, and low schema description coverage, the description is incomplete. It doesn't address behavioral aspects like safety, performance, or return values, leaving gaps that could hinder an AI agent's effective use of the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'for a given account,' which aligns with the 'accountId' parameter in the schema. However, with 0% schema description coverage and only one parameter, the description adds minimal meaning beyond the schema's structure. It doesn't explain the format or constraints of 'accountId,' so it meets the baseline for low parameter count.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('fetch') and resource ('opportunities for a given account from Dynamics 365'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'fetch-accounts' or 'get-user-info', which could involve related data but different resources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description implies it's for fetching opportunities linked to an account, but it doesn't specify prerequisites, exclusions, or compare it to other tools that might handle opportunities or accounts differently.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/srikanth-paladugula/mcp-dynamics365-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server