Skip to main content
Glama
README.md
# api-docs

**Generate Postman and SoapUI files from your API project, in one command or from your AI agent (MCP).**

Reads your routes from a [CodeGraph](https://github.com/colbymchenry/codegraph) index when you have one (Laravel, ASP.NET,
CodeIgniter 3, Spring, Django, FastAPI, Flask, Express, NestJS...), otherwise from an OpenAPI file, otherwise from a
built-in code scan. Then it writes:

- `<name>.postman_collection.json` (Postman collection v2.1, grouped by controller)
- `<name>.postman_environment.json` (`base_url`, `token`)
- `<name>-soapui-project.xml` (SoapUI REST project)

## Get Started

### 1. Install the CLI (once)

Needs Python 3.10+. Pick one:

```bash
pipx install api-docs-mcp          # recommended
uv tool install api-docs-mcp       # if you use uv
pip install --user api-docs-mcp    # plain pip
```

Not published yet? Install from the source folder or GitHub instead:

```bash
pipx install /path/to/api-docs-mcp
pipx install git+https://github.com/RomyPutra/api-docs-mcp.git
```

Open a **new terminal** so the `api-docs` command is on your PATH. Check with `api-docs --version`.

### 2. Connect your AI agents (once)

```bash
api-docs install
```

Detects Claude Code, Cursor, Claude Desktop, Windsurf and Gemini CLI on your machine and adds the MCP server to each
config (existing settings are kept, a `.api-docs.bak` backup is made). Then **restart your agent**.
Using something else (Codex, VS Code...)? Run `api-docs install --print-config codex` and paste the snippet.

### 3. Use it

In any project, ask your agent:

> Use api-docs to generate Postman and SoapUI files for this project.

Or without an agent:

```bash
cd your-project
api-docs generate . --format all      # files appear in ./api-docs
```

Import the files: Postman > **Import**, SoapUI > **File > Import Project**.

### Better results with CodeGraph (recommended)

```bash
cd your-project
codegraph init          # once per project, see the CodeGraph README
```

With the index present, `api-docs` uses the exact routes CodeGraph resolved (route prefixes, controller names,
`Route::resource`) and does not need to guess. Without CodeGraph it still works through OpenAPI or a code scan.
No `.codegraph/` yet? Add `--auto-index` and `api-docs` runs `codegraph init -i` for you.

---

## Commands

```bash
api-docs install                    # connect MCP server to detected agents (--yes to skip prompts)
api-docs install --target claude,cursor        # only these agents
api-docs install --location local   # this project only (Claude Code, Cursor, Gemini)
api-docs install --print-config codex          # just print the config snippet
api-docs uninstall                  # remove from all agents

api-docs scan [path]                # list endpoints, write nothing
api-docs generate [path]            # write Postman + SoapUI files
api-docs doctor [path]              # check install, CodeGraph, project index, agent wiring
api-docs serve                      # MCP server over stdio (your agent runs this, you don't)
```

`path` defaults to the current folder and may also be an OpenAPI file or URL, e.g.
`api-docs generate http://localhost:5000/swagger/v1/swagger.json`.

