Skip to content
Merged
118 changes: 118 additions & 0 deletions versioned_docs/version-4.0.0/running-keploy/agent-test-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,124 @@ Create a `.cursorrules` file in your project root with the same test format refe

Use the same test format documentation as system instructions or project context.

## MCP Server (Recommended for AI Agents)

Keploy provides an MCP (Model Context Protocol) endpoint that gives AI agents **native tool access** to the Automated Test Generation (ATG) platform. Instead of the agent parsing CLI output, it calls structured tools directly and gets typed JSON responses.

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section positions MCP as a way to avoid agents parsing CLI output, but the rest of the page’s “Workflow” section still describes a CLI+JSON-output loop for agent iteration. To avoid confusing readers, consider explicitly stating that the CLI workflow is the fallback when MCP isn’t used (or add an MCP-based workflow variant / link to it).

Suggested change
Keploy provides an MCP (Model Context Protocol) endpoint that gives AI agents **native tool access** to the Automated Test Generation (ATG) platform. Instead of the agent parsing CLI output, it calls structured tools directly and gets typed JSON responses.
Keploy provides an MCP (Model Context Protocol) endpoint that gives AI agents **native tool access** to the Automated Test Generation (ATG) platform. Instead of the agent parsing CLI output, it calls structured tools directly and gets typed JSON responses. This MCP-based flow is the **recommended** integration for supported IDEs and agents.
If your IDE or agent does not support MCP, you can fall back to the CLI + JSON-output workflow described in the **Workflow** section below; both approaches expose the same underlying capabilities.

Copilot uses AI. Check for mistakes.
The MCP endpoint is built into the Keploy API server at `/client/v1/mcp`. Tools are auto-generated from the OpenAPI spec—when the API evolves, tools update automatically.

### Available Tools

| Tool | What it does |
| -------------------- | ------------------------------------------------------------------------ |
| `listApps` | List all applications |
| `createApp` | Create a new application |
| `generateTestSuites` | Trigger AI test generation from an OpenAPI spec |
| `runTestSuites` | Execute test suites against a target API |
| `listTestSuites` | List test suites for an app |
| `createTestSuite` | Create a test suite from steps JSON |
| `generate_and_wait` | Generate tests and wait for completion (composite) |
| `run_and_report` | Run tests and return results with failures and coverage gaps (composite) |
| `get_coverage_gaps` | Get uncovered endpoints with prioritized suggestions |
| _...39+ API tools_ | Every `/client/v1` endpoint is available as an MCP tool |

:::caution API Key Security
The examples below include an API key in configuration files. **Do not commit API keys to version control.** Use environment variables or add the config file to `.gitignore`. For CI/CD, use secret management.
:::

Replace `https://your-keploy-host` with your Keploy instance URL (e.g., `https://api.keploy.io` for Keploy Cloud, or your self-hosted domain).

### Setup for Claude Code

Add to your Claude Code MCP settings (`~/.claude/settings.json` or project-level):

```json
{
"mcpServers": {
"keploy": {
"type": "url",
"url": "https://your-keploy-host/client/v1/mcp",
"headers": {
Comment on lines +102 to +108
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client config examples use slightly different MCP server schemas (Claude includes type: "url", Cursor/Copilot omit it). If type is required only for Claude, it would help to call that out explicitly; otherwise consider standardizing the examples so readers don’t copy the wrong shape between clients.

Copilot uses AI. Check for mistakes.
"Authorization": "Bearer kep_YOUR_API_KEY"
}
}
Comment on lines +106 to +111
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is hardcoded to the Keploy Cloud domain. Since this page targets Keploy Enterprise (including self-hosted), the example should use a placeholder base URL (e.g., https://<your-keploy-host>/client/v1/mcp) and mention that users must replace it with their own API server address.

Copilot uses AI. Check for mistakes.
}
}
```

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples include an API key in a config file. Please add an explicit warning not to commit credentials and guidance on keeping the file out of version control (or using environment-variable substitution / secret storage if supported by the client). Without that, users may paste real keys into repo-tracked files.

Suggested change
**Security note:** When you replace `kep_YOUR_API_KEY` with a real key, keep this settings file out of version control (for example by using user-specific config locations or adding project-level config files to `.gitignore`), or use your editor/client’s secret storage or environment-variable substitution if available. Avoid committing real API keys to your repositories.

Copilot uses AI. Check for mistakes.
Then ask Claude Code:

> "Use the Keploy MCP tools to generate API tests for my OpenAPI spec, run them against my staging server, and show me coverage gaps"

Claude Code will call `generate_and_wait`, `run_and_report`, and `get_coverage_gaps` tools directly.

