API Shakedown

io.github.anzar-ahsan-commits由 GitHub 帳號 anzar-ahsan-commits 發布v0.1.3更新於 Oct 25, 2026

Turn an OpenAPI spec into WireMock stubs, contract tests and chaos scenarios, on local LLMs.

已驗證STDIO僅桌面開發者工具安全與監控

概覽

AI 產生的概覽

把 OpenAPI 規格轉換成 WireMock 樁、契約測試、健壯性探測與混沌情境,並讓助理在執行中的 WireMock 上開關故障情境。

可以做什麼
檢查所設定的 LLM 供應商與模型是否可用(doctor)。從檔案路徑或 URL 載入並驗證 OpenAPI 規格,列出其中的操作(inspect_spec)。將可直接執行的測試工具包產生到輸出目錄,內含 WireMock 樁、契約測試、健壯性探測與混沌情境,可離線確定性產生或透過 LLM 產生(generate_harness)。列出已產生工具包中的混沌情境(list_chaos_scenarios)。在工具包執行中的 WireMock 上開啟某個混沌情境,或關閉全部情境(activate_chaos、deactivate_chaos)。
適用情境
當你已有 OpenAPI 規格,想要一個可對著開發的模擬 API、用來發現規格漂移的契約測試,或驗證用戶端能否應付逾時、限流與故障的演練時適用。適合在 Claude Code、Claude Desktop 等 MCP 用戶端中由開發者操作使用。
執行需求
透過 uvx 或 shakedown-mcp 指令以 stdio 在本機執行,也可使用 Docker 映像。需要 Python 3.11+,產生的工具包還需要 Docker 執行 WireMock。預設使用本機 Ollama 服務與已拉取的模型;使用雲端需 OPENAI_API_KEY 或 ANTHROPIC_API_KEY,並以 SHAKEDOWN_PROVIDER 選擇。需使用絕對路徑。
安裝前請注意
用本機模型產生需要數分鐘,可能超過用戶端的工具逾時。generate_harness 會寫入檔案,輸出目錄非空時會被拒絕,除非設定 force,而 force 會覆寫工具包檔案。雲端供應商會把規格傳送給 OpenAI 或 Anthropic 並消耗你的金鑰額度;預設本機 Ollama 則讓規格留在本機。混沌工具會改變執行中 WireMock 的狀態。它不是負載測試或安全掃描工具。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 API Shakedown,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

API Shakedown

Give it an OpenAPI spec. Get back a ready-to-run test harness: WireMock stubs, contract tests, robustness probes, and chaos scenarios, written by a team of LLM agents that review each other's work.

[CI] [PyPI] [Python] [License: MIT]

Runs locally on Ollama by default: no API key, no data leaves your machine. Cloud models (OpenAI, Anthropic) are bring-your-own-key. Available as a CLI, a Docker image, and an MCP server so an AI assistant can drive it.

Status: alpha (0.1.3). Works end to end on the example spec with a local 8B model.

[Demo: shakedown run generates a harness, its contract tests pass, and a chaos drill makes the first two calls fail with 503 before recovering]

A real run on the bundled example with qwen3:8b on a laptop, sped up: generation took about 9 minutes. Recording: docs/demo.cast.


Contents

Why

Teams that consume an API need three things that are tedious to write by hand and go stale quickly:

  1. A realistic mock of the API to develop and test against.
  2. Contract tests that tell you when the real API stops matching its spec.
  3. Failure drills: what does your client do when the API is slow, flaky, rate limited, returns garbage, or goes down?

API Shakedown generates all three from the spec you already have, and keeps them honest: the LLMs never write code that runs. They propose data (response bodies, test cases, failure scenarios, test records), and code validates every item against the spec, feeds problems back to the model, and falls back to deterministic output when a model cannot get it right. Without any model at all (--offline), every part still works.

Where it helps

