CI: add MCP tool + e2e integration test coverage (Zod, Express, rate-limit) - #49
Merged
Conversation
- server.js: export {app, mcpServer}; gate app.listen() behind
NODE_ENV!=test (no behavior change for normal boot).
- package.json: add supertest devDependency (^7.2.2) for e2e HTTP tests.
- test/mcp-integration.test.js: real Zod validation path via
InMemoryTransport + Client against the actual mcpServer/get_repo tool
(valid args reach the handler; invalid args are rejected pre-handler).
- test/server-e2e.test.js: supertest against the exported app -- /health,
requireMcpKey/requireAllowedIp ordering, and express-rate-limit
(30 allowed, 31st -> 429, via a module-reset fresh limiter instance).
Verified locally: npm ci && npm test (88/88 passing) && npm run lint
(clean) && node --check on all source files && manual server boot +
GET /health smoke test, matching every step of .github/workflows/ci.yml.
No changes needed to the CI workflow itself.
package-lock.json intentionally not touched here -- CI already falls
back to `npm install` when the lockfile is missing/out of sync (see
ci.yml's Install dependencies step), so a stale lockfile doesn't break
CI; regenerate via the repo's "Generate lockfile" workflow separately
if desired.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the integration-test gap ahead of the pending zod 3->4, express 4->5, and express-rate-limit 7->8 bumps (see Notion entity_id
madmcp-ci-integration-test-plan).Gap this closes
The 6 existing test files only cover pure functions (github-client retry/backoff, security IP/CIDR + safeEqual, tar parsing, narrow validation files). Nothing registered an MCP tool via
server.tool(...)and sent it through real Zod validation, nothing hit an Express route/middleware chain end to end, and nothing exercisedexpress-rate-limitunder real traffic.What's added
server.js— refactor only, no behavior change: exports{ app, mcpServer }, gatesapp.listen(...)behindNODE_ENV !== "test". Middleware order (mcpLimiter -> requireMcpKey -> requireAllowedIp -> handleMcp) is unchanged.package.json— addssupertest(^7.2.2) as a devDependency.test/mcp-integration.test.js— real Zod validation path using the actualmcpServer(not a mock), viaInMemoryTransport.createLinkedPair()+ SDKClient. Usesget_repo:{ owner, repo }passes Zod and reaches the handler (surfaces the expected downstreamGITHUB_TOKENerror, not a validation error — proving args parsed/coerced correctly)repo) are rejected at the validation layer (-32602, "Invalid arguments") and never reach the handlertest/server-e2e.test.js— supertest against the exportedapp:GET /health→ 200, no authPOST /mcpwith no key (even from an allowlisted IP) → 401 (key check runs before IP check)POST /mcpwith a valid key from a disallowed IP → 403vi.resetModules()-isolated fresh app instance so this doesn't inherit request count from the earlier tests in the same fileNo changes needed to
.github/workflows/ci.yml—npm testalready runs everytest/*.test.jsfile.Verified locally
npm ci && npm test→ 88/88 passingnpm run lint→ cleannode --checkon all source files → cleannode server.js+curl /health→ passes (confirms the listen-gating change doesn't break normal boot)Note:
package-lock.jsonis not updated in this PR (CI already falls back tonpm installwhen the lockfile is stale/missing, per the existingInstall dependenciesstep) — worth regenerating separately via the repo's "Generate lockfile" workflow.