DEV Community

Cover image for Cursor + MCP Server: AI-Powered API Documentation as Code
Theodore
Theodore

Posted on

3 2 3 3 3

Cursor + MCP Server: AI-Powered API Documentation as Code

Introduction: Bridging AI with Live API Specifications

In modern software development, APIs have become the lingua franca for system communication, while AI-assisted programming is fundamentally transforming our development workflows.

By integrating Apidog MCP Server with AI-powered IDEs like Cursor and VSCode + Cline, we've established a groundbreaking workflow: Enabling AI to directly read, comprehend, and leverage up-to-date API specifications - effectively implementing the "API Documentation as Code" paradigm.

This article details how I connected Apidog MCP Server with Cursor, demonstrating how this integration significantly enhances development efficiency, accuracy, and consistency.

What is Apidog MCP Server?

MCP (Model Context Protocol) is a protocol that enables AI systems to interact with external data sources. Think of it as a standardized endpoint for AI applications to connect various data sources and tools.

Apidog MCP Server allows developers to expose API documentation from Apidog projects as a data source for AI-enabled IDEs like Cursor. This direct access empowers AI assistants to:

  • Generate or modify code based on API specs

  • Search API documentation content

  • Perform context-aware operations

The possibilities are limited only by your team's creativity.

Cursor + MCP Server: AI-Powered API Documentation as Code

Configuring Apidog MCP Server in Cursor

1. Prerequisites

  • Node.js environment (≥ v18, LTS recommended)

  • Latest Cursor version

  • Accessible Apidog project

2. Obtaining Credentials

2.1 Get Apidog Access Token

  • Open Apidog application

  • Hover over profile avatar → "Account Settings → API Access Token"

  • Create and save new API access token

Cursor + MCP Server: AI-Powered API Documentation as Code

2.2 Get Apidog Project ID

  • Open target Apidog project

  • Click "Settings" in left sidebar

  • Copy Project ID from "Basic Settings"

Cursor + MCP Server: AI-Powered API Documentation as Code

3. Configuring MCP Settings

Two configuration approaches: Global (recommended) or Project-specific.

Method 1: Global Configuration

1. In Cursor: Click settings icon → MCP → "+ Add new global MCP server"

Cursor + MCP Server: AI-Powered API Documentation as Code

2. In the opened mcp.json file, add the following configuration, replacing <access-token> and <project-id> with your actual values.

{
  "mcpServers": {
    "API specification": {
      "command": "npx",
      "args": [
        "-y",
        "apidog-mcp-server@latest",
        "--project-id=<project-id>"
      ],
      "env": {
        "APIDOG_ACCESS_TOKEN": "<access-token>"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Windows users may need:

{
  "mcpServers": {
    "API specification": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "-y",
        "apidog-mcp-server@latest",
        "--project-id=<project-id>"
      ],
      "env": {
        "APIDOG_ACCESS_TOKEN": "<access-token>"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Method 2: Project-specific Configuration

  • Create .cursor folder in project root

  • Add mcp.json with same configuration

  • Use the same configuration as above

4. Verifying MCP Connection

Test with AI prompt in Agent mode:

"Fetch API documentation via MCP and list the number of endpoints"

Successful API information retrieval confirms proper setup.

Cursor + MCP Server: AI-Powered API Documentation as Code

Real-World Use Cases: Supercharging AI + API Development

Case 1: Rapid Model Generation

For an e-commerce app with product APIs:

  1. Create new Cursor project

  2. Prompt:

"Fetch product APIs via MCP and generate complete TypeScript endpoints with service classes"

AI will:

  • Analyze API structure

  • Generate compliant code

Sample output:

Cursor + MCP Server: AI-Powered API Documentation as Code

Case 2: Documentation-Code Synchronization

After adding discountPrice field in Apidog:

Prompt:

"Refresh MCP cache and update Product endpoint with new fields"

AI updates:

discountPrice?: number; // New field
Enter fullscreen mode Exit fullscreen mode

Case 3: CRUD Generation

Prompt:

"Generate complete Spring Boot MVC code for user management per API docs"

AI produces compliant controllers/services/repositories.

Case 4: API Documentation Q&A

Prompt:

"Explain payment-related endpoints and their workflow"

AI analyzes and explains payment flow.

Case 5: Automated Test Generation

Prompt:

"Generate Jest tests for product creation endpoint using MCP docs"

AI creates test cases covering edge conditions.

Pro Tips & Best Practices

Multi-Project Management

Configure multiple MCP servers:

{
  "mcpServers": {
    "Mall API Documentation": {
      "command": "npx",
      "args": [
        "-y",
        "apidog-mcp-server@latest",
        "--project=123456"
      ],
      "env": {
        "APIDOG_ACCESS_TOKEN": "<access-token>"
      }
    },
    "CRM API Documentation": {
      "command": "npx",
      "args": [
        "-y",
        "apidog-mcp-server@latest",
        "--project=123456"
      ],
      "env": {
        "APIDOG_ACCESS_TOKEN": "<access-token>"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Specify context:

"Use CRM API Documentation to generate order management code"

Security Practices

To prevent exposing the Access Token in team collaboration:

  • Remove the "APIDOG_ACCESS_TOKEN": "<access-token>" line from configuration files.

  • Set the APIDOG_ACCESS_TOKEN environment variable on each developer's system.

Tips for Improving AI Response Quality

  • Specify the required documentation section: e.g., "Please refer to the API documentation for the user module."

  • Define coding style and conventions: e.g., "Generate code following our team's TypeScript naming conventions."

  • Request comments: e.g., "When generating code, add detailed JSDoc comments for each method."

  • Break tasks into steps: For complex tasks, first ask the AI to outline a plan, then execute step by step.

Conclusion

The Apidog MCP Server + Cursor integration delivers an unprecedented API development experience by enabling:

  1. Dramatically reduced spec-to-code time

  2. Fewer human errors

  3. Faster iteration cycles

  4. Enhanced code quality

As Apidog MCP Server evolves, developers can expect more powerful API workflow optimizations. This AI-API synergy represents a significant productivity leap for both frontend and backend developers.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️