SituationTypical teamsWhat API Shakedown gives you
Building before the backend existsFrontend, mobile, partner integratorsA virtual service generated from the agreed spec, so work starts on day one instead of after the backend ships or after hand-written mocks.
Depending on APIs you don't control (payments, shipping, identity checks, credit bureaus)Fintech, e-commerce, logistics, insuranceVendor sandboxes are often rate-limited, flaky or billed per call. Test locally what your app does when the provider times out, rate-limits you, or returns 503 twice before recovering.
Proving clients survive failureMicroservice teams, SRE game daysSwitch timeouts, rate limits, flaky calls and partial outages on and off while your client runs, and confirm retries, backoff and fallbacks really work.
Catching spec drift before releaseAPI owners, platform and public-API teamsContract tests run against a real deployment in CI and fail when the implementation stops matching its spec.
Hardening input validationAny API teamRobustness probes check that malformed requests get a 4xx, never a 500. A complement to a security review, not a replacement.
Regulated or offline environmentsBanking, healthcare, governmentEverything runs on a local model: the spec never leaves the machine, where many AI tools cannot be used at all.
Migrating or rewriting a serviceLegacy modernisationGenerate contract tests from the existing spec and run them against the new implementation to confirm it behaves the same.
Working through an AI assistantDevelopers using Claude and other MCP clientsThe assistant generates the harness and runs failure drills on request.

It is not a load-testing tool or a security scanner, and the virtual service does not keep state between calls; see Limitations.

Quick start

Prerequisites: Python 3.11+, Docker (for WireMock), and Ollama with a model (ollama pull qwen3:8b) unless you use --offline or a cloud model.

bash
pip install api-shakedownshakedown doctor                                   # is the model ready?shakedown run openapi.yaml --out my-harness        # minutes on a local modelcd my-harnessdocker compose up -d                               # WireMock with your stubs on :8080pip install -r requirements.txtSHAKEDOWN_SELECT_STATUS=1 pytest tests/test_contract.pypython chaos/chaos.py on flaky-start               # now point your client at :8080python chaos/chaos.py off

Try it on the bundled example: shakedown run examples/petstore.yaml --out petstore.

A real run on the example spec with qwen3:8b:

text
Petstore 1.0.0: 5 operations (ollama / qwen3:8b)Generating test data...Test data ready (3 Pet).Generating stubs, contract tests, and chaos scenarios...  stubs: done  contracts: done  chaos: done  review contracts: approved  review stubs: approved  review chaos: approved
Wrote 14 files to harness in 436s: 15 stubs, 11 contract cases, 11 chaos scenarios, 30 probes.Next: cd harness && docker compose up -d   (then see README.md)

What you get

text
my-harness/├── README.md                  # generated: how to run it, every scenario, review notes├── docker-compose.yml         # WireMock 3 serving the stubs (port: SHAKEDOWN_WIREMOCK_PORT)├── wiremock/mappings/         # stub mappings├── tests/│   ├── test_contract.py       # contract tests (cases in contract_cases.json)│   └── test_robustness.py     # malformed-request probes (cases in robustness_cases.json)├── chaos/│   ├── chaos.py               # switch failure scenarios on/off (standard library only)│   └── chaos_scenarios.json├── data/dataset.json          # test records and edge-case values per field├── requirements.txt           # pytest, httpx, openapi-schema-validator└── shakedown.json             # manifest: counts, review outcome, generation notes
PartWhat it does
StubsEvery documented response of every operation. Known ids return their own record, unknown ids return the documented 404, and any other response can be requested with X-Shakedown-Status: <status>.
Contract testsHappy paths, documented error statuses, and boundary values. Each checks the status code, Content-Type, and the body against the response schema. Run them against the stubs or a real deployment.
Robustness probesInvalid bodies and parameters derived from the schemas (missing required fields, wrong types, out-of-range values, broken JSON). A robust server answers 4xx, never 5xx.
Chaos scenariosSeven baseline failures every client should survive, plus scenarios the LLM targets at your API.
Test dataRealistic, consistent records per entity, shared by the stubs and the tests, plus edge-case values for every field.

Baseline chaos scenarios:

