Skip to main content
Glama
DynamicEndpoints

Microsoft 365 Core MCP Server

execute_graph_batch

Execute multiple Microsoft Graph API requests in a single batch operation to improve performance and efficiency.

Instructions

Execute multiple Microsoft Graph API requests in a single batch operation for improved performance and efficiency.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestsYes

Implementation Reference

  • Core handler function that executes multiple Microsoft Graph API requests in a batch using the /$batch endpoint. Validates input, constructs batch payload, sends request, and processes responses with success/error counts.
    async executeBatch(requests: BatchRequest[]): Promise<BatchResponse> {
      if (requests.length === 0) {
        throw new McpError(ErrorCode.InvalidParams, 'At least one request is required for batch operation');
      }
    
      if (requests.length > 20) {
        throw new McpError(ErrorCode.InvalidParams, 'Maximum 20 requests allowed per batch');
      }
    
      const batchPayload = {
        requests: requests.map((req, index) => ({
          id: req.id || index.toString(),
          method: req.method.toUpperCase(),
          url: req.url,
          headers: req.headers || {},
          body: req.body
        }))
      };
    
      try {
        const response = await this.graphClient
          .api('/$batch')
          .post(batchPayload);
    
        return {
          responses: response.responses,
          executedAt: new Date().toISOString(),
          totalRequests: requests.length,
          successCount: response.responses.filter((r: any) => r.status >= 200 && r.status < 300).length,
          errorCount: response.responses.filter((r: any) => r.status >= 400).length
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Batch operation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Zod schema for validating the input parameters of the execute_graph_batch tool, defining the structure of batch requests with validation for 1-20 requests.
    export const batchRequestSchema = z.object({
      requests: z.array(z.object({
        id: z.string().optional(),
        method: z.enum(['GET', 'POST', 'PATCH', 'PUT', 'DELETE']),
        url: z.string(),
        headers: z.record(z.string(), z.string()).optional(),
        body: z.any().optional()
      })).min(1).max(20)
  • MCP server tool registration for 'execute_graph_batch', which instantiates GraphAdvancedFeatures and calls executeBatch with validated args.
    // Batch Operations
    this.server.tool(
      "execute_graph_batch",
      "Execute multiple Microsoft Graph API requests in a single batch operation for improved performance and efficiency.",
      batchRequestSchema.shape,
      {"readOnlyHint":false,"destructiveHint":false,"idempotentHint":false},
      wrapToolHandler(async (args: any) => {
        this.validateCredentials();
        try {
          const advancedFeatures = new GraphAdvancedFeatures(this.getGraphClient(), this.getAccessToken.bind(this));
          const result = await advancedFeatures.executeBatch(args.requests);
          return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
        } catch (error) {
          if (error instanceof McpError) {
            throw error;
          }
          throw new McpError(
            ErrorCode.InternalError,
            `Error executing batch operation: ${error instanceof Error ? error.message : 'Unknown error'}`
          );
        }
      })
  • Tool metadata entry providing description, title, and annotations for the execute_graph_batch tool.
    execute_graph_batch: {
      description: "Execute multiple Microsoft Graph API requests in a single batch operation for improved performance and efficiency.",
      title: "Graph Batch Executor",
      annotations: { title: "Graph Batch Executor", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
  • TypeScript interfaces defining the input BatchRequest and output BatchResponse structures used by the executeBatch handler.
    export interface BatchRequest {
      id?: string;
      method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
      url: string;
      headers?: Record<string, string>;
      body?: any;
    }
    
    export interface BatchResponse {
      responses: Array<{
        id: string;
        status: number;
        headers: Record<string, string>;
        body: any;
      }>;
      executedAt: string;
      totalRequests: number;
      successCount: number;
      errorCount: number;
    }
Behavior3/5

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

Annotations indicate the tool is not read-only, idempotent, or destructive, but the description adds useful context: it specifies batch execution for performance/efficiency and mentions Microsoft Graph API scope. However, it lacks details on error handling, rate limits, authentication needs, or response format. No contradiction with annotations exists.

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, well-structured sentence that efficiently conveys the core functionality and benefit without redundancy. It is front-loaded with the main action and appropriately sized for the tool's complexity.

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

Completeness3/5

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

Given the tool's moderate complexity (batch API execution), lack of output schema, and annotations covering basic safety, the description is adequate but incomplete. It explains the what and why but omits details on response format, error behavior, or practical usage examples that would help an agent invoke it correctly.

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?

With 0% schema description coverage for the single parameter 'requests', the description does not add any parameter-specific information beyond what the schema provides (e.g., structure of requests array, method enums). The baseline is 3 since the schema fully documents the parameter, but the description fails to compensate for the coverage gap by explaining request format or constraints.

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 tool executes multiple Microsoft Graph API requests in a batch operation, specifying the verb ('execute'), resource ('Microsoft Graph API requests'), and benefit ('improved performance and efficiency'). It distinguishes from siblings like 'call_microsoft_api' by emphasizing batch capability, though it doesn't explicitly contrast with single-request alternatives.

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

Usage Guidelines3/5

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

The description implies usage context ('for improved performance and efficiency') suggesting batch operations when multiple requests are needed, but provides no explicit guidance on when to use this versus alternatives like 'call_microsoft_api' for single requests or other siblings. No exclusions or prerequisites are mentioned.

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/DynamicEndpoints/m365-core-mcp'

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