Skip to content

fix(adapters): clean up MCP harness resources on every failure path - #132

Open
omkarjainak wants to merge 1 commit into
systemind-team:mainfrom
omkarjainak:fix/128-mcp-harness-cleanup
Open

omkarjainak wants to merge 1 commit into
systemind-team:mainfrom
omkarjainak:fix/128-mcp-harness-cleanup

Conversation

@omkarjainak

Copy link
Copy Markdown

Summary

Fixes #128. MCP harness turns no longer leak their loopback HTTP listener or tool bridge if creating the workspace temp directory (or any earlier setup step) fails.

Changes

  • Widened the try block in createMcpHarnessRuntime().run to cover seatText, MCP server creation, HTTP server binding, and mkdtemp.
  • Moved http and workspace to let declarations so cleanup can see them.
  • bridge.close() still runs first, followed by Promise.allSettled over http?.close() and workspace removal, so one failing cleanup step cannot skip the rest.

Rationale

Previously, mkdtemp ran after the HTTP server was bound but outside the try, so a failure there left the listener and bridge open. Promise.allSettled also prevents a rejected http.close() from skipping rm(workspace).

Testing

  • pnpm check
  • pnpm typecheck
  • pnpm vitest run packages/adapters/src/mcp-runtime.test.ts (64 tests)
  • pnpm format:check
  • git diff --check
  • Permission-denied paths are covered
  • Protocol compatibility is documented

Security

  • New capabilities deny by default
  • Tool discovery and invocation enforce the same grant
  • No credentials, private context, or evaluator data cross boundaries

Compatibility

  • No breaking contract change
  • Breaking contract change is documented in an ADR

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 harness turn leaves its loopback HTTP listener and tool bridge open if creating the workspace temp dir fails

1 participant