ScenarioWhat happensA resilient client should
total-outageEvery endpoint returns 503Fail fast, back off, not hammer the API
slow-responsesEvery response takes 3 sStay responsive
timeoutsEvery response takes 30 sGive up on its own and free resources
connection-resetsConnections are resetRetry idempotent calls with backoff
flaky-startFirst 2 calls fail with 503, then recoverRetry and succeed on the third attempt
rate-limitedFirst 3 calls return 429Honour Retry-After
truncated-jsonSuccess bodies are cut off mid-JSONReport a parse error, never crash

LLM-targeted scenarios from a real run include createPet fails 3 times with 503 then recovers, listPets is rate limited, and getPet loses required fields.

How it works

mermaid
flowchart LR    spec[/"OpenAPI spec"/] --> load["Load, validate,<br/>normalize, chunk"]    load --> data["Test data agent"]    data --> stubs["Stub agent"]    data --> contracts["Contract agent"]    data --> chaos["Chaos agent"]    stubs --> review{"Reviewer agent"}    contracts --> review    chaos --> review    review -- "blocker: revise with feedback" --> stubs    review -- "blocker" --> contracts    review -- "blocker" --> chaos    review -- "approved, or budget spent" --> coord["Coordinator"]    coord --> harness[/"Harness directory"/]
  1. Spec layer: loads YAML/JSON from a path or URL, validates it (problems become warnings), inlines $refs safely, and splits operations into prompt-sized chunks so large specs fit small models.
  2. Test data agent runs first: the stubs and tests share its records.
  3. Stub, contract, and chaos agents run in parallel.
  4. Reviewer judges each artifact. Blockers send it back to its author with the feedback, for a bounded number of rounds; suggestions are kept as notes.
  5. Coordinator assembles the harness and its README, including anything the reviewer still rejected when the revision budget ran out.

Every agent follows the same pattern, which is what keeps small local models reliable:

mermaid
sequenceDiagram    participant A as Agent    participant M as LLM    participant C as Code checks    A->>M: task + JSON schema (constrained decoding on Ollama)    M-->>A: proposal (bodies, cases, scenarios, records)    A->>C: validate against the spec    alt problems found        C-->>A: exact errors, e.g. "listPets 200: 'id' is a required property"        A->>M: fix these problems        M-->>A: corrected proposal    end    A->>A: keep valid items, fall back to deterministic ones for the rest

Things code guarantees, so the model never has to:

  • Request matching, URL patterns, priorities, and path-parameter types in the stubs.
  • Response bodies valid against their schemas.
  • Test inputs that route (valid path parameters, required query parameters), success cases that use ids that exist, 404 cases that use ids that do not.
  • Authentication from the spec's security schemes.
  • Chaos scenarios that are internally consistent (a "flaky" failure must recover, a rate limit is a 429, a partial outage leaves some endpoints up).
  • Reviewer findings that cite real items, and blockers only on what the author controls.

Install

bash
pip install api-shakedown              # local models via Ollama; includes the MCP serverpip install "api-shakedown[cloud]"     # plus OpenAI and Anthropic

Or use the Docker image, which includes everything: see Docker.

Generated harnesses need Docker (for WireMock) and Python for their tests.

Usage

text
shakedown doctor                     Check the LLM provider is reachable and readyshakedown inspect SPEC [--json]      Show the operations the agents will seeshakedown run SPEC [options]         Generate a harnessshakedown version

shakedown run options:

OptionDefault
--out PATHshakedown-outputWhere to write the harness (refuses a non-empty directory)
--offlineoffNo LLM: deterministic output in seconds
--no-reviewreview onSkip the reviewer (about 3x faster on the example)
--max-revisions N1Review/revise rounds
--forceoffWrite into a non-empty directory (only overwrites harness files)
--provider, --modelfrom settingsOverride the LLM for this run

Using the harness:

bash
docker compose up -d                                     # stubs on http://localhost:8080SHAKEDOWN_SELECT_STATUS=1 pytest tests/test_contract.py  # against the stubspython chaos/chaos.py list | on <scenario> | off         # failure drillsSHAKEDOWN_TARGET_URL=https://api.example.com/v1 pytest tests   # against a real serverSHAKEDOWN_SEED=1 SHAKEDOWN_TARGET_URL=... pytest tests   # create the test records first

