k11-api-contract-qa-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. k11_api_contract_qa_mcp-0.1.0/.gitignore +8 -0
  2. k11_api_contract_qa_mcp-0.1.0/LICENSE +21 -0
  3. k11_api_contract_qa_mcp-0.1.0/PKG-INFO +240 -0
  4. k11_api_contract_qa_mcp-0.1.0/README.md +215 -0
  5. k11_api_contract_qa_mcp-0.1.0/demo/consumers/billing-svc/src/main/java/com/acme/billing/OrderClient.java +15 -0
  6. k11_api_contract_qa_mcp-0.1.0/demo/consumers/checkout-web/src/api.ts +12 -0
  7. k11_api_contract_qa_mcp-0.1.0/demo/formats/graphql/consumers/web/src/orderQueries.ts +15 -0
  8. k11_api_contract_qa_mcp-0.1.0/pyproject.toml +41 -0
  9. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/__init__.py +3 -0
  10. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/__main__.py +3 -0
  11. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/cli.py +91 -0
  12. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/conformance.py +109 -0
  13. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/consumers.py +293 -0
  14. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/diff.py +323 -0
  15. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/drift.py +54 -0
  16. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/__init__.py +79 -0
  17. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/asyncapi.py +89 -0
  18. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/gql.py +167 -0
  19. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/proto.py +372 -0
  20. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/swagger2.py +100 -0
  21. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/formats/wsdl.py +181 -0
  22. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/report.py +72 -0
  23. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/server.py +160 -0
  24. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/spec.py +212 -0
  25. k11_api_contract_qa_mcp-0.1.0/src/k11_contract_qa/testgen.py +123 -0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ .tmp*
