Skip to content

feat(mcp): complete protocol proxy surface - #70

Merged
mohanagy merged 3 commits into
developmentfrom
feat/issue-32-mcp-protocol
Jul 14, 2026
Merged

feat(mcp): complete protocol proxy surface#70
mohanagy merged 3 commits into
developmentfrom
feat/issue-32-mcp-protocol

Conversation

@mohanagy

@mohanagy mohanagy commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add resource template discovery, routing, opaque pagination, subscriptions, lifecycle-safe cleanup, and capability notifications to the MCP proxy.
  • Preserve upstream progress notifications that arrive immediately before responses, without reordering subsequent messages or breaking remote session cleanup.
  • Harden audit journal locking so a slow valid local holder cannot be bypassed; the new regression proves the fail-closed behavior.
  • Extend public contracts, configuration/docs, fixtures, and package coverage for the protocol surface.

Validation

  • npm test (67 files, 907 passed, 11 platform skips)
  • npm run test:core (17 files, 329 passed, 11 platform skips)
  • npm run test:coverage (all enforced thresholds pass)
  • npm run lint
  • npm run typecheck
  • npm run build
  • npm run smoke:cli
  • npm run check:pack
  • npm run test:package

Closes #32

Summary by CodeRabbit

  • New Features

    • Added MCP resource template support (discovery, routing, cursors/pagination, redaction, and collision handling).
    • Added resource subscription/unsubscription proxying with capability detection and update notification fan-out.
    • Forwarded request cancellation and progress notifications across both local STDIO and Streamable HTTP upstreams.
    • Expanded multi-upstream listing and change propagation behavior for resources, prompts, and tools.
  • Bug Fixes

    • Improved audit journal lock probing and ensured safer handling of contention/timeouts.
    • Added additional stable CLI exit-code mappings for template/subscription failures.
  • Documentation

    • Updated configuration, architecture, library API, and README to describe the expanded template/subscription and multi-upstream/progress/cancellation behaviors.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Miftah now proxies MCP resource templates, subscriptions, aggregate pagination, list-change notifications, progress, and cancellation across STDIO and Streamable HTTP upstreams. Registries, pipelines, transports, identity verification, tests, fixtures, error mappings, and documentation were updated.

Changes

MCP protocol conformance

