DEV Community

Cover image for How to Build APIs with Cursor Composer 2.5
Hassann
Hassann

Posted on • Originally published at apidog.com

How to Build APIs with Cursor Composer 2.5

Cursor Composer 2.5 is fast and cheap enough to generate API clients, route handlers, and integration code for you. The failure mode appears when generated code hits a real service: Composer may write a clean request to /v2/orders while your API exposes /orders and expects a different payload. The code compiles, but the integration fails later.

Try Apidog today

This guide shows an implementation workflow to prevent that: connect Composer 2.5 to your real API specification through MCP, generate code against the actual contract, then verify the generated requests in Apidog before a teammate depends on them. If you’re new to the model, the Cursor Composer 2.5 guide covers what it is and how to access it.

Why agentic models guess API shapes

Composer 2.5 is designed for long, multi-step agent tasks. You can ask it to:

“Add a client for our billing service and wire it into the checkout flow.”

It can plan the change, edit multiple files, run tests, and iterate. That is the practical upgrade over Composer 2.

The problem is context. If the model does not have your API contract, it fills in gaps with likely patterns:

  • Common REST paths
  • Common field names
  • Common auth conventions
  • Version prefixes it has seen elsewhere

That produces code that looks right but fails against your service.

Typical symptoms:

  • Endpoint mismatch: /api/users/{id} instead of /users/{userId}
  • Invented or incorrect request fields
  • Generic auth logic instead of your actual scheme
  • Response handling that does not match your real schema

You can paste OpenAPI snippets into chat, but that does not scale. It burns context, gets stale quickly, and is easy to omit. A better approach is to give Composer structured access to the source-of-truth spec.

The fix: ground Composer 2.5 in your real API spec via MCP

Model Context Protocol, or MCP, lets AI tools access external systems and structured data. Cursor supports MCP servers, and the Apidog MCP server exposes your Apidog API specification to Composer.

Instead of guessing, Composer 2.5 can query your actual:

  • Endpoints
  • Path and query parameters
  • Request body schemas
  • Response schemas
  • Auth requirements
  • Error responses

This is the same idea behind vibe coding with the Apidog MCP server, applied to API implementation work.

Step 1: prepare your API spec in Apidog

First, make sure your API contract is accurate in Apidog.

You can:

  • Design the API directly in Apidog
  • Import an OpenAPI specification
  • Import a Postman collection
  • Maintain endpoints, schemas, examples, and auth details in one place

Composer will only be as accurate as the contract it reads. Before connecting MCP, check that the relevant endpoint definitions are current.

For example, if Composer will generate an orders client, verify that Apidog has the correct:

  • POST /orders
  • GET /orders/{orderId}
  • Required headers
  • Request body fields
  • Success responses
  • Validation error responses

Step 2: connect the Apidog MCP server to Cursor

Cursor reads MCP servers from a project config file, commonly:

.cursor/mcp.json
Enter fullscreen mode Exit fullscreen mode

A typical Apidog MCP configuration looks like this:

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

Use the exact command, project ID, and token from the Apidog MCP setup walkthrough, because those values are specific to your Apidog account and the current server setup.

After saving the file, restart Cursor so it loads the MCP server.

Step 3: confirm Composer 2.5 can read the spec

Before asking Composer to write code, test the MCP connection with a read-only prompt.

In Cursor:

  1. Open an agent session.
  2. Select composer-2.5 in the model picker.
  3. Ask Composer to inspect the spec.

Example prompt:

Using the apidog-api-spec MCP server, list the endpoints under the orders resource and the required fields for creating an order.
Enter fullscreen mode Exit fullscreen mode

Expected result:

  • Composer returns endpoints from your actual Apidog project.
  • It lists real request fields from your schema.
  • It does not answer with generic REST assumptions.

If it gives a generic answer, the MCP server is not wired in correctly. Recheck:

  • .cursor/mcp.json
  • Project ID
  • Access token
  • Server name used in the prompt
  • Whether Cursor was restarted after config changes

Step 4: generate code against the contract

Once Composer can read the spec, give it an implementation task and explicitly name the MCP source.

Example prompt:

Using the apidog-api-spec server as the source of truth, write a typed TypeScript client for the orders API.

Include:
- createOrder
- getOrder

Requirements:
- Match the request and response schemas exactly.
- Use the required auth headers from the spec.
- Add error handling for the 422 validation response defined in the spec.
- Do not invent fields or endpoints.
Enter fullscreen mode Exit fullscreen mode

A generated client might have a shape like this:

type ApiClientOptions = {
  baseUrl: string;
  token: string;
};

export class OrdersClient {
  constructor(private readonly options: ApiClientOptions) {}

