Labsco
EliFuzz logo

API Docs MCP

β˜… 2

from EliFuzz

MCP server for API documentation, supporting GraphQL, OpenAPI/Swagger, and gRPC from local files or remote URLs

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

API Docs MCP

Model Context Protocol (MCP) server that provides tools for interacting with API documentation. Supports GraphQL, OpenAPI/Swagger, and gRPC specifications, fetching schema definitions from various sources (local files or remote URLs), caching them, and exposing them through a set of tools.

Table of Contents

MCP Platforms

mcp.so

Features

  • Dynamic Tool Registration: Automatically discovers and registers tools from a specified directory.
  • API Documentation Retrieval: Provides tools to list available API methods (api_docs) and retrieve detailed documentation for specific methods (api_search).
  • Schema Caching: Caches API schema information to reduce redundant fetches and improve performance.
  • Multiple Source Support:
    • GraphQL: Supports loading GraphQL schemas from graphql / gql files or json introspection results (local files or remote URLs).
    • OpenAPI/Swagger: Supports loading OpenAPI/Swagger yaml / yml / json schemas from local files or remote URLs.
    • gRPC: Supports loading gRPC schemas from proto files or via gRPC reflection from remote URLs.
  • Environment-based Configuration: Configures API sources via the API_SOURCES environment variable, allowing flexible deployment and management.
  • Automatic Cache Refresh: Periodically refreshes cached schema data to ensure up-to-date documentation.

Example Use Cases

OpenAPI Petstore retrieval docs

<video src="https://github.com/user-attachments/assets/e2d73c08-7b4b-4157-bd17-aaf3090f67ec" width="100%" controls></video>

GraphQL retrieval docs

<video src="https://github.com/user-attachments/assets/c597015a-ee9f-4f2d-a332-1f1785d88c86" width="100%" controls></video>

Multiple Sources retrieval docs

<video src="https://github.com/user-attachments/assets/3bf7724e-bc74-46c5-9e57-919ea2ec7b52" width="100%" controls></video>

Architecture

The api-docs-mcp project is designed as an MCP server that integrates with various API documentation sources.

graph TD
    mcpServer[MCP Server] e1@--> tools(Tools:<br/>api_docs / api_search);
    tools e2@--> cacheManager{Cache Manager};
    cacheManager e3@--> configuration[Configuration:<br/>API_SOURCES env var];
    configuration e4@--> schemaSources{Schema Sources};
    schemaSources e5@-- FileSource--> localFiles(Local Files:<br/>.graphql, .json, .yaml, .proto);
    schemaSources e6@-- UrlSource--> remoteUrls(Remote URLs:<br/>GraphQL Endpoints, OpenAPI/Swagger Endpoints, gRPC Endpoints);
    localFiles e7@--> processor[Schema Processors];
    remoteUrls e8@--> processor;
    processor e9@--> cacheManager;
    processor e10@--> openAPIProcessor(OpenAPI Processor:<br/>OpenAPI/Swagger);
    processor e11@--> graphQLProcessor(GraphQL Processor);
    processor e12@--> grpcProcessor(gRPC Processor)
    cacheManager e13@--Cached Data--> tools;

    subgraph Core Components
        mcpServer
        tools
        cacheManager
        configuration
    end

    subgraph Data Flow
        schemaSources
        localFiles
        remoteUrls
        processor
        openAPIProcessor
        graphQLProcessor
        grpcProcessor
    end

    e1@{ animate: true }
    e2@{ animate: true }
    e3@{ animate: true }
    e4@{ animate: true }
    e5@{ animate: true }
    e6@{ animate: true }
    e7@{ animate: true }
    e8@{ animate: true }
    e9@{ animate: true }
    e10@{ animate: true }
    e11@{ animate: true }
    e12@{ animate: true }
    e13@{ animate: true }

Flow of Operations:

  1. Server Initialization: The index.ts entry point initializes the MCP server and dynamically registers tools defined in the src/tools directory.
  2. Configuration Loading: The CacheManager loads API source configurations from the API_SOURCES environment variable via src/utils/config.ts.
  3. Schema Fetching & Caching:
    • Based on the configured sources (file-based or URL-based), the CacheManager fetches API schemas.
    • For file sources, it reads local files (graphql, gql, json, yaml, yml, proto).
    • For URL sources, it makes HTTP requests to GraphQL, OpenAPI, or gRPC endpoints.
    • Schemas are then processed by specialized handlers (src/api/api.ts for OpenAPI, src/gql/gql.ts for GraphQL, src/grpc/grpc.ts for gRPC).
    • The processed documentation is stored in an in-memory cache (src/utils/cache.ts) with a specified TTL (Time-To-Live).
    • The cache is periodically refreshed.
  4. Tool Usage:
    • api_docs: When invoked, this tool retrieves a list of all available API resources from the cache, filtered by source if provided.
    • api_search: When invoked with a detailName, this tool provides detailed documentation (request, response, error structures) for a specific API resource from the cache.

Development

Running the Server Locally

  1. Set the API_SOURCES environment variable as described in the Configuration section.

  2. Start the server:

    pnpm start

The server will connect to a StdioServerTransport, meaning it will communicate over standard input/output.

Project Structure

.
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ api/ # OpenAPI/Swagger schema processing
β”‚ β”‚ └── api.ts
β”‚ β”œβ”€β”€ gql/ # GraphQL schema processing
β”‚ β”‚ └── gql.ts
β”‚ β”œβ”€β”€ grpc/ # gRPC schema processing
β”‚ β”‚ └── grpc.ts
β”‚ β”œβ”€β”€ tools/ # MCP tools definitions
β”‚ β”‚ β”œβ”€β”€ api_docs.ts
β”‚ β”‚ └── api_search.ts
β”‚ β”œβ”€β”€ utils/ # Utility functions (cache, config, fetch, file, source)
β”‚ β”‚ β”œβ”€β”€ cache.ts
β”‚ β”‚ β”œβ”€β”€ config.ts
β”‚ β”‚ β”œβ”€β”€ fetch.ts
β”‚ β”‚ β”œβ”€β”€ file.ts
β”‚ β”‚ └── source.ts
β”‚ β”œβ”€β”€ index.ts # Main entry point
β”‚ └── server.ts # MCP server setup and tool registration
└── package.json # Project dependencies and scripts
└── README.md # This file

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.