With SHAKEDOWN_SEED=1, the contract tests first create the test dataset's records on the server, using the spec's own create operations, and delete them when they finish. This writes to the server, so point it at a test instance.

PowerShell: $env:SHAKEDOWN_SELECT_STATUS = "1"; pytest tests/test_contract.py.

Configuration

Settings come from environment variables or a .env file (see .env.example). Everything is optional.

VariableDefault
SHAKEDOWN_PROVIDERollamaollama, openai, or anthropic
SHAKEDOWN_MODELper providerqwen3:8b, gpt-5-mini, claude-sonnet-5-5
SHAKEDOWN_OLLAMA_URLhttp://localhost:11434Where Ollama runs
SHAKEDOWN_BASE_URLEndpoint override, e.g. an OpenAI-compatible server
SHAKEDOWN_TIMEOUT600 (Ollama) / 120Seconds per request
SHAKEDOWN_CONTEXT_WINDOW16384Ollama context size
SHAKEDOWN_REASONINGmodel defaultOllama: turn a reasoning model's thinking on/off
SHAKEDOWN_AGENT_MODELSPer-agent models, e.g. {"reviewer": "anthropic:claude-sonnet-5-5"}
SHAKEDOWN_AGENT_REASONINGthinking off for generatorsPer-agent thinking, e.g. {"reviewer": true}
OPENAI_API_KEY, ANTHROPIC_API_KEYBring your own key

Mixing models works well: generate locally, review with a stronger cloud model:

bash
SHAKEDOWN_AGENT_MODELS='{"reviewer": "anthropic:claude-sonnet-5-5"}' shakedown run openapi.yaml

Generated harnesses read SHAKEDOWN_TARGET_URL, SHAKEDOWN_SELECT_STATUS, SHAKEDOWN_SEED, SHAKEDOWN_API_KEY, SHAKEDOWN_BASIC_AUTH, SHAKEDOWN_TIMEOUT, and SHAKEDOWN_WIREMOCK_PORT / SHAKEDOWN_WIREMOCK_URL.

MCP server

shakedown-mcp (stdio) lets an MCP client such as Claude Code or Claude Desktop generate harnesses and run failure drills:

Tool
doctorIs the LLM provider ready?
inspect_specList a spec's operations and warnings
generate_harnessGenerate a harness, with progress notifications
list_chaos_scenariosScenarios in a harness
activate_chaos / deactivate_chaosSwitch a scenario on/off in a running WireMock
bash
claude mcp add api-shakedown -- uvx api-shakedown mcp     # Claude Code, nothing to installclaude mcp add api-shakedown -- shakedown-mcp             # Claude Code, after pip install

Name in the official MCP Registry: io.github.anzar-ahsan-commits/api-shakedown.

Other clients (mcpServers in their config):

json
{  "mcpServers": {    "api-shakedown": {      "command": "uvx",      "args": ["api-shakedown", "mcp"],      "env": { "SHAKEDOWN_PROVIDER": "ollama" }    }  }}

Pass absolute paths. Generating with a local model takes minutes; if your client gives up on long tool calls, use offline or review: false, or raise its tool timeout.

Docker

bash
docker build -t api-shakedown .docker run --rm -v "$PWD:/work" api-shakedown run /work/openapi.yaml --out /work/harnessdocker run -i --rm -v "$PWD:/work" --entrypoint shakedown-mcp api-shakedown   # MCP server

The image reaches Ollama on the host at host.docker.internal. Details for Linux, PowerShell, and cloud keys: DOCKER.md.

Architecture

mermaid
flowchart TB    subgraph app["api-shakedown"]        cli["CLI: shakedown"] --> pipeline["pipeline"]        mcp["MCP server: shakedown-mcp"] --> pipeline        pipeline --> agents["agents: testdata, stubs, contracts,<br/>chaos, reviewer, coordinator"]        agents --> domain["spec, wiremock, contracts,<br/>chaos, testdata (code checks)"]        pipeline --> harness["harness writer + templates"]    end    subgraph core["agentpanel (reusable core)"]        workflow["Workflow: parallel specialists,<br/>cross-review, bounded revision"]        structured["structured output:<br/>validate, feed back, retry"]        llm["providers: Ollama, OpenAI, Anthropic"]    end    agents --> workflow    agents --> structured    structured --> llm