| `generate` / `scan` option | Meaning |
|---|---|
| `--format postman\|soapui\|all` | what to write (default `all`) |
| `--out DIR` | output folder (default `<project>/api-docs`) |
| `--name NAME` | collection / project name |
| `--base-url URL` | default `http://localhost:8000` (or the spec's server) |
| `--prefer auto\|codegraph\|openapi\|scan` | endpoint source (default `auto` = CodeGraph > OpenAPI > scan) |
| `--auto-index` | run `codegraph init -i` if the project has no index |

(`--format`, `--out`, `--name` and `--base-url` apply to `generate` only.)

## MCP tools

Your agent gets these (usage hints are delivered automatically when it connects):

| Tool | Purpose |
|---|---|
| `scan_api_project` | list endpoints found, writes nothing |
| `generate_postman` | collection v2.1 + environment |
| `generate_soapui` | SoapUI REST project |
| `generate_all` | all of the above |

Each takes `source` (absolute project path, OpenAPI file or URL) and optional `out_dir`, `name`, `base_url`,
`prefer`, `auto_index`. Every result includes `notes` describing which source was used and any caveat.

The server uses the **stdio transport**: the MCP client starts `api-docs serve` as a local process. For a manual
configuration, use the installed `api-docs` executable as the command and `serve` as its argument. Keep stdout
reserved for MCP protocol traffic; do not wrap the command in a shell that writes banners to stdout.

Generation tools write files to disk (default: `<project>/api-docs`). `scan_api_project` is read-only. The source path
must be a project directory or OpenAPI file, or a caller-provided HTTP(S) OpenAPI URL. `auto_index` may invoke the
CodeGraph CLI only when explicitly enabled. Results include notes when discovery falls back or has known limitations.
Remote OpenAPI documents are fetched over HTTP(S) with a 15-second timeout and a 10 MiB response limit; redirects to
non-HTTP(S) URLs are rejected.

## What gets generated

| Framework | Routes | Request examples |
|---|---|---|
| ASP.NET Core / Web API (via CodeGraph) | attribute routes, `[controller]` prefix resolved | `[FromQuery]`, `[FromBody]` DTO properties, path params |
| Laravel (via CodeGraph) | `Route::get/post`, groups, prefixes, `resource` / `apiResource` (5 REST routes) | `FormRequest::rules()` to JSON body |
| CodeIgniter 3, Spring, Django, Rails, Go, ... (via CodeGraph) | whatever CodeGraph resolves | empty `{}` body for POST/PUT/PATCH |
| Any OpenAPI / Swagger source | full | schemas to examples, bearer/apiKey auth |
| FastAPI, Flask, Express, NestJS (no CodeGraph) | built-in scanner | Pydantic models (Python only) |

## Troubleshooting

**`api-docs: command not found`**: open a new terminal. With pipx run `pipx ensurepath`.

**Agent does not show the tools**: run `api-docs doctor` (shows which agents are configured), then restart the agent.
If you installed with `uvx` or inside a throwaway venv, install it permanently (step 1): the agent config stores the
path of the `api-docs` executable.

**"No endpoints found" / zero CodeGraph routes**: CodeGraph only emits routes when it recognises the framework from
project files (e.g. `composer.json` for Laravel, `*.csproj` for ASP.NET). Run `codegraph index --force` after adding
them, or point at an OpenAPI/Swagger file (`api-docs generate path/to/swagger.json`). ASP.NET projects with Swashbuckle
can use `api-docs generate http://localhost:5000/swagger/v1/swagger.json` while the app is running.

**Wrong or missing routes in the output**: the `note:` lines printed by `scan` / `generate` say which source was used.
Code-scan results do not resolve prefixes added through `include_router()` / `app.use()`; prefer CodeGraph or OpenAPI.

**Config file could not be edited** (invalid JSON, permissions): `api-docs install --print-config <agent>` and add the
snippet by hand.

## Known limits

- Reads CodeGraph's SQLite file (`.codegraph/codegraph.db`) directly. That schema is internal to CodeGraph and may change;
  on any error `api-docs` falls back to OpenAPI / scan and says so. Tested with CodeGraph 1.6.7.
- Body examples are built for C# DTOs and Laravel FormRequests only.
- Not yet tested: CodeIgniter 3 route naming, ASP.NET Framework (Web API 2), VB.NET, importing the SoapUI file into SoapUI.
- Auth is not detected from code: set `token` in the Postman environment (or SoapUI project property).
- SoapUI output is REST only. SOAP / WSDL generation is not implemented.

### Real-project smoke test

For a Laravel project with a CodeGraph index, run:

```powershell
api-docs scan D:\path\to\project --prefer codegraph
api-docs generate D:\path\to\project --prefer codegraph --format all --out .\api-docs --name my-api --base-url http://localhost:8000
```

The generator reports the endpoint count and source used. Validate the Postman JSON and SoapUI XML before importing
them into their respective applications; route detection does not replace application-level authorization or business
logic testing.

For CodeGraph/static-scan sources, generated Postman collections use `{{base_url}}`, include a bearer-auth placeholder
that reads the empty secret `{{token}}` environment value, and add a basic successful-response status test to each
request. If a response contains `data.token` (as login endpoints commonly do), its test script saves that token to the
active environment for subsequent bearer-authenticated requests. Fill in the token manually only when the API does not
return it in that response shape. Request bodies inferred
from Laravel validation rules are examples; bodies shown as `{}` are explicitly labeled placeholders when their
fields could not be inferred. They are not guaranteed to satisfy application-specific business rules.

## Compatibility and security notes

- **Python:** 3.10 or newer. CI currently targets Python 3.10, 3.11, and 3.12 on Ubuntu; Windows and macOS are not yet covered by CI.
- **MCP transport:** local stdio server (`api-docs serve`). The install helper currently writes configuration for Claude Code, Cursor, Claude Desktop, Windsurf, and Gemini CLI; Codex configuration is printed for manual entry. Other clients may work with a compatible stdio configuration but are not specifically validated here.
- **Discovery:** CodeGraph index, OpenAPI JSON/YAML, then best-effort Python/Node static scanning (depending on the selected preference and available source). Static scanning may omit framework-composed prefixes.
- **Network:** when given a remote OpenAPI URL, the tool makes an outbound HTTP(S) request, follows HTTP redirects, enforces a 15-second timeout and 10 MiB response limit, and rejects redirects to non-HTTP(S) schemes. Do not provide URLs to untrusted/internal services unless that network access is intended.
- **Filesystem:** generation writes files to the selected output folder; scanning does not write generated files. Use an output path where the user has permission to write.
- **Credentials:** generated token values are empty placeholders. Do not commit generated environments containing real credentials or paste secrets into bug reports.

The GitHub issue templates request versions and reproduction information; remove credentials, private URLs, and proprietary source from submitted diagnostics.

## Publish it (so `pipx install api-docs-mcp` works for everyone)

```bash
pip install build twine
python -m build
twine upload dist/*
```

Check that the name `api-docs-mcp` is free on PyPI first, or rename it in `pyproject.toml`.

## License

MIT