Skip to main content
Glama
yigitkonur

example-mcp-server-stdio

by yigitkonur

Batch Calculate

batch_calculate

Perform multiple arithmetic calculations in a single request to process addition, subtraction, multiplication, and division operations efficiently.

Instructions

Perform multiple calculations in a single request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
calculationsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultsYes

Implementation Reference

  • The handler function for the 'batch_calculate' tool. It processes multiple calculations in batch, calling performBasicCalculation for each, creating history entries, handling individual errors without failing the entire batch, and returning structured results with both text content and detailed results array.
    async ({ calculations }) => {
      log.info(`Executing batch calculations: ${calculations.length} operations`);
      requestCount++;
    
      const results = [];
      for (const calc of calculations) {
        try {
          const result = performBasicCalculation(calc.op, calc.a, calc.b);
          const historyEntry = createHistoryEntry(calc.op, calc.a, calc.b, result);
          addToHistory(historyEntry);
    
          results.push({
            success: true as const,
            expression: historyEntry.expression,
            value: result,
            calculationId: historyEntry.id,
          });
        } catch (error) {
          // NOTE: This is an example of APPLICATION-LEVEL error handling.
          // Instead of throwing and failing the entire batch (a protocol-level error),
          // we catch the error for a single item. The tool itself still succeeds,
          // but its structured output contains the specific error information.
          // This gives the client detailed feedback on a per-item basis.
          results.push({
            success: false as const,
            expression: `${calc.a} ${calc.op} ${calc.b}`,
            error: error instanceof Error ? error.message : String(error),
          });
        }
      }
    
      return {
        content: [
          {
            type: 'text',
            text: results
              .map((r) => (r.success ? r.expression : `Error in ${r.expression}: ${r.error}`))
              .join('\n'),
          },
        ],
        structuredContent: { results },
      };
    },
  • Zod schemas defining the input (array of calculations with a, b, op, limited size) and output (array of results, each either success with value/expression/id or failure with error) for the batch_calculate tool.
    const batchCalculateInputSchema = {
      calculations: z
        .array(
          z.object({
            a: z.number(),
            b: z.number(),
            op: z.enum(['add', 'subtract', 'multiply', 'divide']),
          }),
        )
        .min(1)
        .max(LIMITS.maxBatchSize),
    };
    
    const batchCalculateOutputSchema = {
      results: z.array(
        z.discriminatedUnion('success', [
          z.object({
            success: z.literal(true),
            expression: z.string(),
            value: z.number(),
            calculationId: z.string(),
          }),
          z.object({
            success: z.literal(false),
            expression: z.string(),
            error: z.string(),
          }),
        ]),
      ),
    };
  • src/server.ts:400-451 (registration)
    The server.registerTool call that registers the 'batch_calculate' tool, specifying its name, title, description, input/output schemas, and the handler function.
    server.registerTool(
      'batch_calculate',
      {
        title: 'Batch Calculate',
        description: 'Perform multiple calculations in a single request',
        inputSchema: batchCalculateInputSchema,
        outputSchema: batchCalculateOutputSchema,
      },
      async ({ calculations }) => {
        log.info(`Executing batch calculations: ${calculations.length} operations`);
        requestCount++;
    
        const results = [];
        for (const calc of calculations) {
          try {
            const result = performBasicCalculation(calc.op, calc.a, calc.b);
            const historyEntry = createHistoryEntry(calc.op, calc.a, calc.b, result);
            addToHistory(historyEntry);
    
            results.push({
              success: true as const,
              expression: historyEntry.expression,
              value: result,
              calculationId: historyEntry.id,
            });
          } catch (error) {
            // NOTE: This is an example of APPLICATION-LEVEL error handling.
            // Instead of throwing and failing the entire batch (a protocol-level error),
            // we catch the error for a single item. The tool itself still succeeds,
            // but its structured output contains the specific error information.
            // This gives the client detailed feedback on a per-item basis.
            results.push({
              success: false as const,
              expression: `${calc.a} ${calc.op} ${calc.b}`,
              error: error instanceof Error ? error.message : String(error),
            });
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: results
                .map((r) => (r.success ? r.expression : `Error in ${r.expression}: ${r.error}`))
                .join('\n'),
            },
          ],
          structuredContent: { results },
        };
      },
    );
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions performing 'multiple calculations in a single request' which implies a batch operation, but doesn't disclose behavioral traits like error handling (e.g., if one calculation fails), performance characteristics, rate limits, authentication needs, or what the output looks like. For a tool with no annotations, this leaves significant gaps in understanding how it behaves.

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 extremely concise with a single sentence: 'Perform multiple calculations in a single request'. It's front-loaded with the core purpose, has zero waste, and every word earns its place. It's appropriately sized for a simple tool description.

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 has an output schema (which means return values are documented elsewhere), no annotations, and a simple input schema with one parameter, the description is minimally complete. It states what the tool does but lacks context about when to use it, behavioral details, or how it fits with siblings. For a batch calculation tool with output schema, it's adequate but has clear gaps in guidance and transparency.

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 adds no parameter semantics beyond what the input schema provides. Schema description coverage is 0%, but the description doesn't compensate by explaining the 'calculations' array structure, the meaning of 'a', 'b', 'op', or the enum values. However, since there's only one parameter (calculations array) and the schema is well-defined with properties and enums, the baseline is 3 as the schema does the heavy lifting despite 0% coverage.

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

Purpose3/5

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

The description states the tool's purpose as 'Perform multiple calculations in a single request', which is clear but vague. It specifies the verb 'perform' and resource 'calculations', but doesn't distinguish it from siblings like 'calculate' or 'advanced_calculate' beyond the batch aspect. The purpose is understandable but lacks specificity about what types of calculations or how it differs from alternatives.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer batch_calculate over calculate, advanced_calculate, or other sibling tools. There's no context about use cases, prerequisites, or exclusions. The agent must infer usage from the name alone.

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/yigitkonur/example-mcp-server-stdio'

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