Skip to content

OpenAPI as the Source of Truth for Agent Tool Definitions

Use existing OpenAPI 3.x specs as the source of truth for agent tool definitions — generating tool schemas, descriptions, and parameter constraints from API documentation instead of writing them by hand.

The Mapping

OpenAPI operation objects map directly to agent tool schema fields:

OpenAPI Field Tool Schema Field Notes
operationId name Use action-oriented IDs like createTask, not post-task-endpoint
summary / description description Often needs rewriting for agents (see below)
parameters + requestBody parameters / input_schema / inputSchema JSON Schema objects translate directly
Response schemas Output documentation Agents need to know what data structures to expect

This mapping means a team maintaining an OpenAPI spec already has most of a tool definition's structure — names, parameter schemas, types, and constraints transfer directly. The remaining work is description quality.

Generating MCP Servers from OpenAPI

An ecosystem of tooling converts OpenAPI specs to functional MCP servers. The AutoMCP research showed that static code generation from OpenAPI produces MCP servers where 76.5% of tool calls succeed out of the box, reaching 99.9% after averaging 19 lines of spec changes per API.

Common generators include:

The recommended workflow: autogenerate the groundwork from OpenAPI, then curate by enriching descriptions for agent consumption.

Curation is not optional. Exposing every endpoint as an individual tool without filtering is a recognized anti-pattern: an API with 200 endpoints becomes 200 tools, burning context-window space and producing tool selection failures. Practitioners at GitHub Copilot and Block cut their tool counts by 60–93% before seeing reliable agent behavior. The generation step reduces boilerplate; the curation step — selecting which operations to surface and how to group them — determines whether the resulting server is usable. See MCP tool design guidance and semantics-first MCP design for practitioner evidence.

Description Quality Gap

OpenAPI descriptions written for human developers frequently underperform for agents. A description like "Retrieve a task by ID" tells a human enough; an agent needs to know when to call this endpoint versus alternatives, what the response contains, and what edge cases to expect.

Agent-optimized descriptions should include:

  • When to use this tool versus alternatives
  • Expected parameter formats (e.g., "UUID v4, not integer ID")
  • What the response contains and what an empty result means
  • Error conditions and what they indicate

This is the same principle Anthropic describes for agent-computer interface design: tool descriptions need the same care as human-facing UX.

The Arazzo Layer

Arazzo is a companion specification that defines deterministic multi-step workflows across OpenAPI-described APIs. Where OpenAPI describes individual endpoints, Arazzo describes how to chain them to complete a business outcome.

For agents, Arazzo provides a machine-readable workflow plan that eliminates the need for an LLM to reason about API call ordering. The upcoming Arazzo 1.1.0 release plans to introduce AsyncAPI support, enabling workflows that span both HTTP and event-driven protocols.

Versioning and Sync

When an API changes, the tool schema must change with it. Teams using OpenAPI as the tool source can enforce this through CI:

  1. Generate tool schemas from the OpenAPI spec on every build
  2. Diff generated schemas against committed schemas
  3. Fail the build if they diverge

This prevents the common failure where a tool definition references a deprecated parameter or missing endpoint.

When Not to Use OpenAPI

OpenAPI covers HTTP APIs exclusively. These tool types need manual schemas:

  • File system operations
  • Shell commands and CLI tools
  • In-process function calls
  • Database queries
  • Hardware or device interactions

For non-HTTP tools, write tool schemas directly using JSON Schema.

Example

An OpenAPI operation for retrieving a task:

paths:
  /tasks/{taskId}:
    get:
      operationId: getTaskById
      summary: Retrieve a task by ID
      parameters:
        - name: taskId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Task object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Task'
        '404':
          description: Task not found

The auto-generated MCP tool definition preserves the structure but needs enriched descriptions for agent consumption:

{
  "name": "getTaskById",
  "description": "Retrieve a task by its UUID. Use this when you need the current state of a specific task — not for listing or searching tasks. Returns the full Task object including status, assignee, and timestamps. Returns 404 if the taskId does not exist; do not retry with a modified ID.",
  "input_schema": {
    "type": "object",
    "properties": {
      "taskId": {
        "type": "string",
        "format": "uuid",
        "description": "UUID v4 of the task, e.g. '550e8400-e29b-41d4-a716-446655440000'. Not an integer ID."
      }
    },
    "required": ["taskId"]
  }
}

The operationId becomes the tool name, the parameter schema transfers directly, and the description is rewritten to include when-to-use context, format constraints, and 404 semantics.

Key Takeaways

  • OpenAPI operationId, description, and parameter schemas map directly to agent tool definitions — use the spec as the single source of truth.
  • Auto-generated MCP servers from OpenAPI reach ~77% success out of the box and ~100% after minor spec refinements.
  • Descriptions written for human developers need rewriting for agents: add usage context, format constraints, and edge case behavior.
  • Arazzo adds deterministic multi-step workflow definitions on top of OpenAPI, reducing agent reasoning overhead.
  • OpenAPI only covers HTTP APIs; non-HTTP tools require manual schema definitions.
Feedback