Layer / File(s) Summary
Upstream request and transport contracts
src/upstream/*, src/utils/errors.ts, src/cli/exit-codes.ts
Request cancellation, progress ordering, lifecycle handling, list-change notifications, and protocol error mappings are supported.
Resource templates and cancellable discovery
src/mcp/server/resource-prompt-registry.ts, src/mcp/server/tool-registry.ts
Template routes, namespacing, redaction, cursor continuation, invalidation epochs, collision handling, progress aggregation, and shared cancellation are implemented.
Server forwarding and subscriptions
src/mcp/server/miftah-server.ts, src/mcp/server/operation-pipeline.ts
Request context is forwarded, subscription capability is gated, transitions are serialized, matching updates are proxied, and cleanup is bounded across lifecycle changes.
Identity verification
src/identity/identity-manager.ts
Concurrent identity probes share cancellable upstream work while preserving per-caller cancellation and progress handling.
Validation and documentation
tests/*, README.md, docs/*, CHANGELOG.md
Tests and fixtures cover templates, subscriptions, pagination, notifications, progress, cancellation, transport ordering, and audit locking; documentation describes the expanded behavior.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Poem

A rabbit hops through templates bright,
With cursors paged just right.
Progress blooms and signals race,
Subscriptions find their proper place.
Cancellation leaves no snare—
MCP magic everywhere! 🐇


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (2 errors, 1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ❌ Error The audit journal lock hardening is unrelated to #32’s MCP proxy scope, so the PR includes at least one out-of-scope change. Move the audit journal locking fix into a separate PR, or link an issue that explicitly covers audit behavior.
Docstring Coverage ❌ Error Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers summary and validation, but it omits the required Security impact section from the template. Add a Security impact section and explicitly state the impact on routing, redaction, audit data, subprocesses, and failure behavior.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main MCP protocol proxy expansion covered by the changeset.
Linked Issues check ✅ Passed The changes add templates, subscriptions, pagination, progress/cancellation forwarding, capability gating, and protocol tests matching #32.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-32-mcp-protocol

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

@mohanagy

Copy link
Copy Markdown
Owner Author

@coderabbitai review

The initial CodeRabbit status has remained pending as Review in progress since 01:34 UTC with no review output, while all current-head Linux, macOS, Windows, quality, and package checks are green. Requesting a fresh review run.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

@mohanagy Understood — kicking off a fresh full review now since the previous run appears to have stalled.

✅ Action performed

Full review finished.


You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 44 minutes.

@mohanagy

Copy link
Copy Markdown
Owner Author

Merge-gate exception documented: CodeRabbit confirmed that its original review stalled, and its requested retry is unavailable for 44 minutes because of an adaptive rate limit. A thread-aware audit found zero review threads and no human reviews. All current-head required GitHub Actions checks are green. Proceeding under the repository rule that permits a demonstrably stuck CodeRabbit review to be ignored only after documenting the evidence.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mcp/server/miftah-server.ts`:
- Around line 494-528: The subscription-capability probe in
configureResourceSubscriptionCapability currently starts and stops every
profile/upstream serially, adding substantial startup cost. Reduce the probing
work while preserving the documented maxConcurrentProfiles limit and accurate
resource-subscription detection, reusing existing upstream/session management
symbols such as this.upstreams, get, closeProfile, and
resourceSubscriptionsAvailable.

In `@src/mcp/server/resource-prompt-registry.ts`:
- Around line 251-273: The resource-template registration path must detect
upstream template renames instead of reusing a route with a stale exposed name.
In the loop handling discovered templates, update the existing-route logic
around `existing`, `exposedName`, and `registerResourceTemplateRoute` to
validate that `existing.exposedName` matches the newly computed name and raise
`RESOURCE_TEMPLATE_COLLISION` when it differs, while preserving reuse for
unchanged templates.

In `@src/upstream/progress-preserving-transport.ts`:
- Around line 84-88: Update the finally-path in the progress-preserving
transport to reschedule draining when a synchronous notification handler failure
leaves pendingMessages non-empty, while preserving the existing responseDeferred
behavior and close propagation. Extend the recovery test to enqueue a response
before the handler throws, and verify that both the response and any requested
close are eventually delivered.

In `@tests/resource-prompt-registry.test.ts`:
- Around line 199-212: Correct the URI uniqueness assertion in the aggregate
pagination test by checking the Set’s size rather than using toHaveLength on the
Set. Keep the existing combined-resource mapping and expected count of 3 so the
test genuinely detects duplicate URIs.
- Around line 394-429: The test’s resolution expectation should assert the
expanded alpha template URI rather than the template name. Update the assertion
in the “removes failed template routes…” test around alphaUri so the expected
originalUri matches the substituted account://alpha/one value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a7baa5fa-1a46-4786-8ccf-3b7c5d2a425d

📥 Commits

Reviewing files that changed from the base of the PR and between 19c8253 and 766bcf1.

📒 Files selected for processing (30)
  • CHANGELOG.md
  • README.md
  • docs/architecture.md
  • docs/config.md
  • docs/library-api.md
  • src/audit/audit-journal.ts
  • src/cli/exit-codes.ts
  • src/identity/identity-manager.ts
  • src/mcp/server/miftah-server.ts
  • src/mcp/server/operation-pipeline.ts
  • src/mcp/server/resource-prompt-registry.ts
  • src/mcp/server/tool-registry.ts
  • src/upstream/progress-preserving-transport.ts
  • src/upstream/upstream-process-manager.ts
  • src/upstream/upstream-session.ts
  • src/utils/errors.ts
  • tests/audit.test.ts
  • tests/cli-exit-codes.test.ts
  • tests/fixtures/back-to-back-progress-upstream.mjs
  • tests/fixtures/fake-upstream.mjs
  • tests/helpers/fake-remote-upstream.ts
  • tests/identity-manager.test.ts
  • tests/mcp-wrapper.test.ts
  • tests/multi-upstream.test.ts
  • tests/package-contract.test.ts
  • tests/progress-preserving-transport.test.ts
  • tests/public-api.test.ts
  • tests/remote-transport.test.ts
  • tests/resource-prompt-registry.test.ts
  • tests/upstream-manager.test.ts

Comment thread src/mcp/server/miftah-server.ts
Comment thread src/mcp/server/resource-prompt-registry.ts
Comment thread src/upstream/progress-preserving-transport.ts
Comment thread tests/resource-prompt-registry.test.ts
Comment thread tests/resource-prompt-registry.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/upstream/progress-preserving-transport.ts`:
- Around line 130-132: Update asError to preserve the original thrown value when
it is not an Error, deriving the resulting Error message from that value instead
of always using the fixed generic message; retain existing Error instances
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 097f1b3b-53e4-4785-8ed8-363b867f066f

📥 Commits

Reviewing files that changed from the base of the PR and between 766bcf1 and 2e7e9b7.

📒 Files selected for processing (3)
  • src/upstream/progress-preserving-transport.ts
  • tests/progress-preserving-transport.test.ts
  • tests/resource-prompt-registry.test.ts

Comment thread src/upstream/progress-preserving-transport.ts
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.

[MCP] Complete resource templates, subscriptions, pagination, progress, cancellation, and notifications

1 participant