  async createOrder(input: CreateOrderRequest): Promise<CreateOrderResponse> {
    const response = await fetch(`${this.options.baseUrl}/orders`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${this.options.token}`,
      },
      body: JSON.stringify(input),
    });

    if (response.status === 422) {
      const error = await response.json();
      throw new ValidationError(error);
    }

    if (!response.ok) {
      throw new Error(`Create order failed: ${response.status}`);
    }

    return response.json();
  }

  async getOrder(orderId: string): Promise<GetOrderResponse> {
    const response = await fetch(`${this.options.baseUrl}/orders/${orderId}`, {
      method: "GET",
      headers: {
        Authorization: `Bearer ${this.options.token}`,
      },
    });

    if (!response.ok) {
      throw new Error(`Get order failed: ${response.status}`);
    }

    return response.json();
  }
}
Enter fullscreen mode Exit fullscreen mode

The exact code should come from your project’s conventions and the Apidog spec. The important part is the workflow: Composer should query the contract instead of inventing the API shape.

Step 5: verify the generated requests in Apidog

Grounding Composer in a spec reduces hallucinated endpoints and schemas, but it does not replace verification.

A spec can drift from the deployed service. Composer can also misread an edge case. Before merging, validate the generated behavior.

Use this loop:

  1. Run the generated request in Apidog

Take the endpoint, method, headers, and body that Composer generated. Send the request in Apidog against a real or mock environment.

Check:

  • Status code
  • Response body
  • Auth behavior
  • Required fields
  • Error response shape
  1. Compare the code against the working request

If Apidog succeeds but the generated code fails, inspect differences in:

  • Base URL
  • Path parameters
  • Headers
  • Body serialization
  • Content type
  • Error handling
  1. Save working calls as test scenarios

Once a request is correct, save it as an automated scenario. That turns your manual verification into repeatable coverage.

  1. Mock unfinished endpoints

If the backend endpoint is not implemented yet, use Apidog’s mock server so frontend or client work can continue with realistic responses.

This pairs well with the workflow described in AI agents and API testing.

End-to-end example: refunds feature

Assume you are adding refunds to a payments service.

The target behavior:

  • Generate a typed refund client
  • Add a React hook that calls it
  • Respect an idempotency-key header
  • Handle duplicate refund errors

Workflow:

  1. Confirm the refunds endpoints and schemas exist in your Apidog project.
  2. Connect Apidog MCP to Cursor.
  3. Select Composer 2.5.
  4. Prompt Composer with the spec as the source of truth.

Example prompt:

Using apidog-api-spec, build the refund client and a React hook that calls it.

Requirements:
- Follow the schema exactly.
- Include the idempotency-key header required by the spec.
- Implement createRefund.
- Handle the 409 duplicate refund response.
- Add or update tests where appropriate.
Enter fullscreen mode Exit fullscreen mode

Composer can then generate the client, hook, types, and tests across multiple files.

After generation:

  1. Open Apidog.
  2. Send a real create-refund request.
  3. Confirm the idempotency behavior.
  4. Confirm the 409 response on duplicate requests.
  5. Save both as test scenarios.

The bug this prevents is concrete: a generated client that forgets the idempotency header and causes duplicate refund behavior in staging.

Prompt template you can reuse

Use this pattern when asking Composer 2.5 to implement API code:

Using <mcp-server-name> as the source of truth, implement <feature>.

Read the API contract before writing code.

Generate:
- <client/function/route/hook>
- Types based on the request and response schemas
- Error handling for documented error responses
- Tests or examples if appropriate

Constraints:
- Do not invent endpoints.
- Do not invent request or response fields.
- Match auth requirements from the spec.
- If the spec is ambiguous, ask before implementing.
Enter fullscreen mode Exit fullscreen mode

Example:

Using apidog-api-spec as the source of truth, implement the orders API client.

Read the API contract before writing code.

Generate:
- createOrder
- getOrder
- TypeScript request and response types
- Handling for the documented 422 validation response

Constraints:
- Do not invent endpoints.
- Do not invent request or response fields.
- Match auth requirements from the spec.
Enter fullscreen mode Exit fullscreen mode

Frequently asked questions

Does Composer 2.5 support MCP?

Yes. Composer 2.5 has access to Cursor’s agent toolset, including MCP servers. Select it in the model picker and configure the MCP server in your project. The Composer 2.5 guide covers model selection.

Do I need Apidog to use MCP with Composer 2.5?

You need a structured spec source. This article uses the Apidog MCP server because it also gives you API testing and mocking in the same workflow. Other options are covered in the best MCP servers for Cursor roundup.

Will grounding the model in a spec stop all hallucinations?

No. It removes the biggest category of API hallucinations: wrong endpoints, schemas, parameters, and response shapes. You still need to test against a real or mock environment because specs can drift from deployed services.

Is this worth it for a small project?

Yes, if the generated code touches a real API. The setup is a one-time project config. After that, every API-related prompt can reference the same contract instead of relying on a plausible guess.

The bottom line

Composer 2.5 can handle real API implementation work, but only if it codes against your actual contract. Connect your spec through the Apidog MCP server, make Composer read it before generating code, then Download Apidog to verify live requests and save working flows as tests and mocks.

Grounded generation plus verification is the workflow that turns agent speed into shipped features.

Top comments (0)