8
+ .qa-mcp/contract-report/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 K11 Software Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.5
2
+ Name: k11-api-contract-qa-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server and Claude Code plugin for API contract testing across OpenAPI, Swagger, GraphQL, gRPC/protobuf, AsyncAPI and SOAP/WSDL: consumer-aware breaking-change detection, deployed-contract drift and conformance checks, with an audit trail.
5
+ Project-URL: Homepage, https://github.com/K11-Software-Solutions/k11techlab-api-contract-qa-mcp
6
+ Project-URL: Issues, https://github.com/K11-Software-Solutions/k11techlab-api-contract-qa-mcp/issues
7
+ Author: K11 Software Solutions
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: api-testing,asyncapi,breaking-changes,claude,contract-testing,graphql,grpc,mcp,microservices,openapi,protobuf,qa,soap,swagger,wsdl
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Testing
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: graphql-core<3.4,>=3.2
17
+ Requires-Dist: httpx>=0.27
18
+ Requires-Dist: jsonschema>=4.20
19
+ Requires-Dist: mcp<2,>=1.20
20
+ Requires-Dist: pyyaml>=6
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest-timeout>=2; extra == 'dev'
23
+ Requires-Dist: pytest>=8; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # k11 API Contract QA — MCP server & Claude Code plugin
27
+
28
+ <!-- mcp-name: io.github.K11-Software-Solutions/api-contract-qa -->
29
+
30
+ **Know which services an API change breaks before you merge it, and why. REST, GraphQL, gRPC, events and SOAP.**
31
+
32
+ A pull request renames a field or tightens a request body. Its own tests pass. Three other services break in production. Spec-diff tools can tell you a change is "breaking", but not *who* it breaks, so teams either ignore the warnings or block every change. This MCP server answers the real question:
33
+
34
+ - **Breaking-change detection** for **OpenAPI 3.x, Swagger 2.0, GraphQL, gRPC/protobuf, AsyncAPI 2.x/3.x and SOAP/WSDL 1.1**, including `$ref`s, nested fields and array items, with the rule each change broke.
35
+ - **Consumer-aware impact.** It knows which services call which endpoints, and which fields they read or send. A removed field only counts against the consumers that use it.
36
+ - **A verdict with evidence:** breaking, breaking but no known consumer uses it, or compatible. When 2 or more consumers break, or a critical one does, it says a person should decide before merge.
37
+ - **Deployed-contract drift:** compares what a running service publishes (GraphQL introspection, `?wsdl`, `/v3/api-docs`) with your spec file.
38
+ - **Live conformance checks** for REST: status codes, content type and the JSON body validated against the schema.
39
+ - **Consumer discovery** that scans a consumer's source code (Python, Java, TypeScript, Go, …) for calls to your API, with file and line. For GraphQL it parses the consumer's actual queries, so it knows exactly which fields they read.
40
+ - **Contract test generation** for pytest + httpx or Java REST Assured.
41
+ - **`contract-ci`**: a pull-request comment that lists every affected consumer and the reason.
42
+
43
+ Deterministic rules, no LLM calls, the same result every run. Works with **Claude Code** (as a plugin with `/check-api-change` and `/api-contract-tests`), **Claude Desktop** and any MCP client. Listed in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.K11-Software-Solutions/api-contract-qa`.
44
+
45
+ ---
46
+
47
+ ## See it in a pull request
48
+
49
+ In the demo, Order Service v2 changes `total` from a number to a string, drops `customer.email`, adds a required `channel` to `POST /orders` and removes `DELETE /orders/{id}`. Four services consume it. `contract-ci` posted:
50
+
51
+ > ## API contract check: 🔴 Breaking for known consumers
52
+ >
53
+ > **Order Service**: `main` → this PR. 11 changes, **6 breaking** (worst: critical); 4 known consumers, **3 affected**.
54
+ >
55
+ > > **Needs a person before merge:** 3 consumers break (threshold 2); high-criticality consumers break: notification-svc, billing-svc, checkout-web.
56
+ >
57
+ > | Consumer | Owner | Criticality | Breaking change | Why it affects them |
58
+ > |---|---|---|---|---|
59
+ > | **billing-svc** | @team-billing | critical | `GET /orders/{id}`: Response field 'total' changed type from number to string | reads 'total' |
60
+ > | **checkout-web** | @team-web | high | `POST /orders`: New required request field 'channel' | doesn't send the now-required 'channel' |
61
+ > | **notification-svc** | @team-notify | high | `GET /orders/{id}`: Response field 'customer.email' was removed | reads 'customer.email' |
62
+ >
63
+ > **Breaking, no known consumer:** `DELETE /orders/{orderId}` was removed, plus two response changes on `POST /orders` that checkout-web doesn't read.
64
+
65
+ analytics-svc calls `GET /orders` too, but it reads only `id` and `status`, so it isn't flagged.
66
+
67
+ ## Supported contracts
68
+
69
+ The format is detected automatically from the file. Every format goes through the same rules, consumer impact, report and `contract-ci`, plus rules specific to it.
70
+
71
+ | Format | Operations are named | Format-specific rules | Deployed drift check |
72
+ |---|---|---|---|
73
+ | OpenAPI 3.x | `GET /orders/{id}` | parameters, request bodies, success responses, auth | `GET` the published document |
74
+ | Swagger 2.0 | `GET /api/orders/{id}` | converted to OpenAPI 3 on load (body/formData, definitions, basePath) | `GET` the published document |
75
+ | GraphQL (SDL or introspection JSON) | `QUERY order`, `MUTATION createOrder` | removing *any* argument breaks (unknown arguments are errors); non-null → nullable breaks readers | introspection query |
76
+ | gRPC / protobuf (`.proto`, imports followed) | `RPC shop.v1.OrderService/GetOrder` | field number changed or reused, field renamed (wire-safe but breaks JSON and generated code), removed numbers not reserved, streaming changed, message replaced | not yet (needs server reflection) |
77
+ | AsyncAPI 2.x / 3.x | `EMITS order.created`, `RECEIVES order.cancel` | emitted messages follow reader rules; received messages follow writer rules | `GET` the published document |
78
+ | SOAP / WSDL 1.1 | `SOAP OrderPort/GetOrder` | XSD `minOccurs`/`maxOccurs`/`nillable`, enumerations, extension; SOAPAction and binding style; strict about unknown elements | `GET ...?wsdl` |
79
+
80
+ Consumer discovery finds HTTP paths, GraphQL query documents (exact fields read), gRPC stub calls, SOAP client calls (zeep, JAX-WS, .NET) and AsyncAPI topic names. Live response checks and test generation are for REST (OpenAPI and Swagger).
81
+
82
+ ## Tools
83
+
84
+ | Tool | What it does |
85
+ |---|---|
86
+ | `list_operations` | Lists a contract's operations and its detected format. |
87
+ | `diff_contracts` | Classifies every change between two versions of a contract: rule, field path, before/after, severity. |
88
+ | `assess_impact` | Which consumers a change breaks and why; the verdict and whether a person should decide. Optionally writes the report. |
89
+ | `discover_consumer_usage` | Finds a consumer's calls to your API in its source code and drafts its `consumers.yaml` entry. |
90
+ | `check_deployed_contract` | Compares what a running service publishes with the spec: `matches`, `drift` or `incompatible`. |
91
+ | `check_live_conformance` | Calls a running REST endpoint and checks the response against the spec. Header values can use `${ENV:NAME}`. |
92
+ | `generate_api_tests` | REST contract tests (status + JSON schema) for pytest + httpx or REST Assured. |
93
+ | `write_test` | Writes generated files under `tests/` or `src/test/` only, never overwriting unless asked. |
94
+
95
+ Specs are files in the project or git refs: `origin/main:openapi.yaml`, `origin/main:proto/orders.proto` (imports are read from the same ref).
96
+
97
+ ## Tell it who your consumers are
98
+
99
+ `.qa-mcp/consumers.yaml`:
100
+
101
+ ```yaml
102
+ consumers:
103
+ - name: billing-svc
104
+ repo: acme/billing-svc
105
+ owner: "@team-billing"
106
+ criticality: critical # critical | high | medium | low
107
+ uses:
108
+ - endpoint: GET /orders/{id}
109
+ reads: [id, total, currency] # leave out to mean "any field"
110
+ - name: checkout-web
111
+ owner: "@team-web"
112
+ criticality: high
113
+ uses:
114
+ - endpoint: POST /orders
115
+ sends: [customerId, items]
116
+ reads: [id]
117
+ ```
118
+
119
+ Endpoints use the operation names from the table above (`QUERY order`, `RPC shop.v1.OrderService/GetOrder`, `EMITS order.created`, …). Field lists are what make the verdict precise. Without them, any breaking change on an endpoint counts against everyone who calls it. Start with `discover_consumer_usage` on each consumer's code, then add the fields.
120
+
121
+ ## In CI
122
+
123
+ ```bash
124
+ k11-api-contract-qa-mcp contract-ci --spec openapi.yaml --base origin/main
125
+ ```
126
+
127
+ It compares the spec in the pull request with `origin/main`, writes `contract-report.md` (the PR comment) and `contract-report.json`, sets GitHub Actions outputs (`verdict`, `breaking`, `consumers_affected`, `needs_human`, `report`) and exits non-zero according to `--fail-on`:
128
+
129
+ | `--fail-on` | Fails when |
130
+ |---|---|
131
+ | `breaking` (default) | a known consumer breaks |
132
+ | `needs-human` | 2+ consumers or a critical/high one break |
133
+ | `any-breaking` | any breaking change, used or not |
134
+ | `never` | report only |
135
+
136
+ Copy [`docs/contract-check.yml`](docs/contract-check.yml) to `.github/workflows/` to comment on every pull request that touches the spec.
137
+
138
+ ## Install
139
+
140
+ Requires Python 3.10+.
141
+
142
+ ### Claude Code: plugin (recommended)
143
+
144
+ Needs [uv](https://docs.astral.sh/uv/):
145
+
146
+ ```text
147
+ /plugin marketplace add K11-Software-Solutions/k11techlab-api-contract-qa-mcp
148
+ /plugin install api-contract-qa@k11-api-contract-qa
149
+ ```
150
+
151
+ ### Claude Code: MCP server only
152
+
153
+ ```bash
154
+ claude mcp add api-contract-qa -- uvx k11-api-contract-qa-mcp
155
+ ```
156
+
157
+ ### Claude Desktop and other MCP clients
158
+
159
+ ```json
160
+ {
161
+ "mcpServers": {
162
+ "api-contract-qa": {
163
+ "command": "uvx",
164
+ "args": ["k11-api-contract-qa-mcp"],
165
+ "env": { "QA_MCP_ROOT": "/path/to/your/service" }
166
+ }
167
+ }
168
+ }
169
+ ```
170
+
171
+ Or `pip install k11-api-contract-qa-mcp`.
172
+
173
+ ## Try the demo
174
+
175
+ ```bash
176
+ cd demo/order-service
177
+ k11-api-contract-qa-mcp contract-ci --spec openapi.yaml --base-spec openapi.v1.yaml
178
+ python server.py --port 8080 # v2 implementation with one deliberate contract bug
179
+ ```
180
+
181
+ Then ask Claude to `check_live_conformance` on `GET /orders/{id}` with `id` 1001. It finds that `total` is still sent as a number.
182
+
183
+ `demo/formats/` has a v1 and v2 contract for each other format (Swagger 2.0, GraphQL, protobuf with an import, AsyncAPI 2.x → 3.x, WSDL) and a small consumer for each, for example:
184
+
185
+ ```bash
186
+ k11-api-contract-qa-mcp contract-ci --spec demo/formats/graphql/schema.graphql --base-spec demo/formats/graphql/schema.v1.graphql --fail-on never
187
+ ```
188
+
189
+ ## Rules
190
+
191
+ These apply to every format (with each format's names for inputs and outputs):
192
+
193
+ | Rule | Breaking? |
194
+ |---|---|
195
+ | Endpoint removed | yes (critical) |
196
+ | Response field removed, type changed, became nullable, no longer guaranteed | yes |
197
+ | Success response or JSON media type removed | yes |
198
+ | New required request field / parameter, field or parameter became required | yes |
199
+ | Request enum value removed, request field newly restricted to an enum | yes |
200
+ | New authentication requirement | yes (critical) |
201
+ | Required request field removed (any removed input for GraphQL and SOAP) | yes |
202
+ | New endpoint, optional field or parameter; response enum value added | no (enum additions flagged for exhaustive switches) |
203
+ | Path parameter renamed, endpoint deprecated | no |
204
+ | protobuf: field number changed, message replaced, streaming changed | yes |
205
+ | protobuf: field renamed with the same number | yes (medium: wire-safe, breaks JSON and generated code) |
206
+
207
+ The rules extend the K11 research on [cross-repository contract testing and change impact analysis](https://doi.org/10.18535/ijecs.v15i07.5599) (IJECS, 2026), whose reference system is [k11techlab-microservice-qa-system](https://github.com/K11-Software-Solutions/k11techlab-microservice-qa-system). This server adds `$ref`, nested and array-item rules and field-level consumer matching.
208
+
209
+ ## How it compares
210
+
211
+ | | Spec diff tools (e.g. oasdiff) | Consumer-driven contracts (e.g. Pact) | k11 API Contract QA |
212
+ |---|---|---|---|
213
+ | Knows who breaks | No | Yes | Yes, field-level |
214
+ | Setup per consumer | None | Contract tests in every consumer | One YAML entry; discovery drafts it |
215
+ | Explains why | Rule only | Failing interaction | Rule, field, and what the consumer reads or sends |
216
+ | Formats | Usually one | HTTP and messages | OpenAPI, Swagger, GraphQL, gRPC, AsyncAPI, SOAP |
217
+ | Usable by an AI agent | No | No | Yes, over MCP |
218
+
219
+ ## Safety
220
+
221
+ - Specs, consumer folders and reports must be inside the project folder; git refs are read with `git show`, never a shell.
222
+ - `write_test` writes only under `tests/` or `src/test/`, and won't overwrite without asking.
223
+ - Tokens for live checks are read from the environment (`${ENV:NAME}`) and never echoed.
224
+
225
+ ## Development
226
+
227
+ ```bash
228
+ python -m venv .venv && .venv/Scripts/pip install -e ".[dev]" # bin/pip on macOS/Linux
229
+ pytest # rules for all formats, consumer impact, discovery, drift, conformance, generated tests, contract-ci, MCP (38)
230
+ ```
231
+
232
+ ## Roadmap
233
+
234
+ - Transitive impact (a consumer that re-exposes the data to its own consumers)
235
+ - Live gRPC checks through server reflection; WSDL 2.0; GraphQL federation
236
+ - Optional LLM review for "uncertain" cases, as in the research system
237
+
238
+ ---
239
+
240
+ Built by [K11 Software Solutions](https://k11softwaresolutions.com). Part of the K11 Tech Lab agentic QA series, alongside [Playwright QA](https://github.com/K11-Software-Solutions/k11techlab-playwright-qa-mcp), [Selenium QA](https://github.com/K11-Software-Solutions/k11techlab-selenium-qa-mcp) and [LLM Assure](https://github.com/K11-Software-Solutions/k11techlab-llm-assurance-toolkit). MIT licensed.
@@ -0,0 +1,215 @@
1
+ # k11 API Contract QA — MCP server & Claude Code plugin
2
+
3
+ <!-- mcp-name: io.github.K11-Software-Solutions/api-contract-qa -->
4
+
5
+ **Know which services an API change breaks before you merge it, and why. REST, GraphQL, gRPC, events and SOAP.**
6
+
7
+ A pull request renames a field or tightens a request body. Its own tests pass. Three other services break in production. Spec-diff tools can tell you a change is "breaking", but not *who* it breaks, so teams either ignore the warnings or block every change. This MCP server answers the real question:
8
+
9
+ - **Breaking-change detection** for **OpenAPI 3.x, Swagger 2.0, GraphQL, gRPC/protobuf, AsyncAPI 2.x/3.x and SOAP/WSDL 1.1**, including `$ref`s, nested fields and array items, with the rule each change broke.
10
+ - **Consumer-aware impact.** It knows which services call which endpoints, and which fields they read or send. A removed field only counts against the consumers that use it.
11
+ - **A verdict with evidence:** breaking, breaking but no known consumer uses it, or compatible. When 2 or more consumers break, or a critical one does, it says a person should decide before merge.
12
+ - **Deployed-contract drift:** compares what a running service publishes (GraphQL introspection, `?wsdl`, `/v3/api-docs`) with your spec file.
13
+ - **Live conformance checks** for REST: status codes, content type and the JSON body validated against the schema.
14
+ - **Consumer discovery** that scans a consumer's source code (Python, Java, TypeScript, Go, …) for calls to your API, with file and line. For GraphQL it parses the consumer's actual queries, so it knows exactly which fields they read.
15
+ - **Contract test generation** for pytest + httpx or Java REST Assured.
16
+ - **`contract-ci`**: a pull-request comment that lists every affected consumer and the reason.
17
+
18
+ Deterministic rules, no LLM calls, the same result every run. Works with **Claude Code** (as a plugin with `/check-api-change` and `/api-contract-tests`), **Claude Desktop** and any MCP client. Listed in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.K11-Software-Solutions/api-contract-qa`.
19
+
20
+ ---
21
+
22
+ ## See it in a pull request
23
+
24
+ In the demo, Order Service v2 changes `total` from a number to a string, drops `customer.email`, adds a required `channel` to `POST /orders` and removes `DELETE /orders/{id}`. Four services consume it. `contract-ci` posted:
25
+
26
+ > ## API contract check: 🔴 Breaking for known consumers
27
+ >
28
+ > **Order Service**: `main` → this PR. 11 changes, **6 breaking** (worst: critical); 4 known consumers, **3 affected**.
29
+ >
30
+ > > **Needs a person before merge:** 3 consumers break (threshold 2); high-criticality consumers break: notification-svc, billing-svc, checkout-web.
31
+ >
32
+ > | Consumer | Owner | Criticality | Breaking change | Why it affects them |
33
+ > |---|---|---|---|---|
34
+ > | **billing-svc** | @team-billing | critical | `GET /orders/{id}`: Response field 'total' changed type from number to string | reads 'total' |
35
+ > | **checkout-web** | @team-web | high | `POST /orders`: New required request field 'channel' | doesn't send the now-required 'channel' |
36
+ > | **notification-svc** | @team-notify | high | `GET /orders/{id}`: Response field 'customer.email' was removed | reads 'customer.email' |
37
+ >
38
+ > **Breaking, no known consumer:** `DELETE /orders/{orderId}` was removed, plus two response changes on `POST /orders` that checkout-web doesn't read.
39
+
40
+ analytics-svc calls `GET /orders` too, but it reads only `id` and `status`, so it isn't flagged.
41
+
42
+ ## Supported contracts
43
+
44
+ The format is detected automatically from the file. Every format goes through the same rules, consumer impact, report and `contract-ci`, plus rules specific to it.
45
+
46
+ | Format | Operations are named | Format-specific rules | Deployed drift check |
47
+ |---|---|---|---|
48
+ | OpenAPI 3.x | `GET /orders/{id}` | parameters, request bodies, success responses, auth | `GET` the published document |
49
+ | Swagger 2.0 | `GET /api/orders/{id}` | converted to OpenAPI 3 on load (body/formData, definitions, basePath) | `GET` the published document |
50
+ | GraphQL (SDL or introspection JSON) | `QUERY order`, `MUTATION createOrder` | removing *any* argument breaks (unknown arguments are errors); non-null → nullable breaks readers | introspection query |
51
+ | gRPC / protobuf (`.proto`, imports followed) | `RPC shop.v1.OrderService/GetOrder` | field number changed or reused, field renamed (wire-safe but breaks JSON and generated code), removed numbers not reserved, streaming changed, message replaced | not yet (needs server reflection) |
52
+ | AsyncAPI 2.x / 3.x | `EMITS order.created`, `RECEIVES order.cancel` | emitted messages follow reader rules; received messages follow writer rules | `GET` the published document |
53
+ | SOAP / WSDL 1.1 | `SOAP OrderPort/GetOrder` | XSD `minOccurs`/`maxOccurs`/`nillable`, enumerations, extension; SOAPAction and binding style; strict about unknown elements | `GET ...?wsdl` |
54
+
55
+ Consumer discovery finds HTTP paths, GraphQL query documents (exact fields read), gRPC stub calls, SOAP client calls (zeep, JAX-WS, .NET) and AsyncAPI topic names. Live response checks and test generation are for REST (OpenAPI and Swagger).
56
+
57
+ ## Tools
58
+
59
+ | Tool | What it does |
60
+ |---|---|
61
+ | `list_operations` | Lists a contract's operations and its detected format. |
62
+ | `diff_contracts` | Classifies every change between two versions of a contract: rule, field path, before/after, severity. |
63
+ | `assess_impact` | Which consumers a change breaks and why; the verdict and whether a person should decide. Optionally writes the report. |
64
+ | `discover_consumer_usage` | Finds a consumer's calls to your API in its source code and drafts its `consumers.yaml` entry. |
65
+ | `check_deployed_contract` | Compares what a running service publishes with the spec: `matches`, `drift` or `incompatible`. |
66
+ | `check_live_conformance` | Calls a running REST endpoint and checks the response against the spec. Header values can use `${ENV:NAME}`. |
67
+ | `generate_api_tests` | REST contract tests (status + JSON schema) for pytest + httpx or REST Assured. |
68
+ | `write_test` | Writes generated files under `tests/` or `src/test/` only, never overwriting unless asked. |
69
+
70
+ Specs are files in the project or git refs: `origin/main:openapi.yaml`, `origin/main:proto/orders.proto` (imports are read from the same ref).
71
+
72
+ ## Tell it who your consumers are
73
+
74
+ `.qa-mcp/consumers.yaml`:
75
+
76
+ ```yaml
77
+ consumers:
78
+ - name: billing-svc
79
+ repo: acme/billing-svc
80
+ owner: "@team-billing"
81
+ criticality: critical # critical | high | medium | low
82
+ uses:
83
+ - endpoint: GET /orders/{id}
84
+ reads: [id, total, currency] # leave out to mean "any field"
85
+ - name: checkout-web
86
+ owner: "@team-web"
87
+ criticality: high
88
+ uses:
89
+ - endpoint: POST /orders
90
+ sends: [customerId, items]
91
+ reads: [id]
92
+ ```
93
+
94
+ Endpoints use the operation names from the table above (`QUERY order`, `RPC shop.v1.OrderService/GetOrder`, `EMITS order.created`, …). Field lists are what make the verdict precise. Without them, any breaking change on an endpoint counts against everyone who calls it. Start with `discover_consumer_usage` on each consumer's code, then add the fields.
95
+
96
+ ## In CI
97
+
98
+ ```bash
99
+ k11-api-contract-qa-mcp contract-ci --spec openapi.yaml --base origin/main
100
+ ```
101
+
102
+ It compares the spec in the pull request with `origin/main`, writes `contract-report.md` (the PR comment) and `contract-report.json`, sets GitHub Actions outputs (`verdict`, `breaking`, `consumers_affected`, `needs_human`, `report`) and exits non-zero according to `--fail-on`:
103
+
104
+ | `--fail-on` | Fails when |
105
+ |---|---|
106
+ | `breaking` (default) | a known consumer breaks |
107
+ | `needs-human` | 2+ consumers or a critical/high one break |
108
+ | `any-breaking` | any breaking change, used or not |
109
+ | `never` | report only |
110
+
111
+ Copy [`docs/contract-check.yml`](docs/contract-check.yml) to `.github/workflows/` to comment on every pull request that touches the spec.
112
+
113
+ ## Install
114
+
115
+ Requires Python 3.10+.
116
+
117
+ ### Claude Code: plugin (recommended)
118
+
119
+ Needs [uv](https://docs.astral.sh/uv/):
120
+
121
+ ```text
122
+ /plugin marketplace add K11-Software-Solutions/k11techlab-api-contract-qa-mcp
123
+ /plugin install api-contract-qa@k11-api-contract-qa
124
+ ```
125
+
126
+ ### Claude Code: MCP server only
127
+
128
+ ```bash
129
+ claude mcp add api-contract-qa -- uvx k11-api-contract-qa-mcp
130
+ ```
131
+
132
+ ### Claude Desktop and other MCP clients
133
+
134
+ ```json
135
+ {
136
+ "mcpServers": {
137
+ "api-contract-qa": {
138
+ "command": "uvx",
139
+ "args": ["k11-api-contract-qa-mcp"],
140
+ "env": { "QA_MCP_ROOT": "/path/to/your/service" }
141
+ }
142
+ }
143
+ }
144
+ ```
145
+
146
+ Or `pip install k11-api-contract-qa-mcp`.
147
+
148
+ ## Try the demo
149
+
150
+ ```bash
151
+ cd demo/order-service
152
+ k11-api-contract-qa-mcp contract-ci --spec openapi.yaml --base-spec openapi.v1.yaml
153
+ python server.py --port 8080 # v2 implementation with one deliberate contract bug
154
+ ```
155
+
156
+ Then ask Claude to `check_live_conformance` on `GET /orders/{id}` with `id` 1001. It finds that `total` is still sent as a number.
157
+
158
+ `demo/formats/` has a v1 and v2 contract for each other format (Swagger 2.0, GraphQL, protobuf with an import, AsyncAPI 2.x → 3.x, WSDL) and a small consumer for each, for example:
159
+
160
+ ```bash
161
+ k11-api-contract-qa-mcp contract-ci --spec demo/formats/graphql/schema.graphql --base-spec demo/formats/graphql/schema.v1.graphql --fail-on never
162
+ ```
163
+
164
+ ## Rules
165
+
166
+ These apply to every format (with each format's names for inputs and outputs):
167
+
168
+ | Rule | Breaking? |
169
+ |---|---|
170
+ | Endpoint removed | yes (critical) |
171
+ | Response field removed, type changed, became nullable, no longer guaranteed | yes |
172
+ | Success response or JSON media type removed | yes |
173
+ | New required request field / parameter, field or parameter became required | yes |
174
+ | Request enum value removed, request field newly restricted to an enum | yes |
175
+ | New authentication requirement | yes (critical) |
176
+ | Required request field removed (any removed input for GraphQL and SOAP) | yes |
177
+ | New endpoint, optional field or parameter; response enum value added | no (enum additions flagged for exhaustive switches) |
178
+ | Path parameter renamed, endpoint deprecated | no |
179
+ | protobuf: field number changed, message replaced, streaming changed | yes |
180
+ | protobuf: field renamed with the same number | yes (medium: wire-safe, breaks JSON and generated code) |
181
+
182
+ The rules extend the K11 research on [cross-repository contract testing and change impact analysis](https://doi.org/10.18535/ijecs.v15i07.5599) (IJECS, 2026), whose reference system is [k11techlab-microservice-qa-system](https://github.com/K11-Software-Solutions/k11techlab-microservice-qa-system). This server adds `$ref`, nested and array-item rules and field-level consumer matching.
183
+
184
+ ## How it compares
185
+
186
+ | | Spec diff tools (e.g. oasdiff) | Consumer-driven contracts (e.g. Pact) | k11 API Contract QA |
187
+ |---|---|---|---|
188
+ | Knows who breaks | No | Yes | Yes, field-level |
189
+ | Setup per consumer | None | Contract tests in every consumer | One YAML entry; discovery drafts it |
190
+ | Explains why | Rule only | Failing interaction | Rule, field, and what the consumer reads or sends |
191
+ | Formats | Usually one | HTTP and messages | OpenAPI, Swagger, GraphQL, gRPC, AsyncAPI, SOAP |
192
+ | Usable by an AI agent | No | No | Yes, over MCP |
193
+
194
+ ## Safety
195
+
196
+ - Specs, consumer folders and reports must be inside the project folder; git refs are read with `git show`, never a shell.
197
+ - `write_test` writes only under `tests/` or `src/test/`, and won't overwrite without asking.
198
+ - Tokens for live checks are read from the environment (`${ENV:NAME}`) and never echoed.
199
+
200
+ ## Development
201
+
202
+ ```bash
203
+ python -m venv .venv && .venv/Scripts/pip install -e ".[dev]" # bin/pip on macOS/Linux
204
+ pytest # rules for all formats, consumer impact, discovery, drift, conformance, generated tests, contract-ci, MCP (38)
205
+ ```
206
+
207
+ ## Roadmap
208
+
209
+ - Transitive impact (a consumer that re-exposes the data to its own consumers)
210
+ - Live gRPC checks through server reflection; WSDL 2.0; GraphQL federation
211
+ - Optional LLM review for "uncertain" cases, as in the research system
212
+
213
+ ---
214
+
215
+ Built by [K11 Software Solutions](https://k11softwaresolutions.com). Part of the K11 Tech Lab agentic QA series, alongside [Playwright QA](https://github.com/K11-Software-Solutions/k11techlab-playwright-qa-mcp), [Selenium QA](https://github.com/K11-Software-Solutions/k11techlab-selenium-qa-mcp) and [LLM Assure](https://github.com/K11-Software-Solutions/k11techlab-llm-assurance-toolkit). MIT licensed.
@@ -0,0 +1,15 @@
1
+ package com.acme.billing;
2
+
3
+ import java.math.BigDecimal;
4
+ import org.springframework.web.client.RestClient;
5
+
6
+ public class OrderClient {
7
+ private final RestClient http = RestClient.create("http://order-service");
8
+
9
+ public BigDecimal amountDue(String orderId) {
10
+ OrderDto order = http.get().uri("/orders/" + orderId).retrieve().body(OrderDto.class);
11
+ return order.total(); // a JSON number today
12
+ }
13
+
14
+ record OrderDto(String id, BigDecimal total, String currency) {}
15
+ }
@@ -0,0 +1,12 @@
1
+ export async function placeOrder(customerId: string, items: { sku: string; qty: number }[]) {
2
+ const res = await fetch(`/orders`, {
3
+ method: "POST",
4
+ headers: { "Content-Type": "application/json" },
5
+ body: JSON.stringify({ customerId, items }),
6
+ });
7
+ return res.json();
8
+ }
9
+
10
+ export async function trackOrder(id: string) {
11
+ return (await fetch(`/orders/${id}/tracking`)).json();
12
+ }
@@ -0,0 +1,15 @@
1
+ import { gql } from "@apollo/client";
2
+
3
+ export const ORDER_SUMMARY = gql`
4
+ query OrderSummary($id: ID!) {
5
+ order(id: $id) {
6
+ id
7
+ status
8
+ ...Money
9
+ }
10
+ }
11
+ fragment Money on Order {
12
+ total
13
+ currency
14
+ }
15
+ `;
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "k11-api-contract-qa-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP server and Claude Code plugin for API contract testing across OpenAPI, Swagger, GraphQL, gRPC/protobuf, AsyncAPI and SOAP/WSDL: consumer-aware breaking-change detection, deployed-contract drift and conformance checks, with an audit trail."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "K11 Software Solutions" }]
13
+ requires-python = ">=3.10"
14
+ keywords = ["mcp", "openapi", "swagger", "graphql", "grpc", "protobuf", "asyncapi", "wsdl", "soap", "contract-testing", "api-testing", "breaking-changes", "microservices", "qa", "claude"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Software Development :: Testing",
20
+ ]
21
+ dependencies = ["mcp>=1.20,<2", "pyyaml>=6", "httpx>=0.27", "jsonschema>=4.20", "graphql-core>=3.2,<3.4"]
22
+
23
+ [project.optional-dependencies]
24
+ dev = ["pytest>=8", "pytest-timeout>=2"]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/K11-Software-Solutions/k11techlab-api-contract-qa-mcp"
28
+ Issues = "https://github.com/K11-Software-Solutions/k11techlab-api-contract-qa-mcp/issues"
29
+
30
+ [project.scripts]
31
+ k11-api-contract-qa-mcp = "k11_contract_qa.cli:main"
32
+
33
+ [tool.hatch.build.targets.wheel]
34
+ packages = ["src/k11_contract_qa"]
35
+
36
+ [tool.hatch.build.targets.sdist]
37
+ include = ["src", "README.md", "LICENSE"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
41
+ timeout = 120
@@ -0,0 +1,3 @@
1
+ """k11 API Contract QA: consumer-aware API contract testing for MCP clients and CI."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())