HUB
Sign inSign up
openapi-context logo

djankies/openapi-context

By djankies

โ€ขUpdated over 1 year ago

MCP server with tools for efficient querying of OpenAPI specifications

Image
Developer tools
0

1.9K

djankies/openapi-context repository overview

โ OpenAPI Context MCP Server

Stop drowning your LLM in API documentation. This MCP server gives LLMs intelligent, progressive access to OpenAPI specs without overwhelming their context windows.

โ ๐Ÿš€ Quick Start

{
  "openapi-context": { // name it whatever you want
    "command": "docker",
    "args": [
      "run", "--rm", "-i",
      "-v", "/path/to/your/openapi.yaml:/app/spec:ro", // filepath + :/app/spec:ro
      "djankies/openapi-context:latest"
    ]
  }
}

That's it. Your LLM now has API hotwheels.

โ ๐ŸŽฏ Why This Exists

I wanted to create a tool that was more effective at helping LLMs efficiently navigate and retrieve laser-scoped information from OpenAPI specs without overwhelming their context windows. LLMs start with high-level overviews, then drill down only into what they need, being naturally guided by the tools the whole way.

โ The Problem
  • ๐Ÿ“„ Full OpenAPI specs can be 1000s of lines
  • ๐Ÿคฏ LLMs get overwhelmed with unnecessary details
  • ๐Ÿ’ธ Wastes context tokens on irrelevant information
  • ๐Ÿ”„ LLMs don't know how to use openapi tools correctly
โ The Solution
  • ๐Ÿ” Progressive exploration that guides LLMs naturally
  • ๐Ÿง  Built-in intelligence that helps LLMs make correct tool choices
  • ๐Ÿ“ฆ Automatic simplification without losing essential information
  • ๐ŸŽฏ Error messages that guide LLMs to the right next step

โ โœจ Key Features for LLM Success

โ ๐Ÿง  Intelligent LLM Guidance

Every tool description is dynamically generated to include context about the loaded API:

list_operations: "List all endpoints from Petstore API v1.0.0"
get_operation_details: "Get details for operations in Petstore API v1.0.0"

Every error includes the exact next step:

**Operation Not Found**

Operation not found: createUser

๐Ÿ’ก Use `list_operations()` to see available operations or call `help()` for usage guidance.

The tool design naturally guides LLMs through efficient exploration:

  1. list_tags โ†’ See API structure
  2. get_operation_summary โ†’ Quick overview without schemas
  3. get_request_schema โ†’ Details only when needed
โ ๐Ÿ“Š Context-Efficient Design
// LLM can request minimal info
get_operation_details({ operation_id: "createUser", detail_level: "minimal" })

// Or specific fields only
get_operation_details({ operation_id: "createUser", fields: ["parameters"] })

// Or compact schemas
get_request_schema({ operation_id: "createUser", compact: true })
// Returns: "Type: object { name: string, email: string (email) }"
โ ๐Ÿ”„ Never Get Stuck

Helpful Parameter Validation:

**Missing Parameters**

Please provide either `operation_id` or both `method` and `path`.

๐Ÿ’ก Need help with tool usage? Call the `help` tool for detailed parameter guidance.

Built-in Health Check:

The ping helps the llm verify the server is actually responsive when receiving errors, preventing extraneous calls to the tool when the server is not running.

**Server Status**

Status: Ready
OpenAPI Spec: Loaded (Petstore API v1.0.0)
Ready to process queries.

โ ๐Ÿ›  Available Tools

โ Discovery Tools (LLMs Start Here)
  • ๐Ÿท๏ธ list_tags - See API categories with operation counts
  • ๐Ÿ“œ list_operations - List endpoints with filtering and compact mode
  • ๐Ÿ” search_operations - Find endpoints by keyword
  • ๐Ÿ“‹ get_operation_summary - Quick overview without full schemas
โ Detail Tools (Use When Needed)
  • ๐Ÿฉป get_operation_details - Full endpoint info with customizable detail levels
  • ๐Ÿ“ค get_request_schema - Request schemas with pagination and compact mode
  • ๐Ÿ“ฅ get_response_schema - Response schemas by status code
  • ๐Ÿ“ get_operation_examples - Example payloads when available
  • ๐Ÿ” get_auth_requirements - Authentication details with examples
  • โ„น๏ธ get_server_info - API metadata and statistics
โ Utility Tools
  • ๐Ÿ›œ ping - Check server responsiveness
  • โ“ help - Comprehensive guidance with current context

โ ๐Ÿ“– How LLMs Navigate Efficiently

โ Natural Discovery Pattern
// 1. Understand API structure (3 lines)
list_tags()
// โ†’ "Users (12 operations), Orders (8 operations), Auth (3 operations)"

// 2. Find relevant operations (10 lines)
list_operations({ filter: "Users", compact: true })
// โ†’ "GET /users - List users\nPOST /users - Create user..."

// 3. Get overview before diving deep (5 lines)
get_operation_summary({ operation_id: "createUser" })
// โ†’ "POST /users\nParameters: body: required\nRequired: name, email\nAuth: api_key"

// 4. Get details only when needed (1 line with compact mode)
get_request_schema({ operation_id: "createUser", compact: true })
// โ†’ "Type: object { name: string, email: string (email), age?: number }"
โ Adaptive Detail Levels

The server provides three detail levels that LLMs can choose based on their needs:

  • minimal: Just operation signatures and required fields
  • standard: Simplified schemas without patterns (default)
  • full: Complete details including patterns and examples
โ Automatic Pagination Handling

When schemas are large, LLMs receive clear continuation instructions:

Page 1 of 3 (showing 0-2000 of 5432 chars)
...content...
Use index=2000 to continue reading.

โ ๐Ÿณ Docker Configuration

โ Basic Setup
{
  "openapi-context": {
    "command": "docker",
    "args": [
      "run", "--rm", "-i",
      "-v", "/path/to/your/spec.yaml:/app/spec:ro",
      "djankies/openapi-context:latest"
    ]
  }
}
โ Multiple APIs

Each API gets its own instance with dedicated tool contexts:

{
  "users-api": {
    "command": "docker",
    "args": [
      "run", "--rm", "-i",
      "-v", "/path/to/users-api.yaml:/app/spec:ro",
      "djankies/openapi-context:latest"
    ]
  },
  "orders-api": {
    "command": "docker",
    "args": [
      "run", "--rm", "-i",
      "-v", "/path/to/orders-api.yaml:/app/spec:ro",
      "djankies/openapi-context:latest"
    ]
  }
}
โ Environment Variables
VariableDescriptionDefault
LOG_LEVELLogging verbosity (error, warn, info, debug)info
MAX_SPEC_SIZEMaximum OpenAPI spec file size in MB10
MCP_MODEServer mode (stdio for MCP, http for debugging)stdio

โ ๐Ÿงช HTTP Mode (Development & Debugging)

Test the server independently:

docker run --rm -p 3000:3000 \
  -e MCP_MODE=http \
  -v "/path/to/spec.yaml:/app/spec:ro" \
  djankies/openapi-context:latest

Access health check at http://localhost:3000/health

โ ๐Ÿ— Development

# Install dependencies
npm install

# Run tests
npm test

# Development mode
npm run dev

# Full CI pipeline
npm run ci

โ ๐Ÿ“‹ Supported Formats

  • OpenAPI 3.1 specifications
  • File extensions: .yaml, .yml, .json
  • Auto-detects format from content

โ ๐Ÿ“ License

MIT License - see LICENSEโ  file for details.

Tag summary

Content type

Image

Digest

sha256:95eaf6534โ€ฆ

Size

78.2 MB

Last updated

over 1 year ago

docker pull djankies/openapi-context