### Setup for Cursor

Cursor supports MCP servers. Add to your Cursor MCP configuration (`.cursor/mcp.json`):

```json
{
"mcpServers": {
"keploy": {
"url": "https://your-keploy-host/client/v1/mcp",
"headers": {
"Authorization": "Bearer kep_YOUR_API_KEY"
}
}
Comment on lines +128 to +134
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is hardcoded to the Keploy Cloud domain. Since this page targets Keploy Enterprise (including self-hosted), the Cursor example should use a placeholder base URL and mention replacing it with the user’s Keploy API server host.

Copilot uses AI. Check for mistakes.
}
}
```

Cursor's AI agent can then discover and use all Keploy tools natively.

### Setup for GitHub Copilot

GitHub Copilot supports MCP in agent mode. Add to `.github/copilot-mcp.json` in your project (add this file to `.gitignore` since it contains credentials).

> **Note:** GitHub Copilot uses the top-level key `servers` (not `mcpServers` as other clients use). This is Copilot-specific.

```json
{
"servers": {
"keploy": {
"url": "https://your-keploy-host/client/v1/mcp",
"headers": {
"Authorization": "Bearer kep_YOUR_API_KEY"
}
}
Comment on lines +149 to +155
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is hardcoded to the Keploy Cloud domain. Since this page targets Keploy Enterprise (including self-hosted), the Copilot example should use a placeholder base URL and mention replacing it with the user’s Keploy API server host.

Copilot uses AI. Check for mistakes.
}
}
```

### Setup for Antigravity

Antigravity (formerly Windsurf) supports MCP servers. Add to your Antigravity MCP settings:

```json
{
"mcpServers": {
"keploy": {
"serverUrl": "https://your-keploy-host/client/v1/mcp",
"headers": {
"Authorization": "Bearer kep_YOUR_API_KEY"
}
Comment on lines +164 to +171
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Antigravity example uses serverUrl while the other client examples use url, but unlike the Copilot section there’s no note explaining this schema difference. Add a short note clarifying that Antigravity expects serverUrl (if that’s intentional), or rename it to url for consistency.

Copilot uses AI. Check for mistakes.
}
Comment on lines +166 to +172
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is hardcoded to the Keploy Cloud domain. Since this page targets Keploy Enterprise (including self-hosted), the Antigravity example should use a placeholder base URL and mention replacing it with the user’s Keploy API server host.

Copilot uses AI. Check for mistakes.
}
}
```

### How it Works

1. The agent discovers available tools via `tools/list`
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tools/list may be read as an HTTP path. If this refers to the MCP method name, consider clarifying it’s the MCP "tools/list" request (not a REST endpoint on the Keploy server) to prevent confusion for readers trying to curl it.

Suggested change
1. The agent discovers available tools via `tools/list`
1. The agent discovers available tools via the MCP `tools/list` request (this is an MCP method, not an HTTP path on the Keploy server)

Copilot uses AI. Check for mistakes.
2. When you ask "generate API tests", the agent calls `generate_and_wait` with your OpenAPI spec
3. The tool triggers AI generation on the Keploy platform, polls until complete, and returns the created suites
4. The agent calls `run_and_report` to execute suites against your API
5. The tool returns pass/fail results, assertion failures, and coverage gaps
6. The agent reads the coverage gaps and generates additional test suites for uncovered endpoints
7. This loop continues until coverage targets are met

The MCP endpoint uses the same API key as the REST API and accepts the same two authentication methods: `Authorization: Bearer kep_...` or `X-API-Key: kep_...`. See the [Public API docs](/running-keploy/public-api) for details. All tools proxy to `/client/v1` endpoints using the caller's credentials.
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internal link to the Public API docs uses /running-keploy/public-api, but other versioned docs in this repo use the /docs/... prefix for internal links (e.g., this same page links to /docs/keploy-cloud/cloud-installation/). This link is likely broken in the built site; please update it to the correct docs path (or a relative link) consistent with the rest of the docs.

Suggested change
The MCP endpoint uses the same API key as the REST API and accepts the same two authentication methods: `Authorization: Bearer kep_...` or `X-API-Key: kep_...`. See the [Public API docs](/running-keploy/public-api) for details. All tools proxy to `/client/v1` endpoints using the caller's credentials.
The MCP endpoint uses the same API key as the REST API and accepts the same two authentication methods: `Authorization: Bearer kep_...` or `X-API-Key: kep_...`. See the [Public API docs](/docs/running-keploy/public-api) for details. All tools proxy to `/client/v1` endpoints using the caller's credentials.

Copilot uses AI. Check for mistakes.

## Workflow

### 1. Initialize the test directory
Expand Down
Loading