|
| 1 | +# swagger-mcp — usage guide |
| 2 | + |
| 3 | +This server lets you explore an OpenAPI/Swagger spec without loading the whole |
| 4 | +document into context. It is built to minimize tokens: responses are compact |
| 5 | +(TOON), lists are auto-limited, and repeated schemas are de-duplicated. Follow |
| 6 | +the workflow below to stay efficient. |
| 7 | + |
| 8 | +## Workflow |
| 9 | + |
| 10 | +1. `fetch_spec` — once per spec URL. Returns title/version/counts. Establishes |
| 11 | + the cache so later calls are instant. |
| 12 | +2. `analyze_tags` — **always start here**. Maps the API into tags with endpoint |
| 13 | + counts so you know where to look. |
| 14 | +3. `list_endpoints` — filter by `tag` (preferred), `method`, or `path_pattern`. |
| 15 | + Never browse unfiltered on a large API. |
| 16 | +4. `get_endpoint` — full detail for one endpoint: params, request body, |
| 17 | + responses, and resolved schemas. |
| 18 | +5. `get_schema` — only to expand a `$ref(Name)` you saw in `get_endpoint` and |
| 19 | + whose fields you actually need. |
| 20 | +6. `generate_types` — emit ready-to-paste TypeScript interfaces or Go structs |
| 21 | + instead of translating schemas by hand. |
| 22 | + |
| 23 | +`search_spec` is the shortcut when you already know a keyword (it searches |
| 24 | +paths, summaries, operation IDs, params, and body field names). |
| 25 | + |
| 26 | +## Reading the output (TOON) |
| 27 | + |
| 28 | +- Endpoint list: `METHOD /path — summary [tag1, tag2]`, one per line. |
| 29 | +- Schema fields: `field: type` — a trailing `*` marks a **required** field, and |
| 30 | + `— text` after the type is the field's description. Example: |
| 31 | + `email*: string(email) — primary contact email`. |
| 32 | +- `$ref(Name)` means that schema was already shown once in this response (or is |
| 33 | + shared across responses). Don't re-expand it unless you need its fields — and |
| 34 | + if you do, call `get_schema Name`. |
| 35 | +- Schemas resolve **3 levels deep by default**. Pass `resolve_depth` (0–10) to |
| 36 | + go deeper on nested models, or `0` for names-only (cheapest). |
| 37 | + |
| 38 | +## Token-efficiency rules |
| 39 | + |
| 40 | +- Filter before listing. `analyze_tags` → filtered `list_endpoints` beats one |
| 41 | + unfiltered dump by ~30×. |
| 42 | +- Reuse the cache. Don't re-`fetch_spec` a URL you already loaded; check |
| 43 | + `spec_status` if unsure. |
| 44 | +- Default format is TOON (compact). Only pass `format=json` when a tool consumer |
| 45 | + needs structured JSON. |
| 46 | +- Lower `resolve_depth` (or 0) when you only need field names, not nested shapes. |
| 47 | + |
| 48 | +## Example sequences |
| 49 | + |
| 50 | +**"What can this API do with employees?"** |
| 51 | +``` |
| 52 | +analyze_tags(url) → see an "Employee" tag, 40 endpoints |
| 53 | +list_endpoints(url, tag="Employee") → the 40 endpoints, one line each |
| 54 | +get_endpoint(url, "POST", "/api/v1/Employee") → full request/response shape |
| 55 | +``` |
| 56 | + |
| 57 | +**"I need to call the create-user endpoint."** |
| 58 | +``` |
| 59 | +search_spec(url, query="create user") → ranked matches |
| 60 | +get_endpoint(url, "POST", "/users") → params + body + responses |
| 61 | +get_schema(url, "CreateUserDto") → only if a $ref(CreateUserDto) needs expanding |
| 62 | +``` |
| 63 | + |
| 64 | +**"Give me the TypeScript types for the orders response."** |
| 65 | +``` |
| 66 | +generate_types(url, method="GET", path="/orders", language="typescript") |
| 67 | +``` |
| 68 | + |
| 69 | +**"Did the spec change since last time?"** |
| 70 | +``` |
| 71 | +refresh_spec(url) → reports changed/unchanged via fingerprint, plus a fresh summary |
| 72 | +``` |
| 73 | + |
| 74 | +## Anti-patterns |
| 75 | + |
| 76 | +- Don't `list_endpoints` without filters on a large API — it wastes tokens. |
| 77 | +- Don't `get_endpoint` every endpoint to "look around" — narrow with tags/search. |
| 78 | +- Don't expand every `$ref(Name)` — only the ones whose fields you actually need. |
| 79 | +- Don't re-fetch a cached spec — use `spec_status` to check first. |
| 80 | +- Don't raise `resolve_depth` to 10 by reflex — the default of 3 is enough for |
| 81 | + most models, and the dedup keeps shared schemas from repeating anyway. |
0 commit comments