Letting AI Agents Run E2E API Contract Tests Safely via MCP
AI coding assistants are pretty good at reading an OpenAPI spec and writing integration tests. The awkward part starts when you actually want them to run those tests against a live server. Most people end up giving the agent shell access with curl and an .env file full of Bearer tokens or API keys.

AI coding assistants are pretty good at reading an OpenAPI spec and writing integration tests. The awkward part starts when you actually want them to run those tests against a live server.
Most people end up giving the agent shell access with curl and an.env file full of Bearer tokens or API keys. That works for a quick experiment, but it falls apart fast if you care about security or reliability:
I ran into this while building Open API Portal, so I added a scoped Model Context Protocol (MCP) test runner directly into the portal.
The main idea is simple: the AI agent should know the API contract, not the credentials or even the raw target URL.
In Open API Portal, you set up a Test Profile and an MCP Test Suite from the UI:
When an agent connects to /mcp, it gets five tools:
Real API flows usually take more than one call. The server injects the profile's encrypted auth automatically on every step, and the agent can use skipAuth: true to verify negative 401 cases or capture values (using JSONPath or headers) to pass into later steps with {{var}}, plus built-in helpers like {{$uuid}} and {{$isoNow}}:
{ "name": "Create and Verify Order", "steps": [ { "name": "Reject Unauthenticated Request", "method": "GET", "path": "/api/v1/orders", "skipAuth": true, "expectedStatus": 401 }, { "name": "Create Order", "method": "POST", "path": "/api/v1/orders", "body": { "reference": "ord_{{$uuid}}", "amount": 49.99 }, "expectedStatus": 201, "capture": { "orderId": "$.id" }, "assertions": [ { "source": "body", "path": "$.status", "op": "eq", "value": "CREATED" }, { "source": "latency", "op": "lt", "value": 1000 } ] }, { "name": "Verify Order Contract", "method": "GET", "path": "/api/v1/orders/{id}", "pathParams": { "id": "{{orderId}}" }, "expectedStatus": 200, "validateSchema": true } ] } Enter fullscreen mode Exit fullscreen mode Whenever validateSchema is enabled, the runner validates the live JSON response against the OpenAPI schema using Ajv. If a field is missing or comes back with the wrong type, the agent gets the exact schema error and can fix the API code right away.
Every run is also saved as a Test Report inside the portal, so you can open the UI and see the exact status codes, latencies, assertions, and schema checks yourself.
If you want to test it locally, the repo includes a built-in mock server so you don't need an external API to play with it:
git clone https://github.com/minuth/open-api-portal.git cd open-api-portal cp example.env.env npm install && npm run dev Enter fullscreen mode Exit fullscreen mode Source code and setup docs are on GitHub: github.com/minuth/open-api-portal.
Expand Abdullah Naseer Abdullah Naseer Abdullah Naseer Follow Need to know about me? I Can Be Your Manager Or a Worker Here's My Insta ID 👉: wogfl Come if you need Anything 🤞 Joined Oct 26, 2026 • Nov 28 Dropdown menu Copy link Hide The line that frames the whole design is "the agent should know the API contract, not the credentials or even the raw target URL" — that's the right boundary, and the allowlisted METHOD + /path list is what actually enforces it. Most MCP test setups hand the agent curl and a.env file and hope it behaves, which is exactly how a hallucinated path ends up hitting a DELETE on an admin endpoint.
One question on the allowlist: when a new endpoint lands in the spec, does the suite fail closed — the endpoint stays invisible until someone explicitly allowlists it? And for chained flows, when a step captures a value with {{var}} to pass into the next call, does the agent ever see the captured value, or does that substitution happen server-side too?