The orchestration core is published separately as agentpanel: a small, domain-agnostic library for "specialists draft, reviewers critique, authors revise, a coordinator decides" workflows on LangGraph. It never imports the application; a test enforces that.

text
packages/agentpanel/     # the reusable core (its own PyPI package)src/api_shakedown/       # the application  spec/                  # loading, validation, $ref resolution, edge cases, samples  agents/                # the six agents  templates/             # runners copied into every harnessexamples/petstore.yaml   # example spectests/                   # offline tests; `-m live` for Ollama + Docker tests

Limitations

  • Speed on local models: a full run on the 5-operation example takes about 7 minutes with qwen3:8b, most of it review; --no-review takes about 2.5 minutes.
  • Small reviewers are imperfect: an 8B reviewer sometimes raises a false blocker, which costs a revision round. Use a stronger model for the reviewer if you can.
  • Specs: OpenAPI 3.0-3.2. Swagger 2.0 must be converted first; references to other files are not followed; self-referencing schemas are not validated.
  • Stubs are static: a create call returns a new record, but stubs do not keep state between calls.
  • Probes against stubs only cover operations that document a 4xx; they are meant for real servers.
  • Seeding has limits: SHAKEDOWN_SEED=1 can only create records the spec lets it create with the test data's ids, and real servers often enforce rules the spec doesn't state. Records it can't create are listed in a warning, and tests that read them fail with 404 until you create them yourself.
  • Scope: not a load-testing tool or a security scanner.
  • Large specs are slow on a laptop: the Typesense API (79 operations) takes several hours end to end with qwen3:8b on a laptop GPU, versus minutes for small specs. A bigger GPU or a cloud model is much faster; --offline takes seconds. Reports from more real-world specs are very welcome.

Roadmap

  • Faster runs on large specs (smaller prompts per batch, progress per batch)
  • Smarter seeding: capture server-assigned ids from create responses, so resources like API keys can be seeded too
  • Stateful stubs (WireMock response templating, created records visible to later calls)
  • Auth-failure scenarios (401/403) and "valid but nasty input must not 5xx" probes
  • Review of the test dataset
  • More harness targets (k6 load profiles, Postman collections)

Development

bash
git clone https://github.com/anzar-ahsan-commits/api-shakedown.gitcd api-shakedownpython -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activatepip install -e packages/agentpanel -e ".[dev]"ruff check . && ruff format --check . && mypypytest                 # offline: LLMs are faked, about 20 spytest -m live         # also uses your local Ollama and Docker

Contributing

Contributions are welcome: see CONTRIBUTING.md. Security issues: see SECURITY.md.

License

MIT © 2026 Anzar Ahsan

來源:README.md,提交 b75a499

工具

6

doctor

Check that the configured LLM provider is reachable and the model is available.

無需輸入參數。

inspect_spec

Load and validate an OpenAPI spec (file path or http(s) URL) and list its operations.

輸入參數spec必填

generate_harness

Generate a ready-to-run chaos test harness for an OpenAPI spec into out_dir. offline=true skips the LLM (deterministic, seconds); otherwise this takes minutes on a local model, and review=false roughly halves that. Refuses a non-empty out_dir unless force=true (which overwrites only the harness's own files).

輸入參數spec必填forcereviewofflineout_dir必填max_revisions

list_chaos_scenarios

List the chaos scenarios of a generated harness.

輸入參數harness_dir必填

activate_chaos

Turn one chaos scenario on in the harness's running WireMock (others go off).

輸入參數harness_dir必填scenario_id必填wiremock_url

deactivate_chaos

Turn all chaos scenarios off: the stubs behave normally again.

輸入參數wiremock_url

版本歷史

2
  1. v0.1.3最新Oct 24, 2026
  2. v0.1.1Oct 15, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分