Cluster 9 · AI Agent & MCP Cost · MCPDiet · Token Budget

Cutting AI Agent / MCP Pre-Prompt Token Costs When Converting OpenAPI Specs to Tools

Why auto-generating MCP tools from bloated OpenAPI specs explodes LLM context bills (up to 16,424+ tokens/turn in our 100-server MCP study) and how to shrink schemas 60–80% without breaking agent tool calls.

Zero Telemetry · Strict CSP (connect-src 'none')

1. Paste OpenAPI Spec (Quick-Lint) & Controls

OAS 2.0 / 3.0 / 3.1 · OWASP API Top 10
Parsed YAML OpenAPI 3.0.3 · 2 ops · 2 {id} routes · 1 nullable: true · ~422 tok
OWASP API Top 10 & MCP Readiness Checklist (100 Points)
Moderate Schema / Auth Gaps
60 / 100 (D)
CONDITIONAL — FIX GAPS IN PR

Passing: 5 · Fixes Needed: 3 · Target: OpenAPI 3.1.0

Est. MCP Schema Tokens
6,450 tok
$29.03/mo at 50 turns/day ($3/1M)
Reclaimable Diet Savings
-3,575 tok
Saves $16.09/mo via MCPDiet
API2-AUTH (OWASP API2:2023): Explicit components.securitySchemes (Bearer JWT / OAuth2 scopes) + global/op security PASS
Bearer JWT / OAuth2 securitySchemes and security[] requirements are enforced.
API1-BOLA (OWASP API1:2023): Object-ID routes ({id}) enforce explicit 401/403 responses & tenant ownership scopes PASS
Parameterized {id} endpoints verify tenant ownership and document 401/403 status codes.
API3-BOPLA (OWASP API3:2023): additionalProperties: false + readOnly: true on server-owned fields (role, id, plan) CRITICAL FIX
Unbounded object schemas allow attackers to inject role, plan, or tenantId fields (OWASP API3 Mass Assignment / BOPLA).
API4-BOUNDS (OWASP API4:2023): maxLength, maxItems, maximum & bounded pagination (limit <= 100 / cursor) on inputs CRITICAL FIX
Unbounded arrays/strings and uncapped ?limit= queries expose memory/CPU DoS vectors (OWASP API4).
API8-TLS (OWASP API8:2023): HTTPS-only servers[] URLs (zero http:// prod) + strict CORS allowlist & headers PASS
Production servers[] enforce HTTPS-only URLs and strict origin allowlist CORS.
API4-429 (OWASP API4 / API8): Explicit 401, 403 & 429 Too Many Requests responses with Retry-After / X-RateLimit-* PASS
401, 403, and 429 Too Many Requests responses include Retry-After / X-RateLimit-* headers.
API9-INV (OWASP API9:2023): Versioned base paths + deprecated: true ops declare Sunset header & replacement path PASS
Deprecated endpoints publish Sunset headers and migration paths; zero shadow APIs.
MCP-TOKEN (AI / MCP Readiness): Concise tool descriptions (<= 120 tok/op) & OpenAPI 3.1 type arrays (no nullable: true) HIGH FIX
Verbose descriptions (~128 tok/op) and legacy nullable: true add ~3,575 wasted MCP pre-prompt tokens.
openapi-owasp-remediation.yaml
openapi: "3.1.0"
info:
  title: "OpenAPI -  MCP Agent Toolset"
  version: "1.0.0"
components:
  schemas:
    WorkspaceMemberCreateRequest:
      type: object
      additionalProperties: false
      required:
        - email
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        role:
          type: string
          readOnly: true
        email:
          type: string
          format: email
          maxLength: 254
        tags:
          type: array
          maxItems: 20
          items:
            type: string
            maxLength: 32
        nickname:
          type:
            - string
            - "null"
          maxLength: 64
paths:
  /v1/workspaces/{workspaceId}/members:
    get:
      operationId: listWorkspaceMembers
      description: List members for a tenant workspace.
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema:
            type: string
            format: uuid
            maxLength: 36
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
      responses:
        "200":
          description: Bounded member page
        "401":
          $ref: "#/components/responses/Unauthorized401"
        "403":
          $ref: "#/components/responses/Forbidden403"
        "429":
          $ref: "#/components/responses/TooManyRequests429"
Zero-Upload SpecDiff $49 Remediation PR

Audit Full OpenAPI Specs or Ship a Hardened PR Today

Run a 100% browser-side breaking-change diff, OWASP API Top 10 scan & SARIF 2.1.0 export on SpecDiff (https://spec.runglab.dev), order a $49 Done-For-You OpenAPI & MCP Remediation PR on Creem, or automate via POST /v1/openapi/audit (API Hub), remote MCP tool audit_openapi_spec, and Apify Cloud PPE.

OpenAPI Controls, Bounds & Verification Reference

Rule / Control Hardened Pattern Security & Token Rationale
Description Token Cap <= 30–40 words (<= 60 tok/tool) Strips changelog notes, curl examples & repeated parameter prose out of tool prompts
Endpoint Filtering Expose <= 10–15 task-scoped ops Never convert all 80 admin + CRUD routes into one always-on MCP toolset
Strict Object Schemas additionalProperties: false + enums Eliminates hallucinated keys and shrinks ambiguous deep `oneOf` unions
Empirical Benchmark Median 2,003 · P90 9,884 tok Across 100 live MCP servers, trimming bloated prose saved 26,356 tokens immediately

Before vs After: Lean MCP-Ready OpenAPI Operation Schema

mcp-lean-openapi.yaml
# BEFORE (~165 tokens — bloated prose + loose nested schema):
#   description: "This endpoint retrieves workspace metrics. In v1.x it used CSV, now JSON.
#     Example request: { workspaceId: '123' }. Never use legacy_metrics unless migrating..."
#   parameters: [{ name: filters, in: query, schema: { type: object } }]

# AFTER (~58 tokens — 65% smaller, strict bounds, zero LLM key hallucination):
paths:
  /v1/workspaces/{workspaceId}/metrics:
    get:
      operationId: getWorkspaceMetrics
      description: Fetch tenant usage metrics for a bounded date window.
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema: { type: string, format: uuid, maxLength: 36 }
        - name: days
          in: query
          schema: { type: integer, minimum: 1, maximum: 90, default: 30 }
      responses:
        "200": { description: Usage metrics }
        "401": { description: Unauthorized }
        "403": { description: Forbidden }
        "429": { description: Rate limited }

Model Token Cost & Audit OpenAPI -> MCP Bloat

mcp-token-audit.sh
# 1. Price monthly token burn across 8 frontier LLMs:
#    https://tools.runglab.dev/mcp-cost/
# 2. Read RungLab's 100-server live MCP audit (median 2,003 / P90 9,884 / max 16,424 tok):
#    https://tools.runglab.dev/research/mcp-100-servers-context-tax/
# 3. Call dev.runglab/devtools MCP tool audit_openapi_spec or SpecDiff:
#    https://spec.runglab.dev

Key Engineering Takeaways

  • Auto-converting a 40-endpoint OpenAPI file directly into an MCP server injects 8,000–16,000+ schema tokens on every single agent turn — costing $40–$75+/seat/month on frontier LLMs before a single user message.
  • In RungLab's 100-server MCP benchmark, 54.5% of servers omitted `additionalProperties: false` and bloated >120-token descriptions accounted for massive wasted context.
  • Trimming operation descriptions to 1 clear imperative sentence, replacing loose objects with strict typed properties, and scoping read/write tool profiles cuts pre-prompt overhead by 60–80% while improving tool-call accuracy.

Common Contract Pitfalls to Avoid

  • Pasting multi-paragraph marketing docs, curl snippets, and legacy deprecation lore into OpenAPI `description:` fields fed to LLMs.
  • Exposing destructive `DELETE` or admin billing endpoints to unauthenticated/read-only MCP agent profiles.
  • Leaving `nullable: true` or huge `oneOf` discriminators that confuse LLM structured-output decoders.

More OpenAPI OWASP & MCP Optimization Guides

← Back to OpenAPI OWASP & MCP Scorer Hub · 2026 N=26 OpenAPI & MCP Benchmark → · MCP Context Token Cost Calculator → · CORS Preflight & Webhook HMAC Debugger → · SpecDiff Live Diff & SARIF → · $49 Remediation PR →

Frequently Asked Questions

How many tokens should a single OpenAPI-derived MCP tool consume?

Aim for ~50–120 tokens total per tool (concise 10–25 word description + typed properties with `additionalProperties: false`). Keeping a 10-tool profile under 1,800 tokens earns Grade A on MCPDiet.

How does RungLab's own Official MCP Server score on token efficiency?

Our live server `dev.runglab/devtools` v1.2.0 exposes 7 read-only tools (including `audit_openapi_spec`) in just 1,789 schema tokens — earning 100/100 Grade A on MCPDiet.

Where can I price the dollar savings of trimming OpenAPI -> MCP schemas?

Compare live monthly spend across 8 LLMs on our Cluster 3 MCP Cost Calculator (/mcp-cost/) and run an OpenAPI token audit on https://spec.runglab.dev.