Skip to content

feat(mcp): MCP/HTTP affected tool (Phase 2)#133

Merged
SutuSebastian merged 3 commits into
mainfrom
feat/mcp-affected-tool
May 25, 2026
Merged

feat(mcp): MCP/HTTP affected tool (Phase 2)#133
SutuSebastian merged 3 commits into
mainfrom
feat/mcp-affected-tool

Conversation

@SutuSebastian

@SutuSebastian SutuSebastian commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds MCP/HTTP affected tool with { paths?, changed_since?, test_glob?, max_depth? } — same preprocessor as codemap affectedaffected-tests recipe.
  • Extracts shared logic to src/application/affected-engine.ts (CLI + transports).
  • Documents in mcp-instructions + skill; registers in CODEMAP_MCP_TOOLS allowlist.

Follow-up to #132 (Phase 2 optional from agent-surface plan).

Test plan

  • bun test src/application/affected-engine.test.ts
  • bun test src/application/mcp-server.test.ts (affected + allowlist)
  • bun test src/application/http-server.test.ts (affected)
  • bun test src/cli/cmd-affected.test.ts
  • bun run typecheck

Summary by CodeRabbit

  • New Features

    • Added "affected" tool to automatically identify tests impacted by file changes. Supports explicit path specification or git-based change detection with configurable depth limits and test matching options.
  • Documentation

    • Updated guidance on using the affected tool in agent workflows and CLI commands with example usage patterns.

Review Change Stack

Extract shared affected-engine from cmd-affected; register affected on
MCP/HTTP with paths/changed_since/test_glob/max_depth. Document in
mcp-instructions and skill; include in CODEMAP_MCP_TOOLS allowlist.
@changeset-bot

changeset-bot Bot commented May 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bff97fd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@SutuSebastian, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 42 minutes and 17 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ee50c4f-eac9-4bd7-ab79-39f42652a111

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad7dd8 and bff97fd.

📒 Files selected for processing (19)
  • .codemap/.gitignore
  • docs/architecture.md
  • docs/glossary.md
  • docs/plans/affected-tests-recipe.md
  • docs/plans/agent-surface-delivery.md
  • docs/roadmap.md
  • src/application/affected-engine.test.ts
  • src/application/affected-engine.ts
  • src/application/http-server.test.ts
  • src/application/mcp-server.test.ts
  • src/application/mcp-server.ts
  • src/application/recipe-params.test.ts
  • src/application/recipe-params.ts
  • src/application/recipe-recency.ts
  • src/application/tool-handlers.ts
  • src/cli/cmd-affected.test.ts
  • src/cli/cmd-affected.ts
  • templates/agent-content/skill/10-recipes-context.md
  • templates/recipes/affected-tests.md
📝 Walkthrough

Walkthrough

This PR introduces a new MCP/HTTP affected tool that identifies test dependencies from changed file paths. The change extracts shared logic into a reusable affected-engine module, refactors the existing CLI to delegate to it, wires the tool through both MCP and HTTP dispatch layers, and updates planning and documentation to reflect the new Phase 2 delivery.

Changes

MCP/HTTP Affected Tool Implementation

Layer / File(s) Summary
Shared affected-engine module
src/application/affected-engine.ts, src/application/affected-engine.test.ts
New module exports path normalization (normalizeChangedPathList, joinChangedPaths), change resolution (resolveAffectedChangedPaths using git or explicit paths), and recipe execution (executeAffectedTests via the affected-tests recipe). Comprehensive unit tests validate path deduplication, git-based change detection, and transitive test discovery with action metadata.
CLI refactoring to shared engine
src/cli/cmd-affected.ts
Delegates path normalization, change resolution, and test execution to the affected-engine module. Removes inline recipe parameter building and SQL query logic; re-exports CHANGED_PATH_DELIM and joinChangedPaths from the engine. Error handling and output formatting preserved for CLI clients.
Affected tool handler and schema
src/application/tool-handlers.ts
Implements handleAffected that composes resolveAffectedChangedPaths and executeAffectedTests from the shared engine. Exports affectedArgsSchema and AffectedArgs for request validation; converts engine failures and exceptions into ToolResult errors with appropriate status codes.
MCP server registration and integration tests
src/application/mcp-server.ts, src/application/mcp-server.test.ts
Registers affected as an MCP tool via registerAffectedTool, wrapping the handler with wrapToolResult. Tests verify tool listing, request/response payload structure with run-affected-tests actions, and allowlist-based gating via CODEMAP_MCP_TOOLS.
HTTP server dispatch and integration tests
src/application/http-server.ts, src/application/http-server.test.ts
Extends dispatchTool to route POST /tool/affected requests; adds affected to the TOOL_NAMES catalog. Tests verify tool response envelope and HTTP 400 validation errors for malformed inputs like non-integer max_depth.
Allowlist registration and documentation
src/application/mcp-tool-allowlist.ts, .changeset/mcp-affected-tool.md, docs/plans/*.md, templates/agent-content/*.md
Adds "affected" to recognized MCP tool names. Updates planning documents to mark PR 5 as merged and the MCP affected tool as shipped Phase 2 delivery. Updates agent guidance with affected tool contract, parameter semantics, and calling examples for both CLI and MCP/HTTP forms.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • stainless-code/codemap#35: Both PRs extend the MCP server/tooling scaffolding, with the main PR adding a new MCP affected tool wired into src/application/mcp-server.ts and tool-handlers.ts (in the same MCP transport/registry layer introduced by PR #35).

  • stainless-code/codemap#44: Both PRs extend the HTTP tool-dispatch layer—main PR adds the new affected tool to src/application/http-server.ts's TOOL_NAMES catalog and dispatchTool routing (via affectedArgsSchema/handleAffected), building on the HTTP API server infrastructure introduced in PR #44).

Poem

🐰 Hops with glee through paths aflame,
A new tool born—the "affected" name!
Shared engine sings, from CLI to MCP's call,
One module feeds them all!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding an MCP/HTTP affected tool as a Phase 2 follow-up. It is concise, specific, and clearly reflects the primary feature introduced across the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-affected-tool

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Move tryRecordRecipeRun to handleAffected/runAffectedCmd (recipe_recency
boundary). Align max_depth integer validation, HTTP 400 vs 500, agent
changed_since error labels. Expand tests and architecture/docs updates.
…ests

Require integer coercion for recipe number params, document recency skip
on empty paths, and add MCP/HTTP/CLI parity tests for max_depth validation
and recipe_recency writes.
@SutuSebastian SutuSebastian merged commit 386ffa6 into main May 25, 2026
12 checks passed
@SutuSebastian SutuSebastian deleted the feat/mcp-affected-tool branch May 25, 2026 13:48
SutuSebastian added a commit that referenced this pull request May 25, 2026
@github-actions github-actions Bot mentioned this pull request May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant