Skip to content

refactor(mcp): extract connection/manager modules, add discovery caching and tests#194

Merged
im10furry merged 5 commits into
mainfrom
fix/windows-wsl-startup-bash-completion
Jun 9, 2026
Merged

refactor(mcp): extract connection/manager modules, add discovery caching and tests#194
im10furry merged 5 commits into
mainfrom
fix/windows-wsl-startup-bash-completion

Conversation

@im10furry

@im10furry im10furry commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Extract MCP connection logic from client.ts into dedicated connection.ts and manager.ts modules
  • Add MCPClientManager with connection pooling, ping health checks, config-change detection, and auto-cleanup
  • Add per-client discovery caching with ToolListChanged/PromptListChanged notification-driven invalidation
  • Fix stderr listener timing to capture handshake-phase output
  • Add assertJsonPayloadBudget validation on MCP tool arguments
  • Use
    ormalizeImageMediaType for safe Anthropic image block conversion
  • Fix mergeAbortSignals listener cleanup
  • Fix ListMcpResourcesTool indentation and add error logging

Changes

File Change
src/services/mcp/connection.ts New — transport candidates, timeout, batch connect, stderr capture
src/services/mcp/manager.ts New — MCPClientManager class with health checks and connection pooling
src/services/mcp/client.ts Refactored to delegate to MCPClientManager
src/services/mcp/tools-integration.ts Discovery caching, notification handlers, cleanup fixes
src/entrypoints/mcp.ts JSON payload budget validation
src/tools/mcp/ListMcpResourcesTool/ Indentation fix + error logging
src/utils/ai/anthropic.ts
ormalizeImageMediaType utility
src/acp/validation.ts assertJsonPayloadBudget utility
ests/unit/mcp-manager-lifecycle.test.ts New — 9 tests for MCPClientManager
ests/unit/mcp-connection-internals.test.ts New — connection internals tests
ests/unit/mcp-content-normalization.test.ts New — image content normalization tests

Verification

  • bun run typecheck — pass
  • bun run lint — pass
  • bun test (16 MCP tests) — all pass

im10furry added 5 commits June 9, 2026 14:01
…ing and tests

- Extract connection logic from client.ts into connection.ts (transport candidates, timeout, batch connect)
- Add MCPClientManager in manager.ts with connection pooling, ping health checks, config-change detection, and auto-cleanup
- Add per-client discovery caching in tools-integration.ts with ToolListChanged/PromptListChanged notification invalidation
- Fix stderr listener timing in connection.ts: register before connectWithTimeout to capture handshake-phase output
- Add assertJsonPayloadBudget validation on MCP tool arguments in mcp.ts
- Use normalizeImageMediaType for safe Anthropic image block conversion
- Fix mergeAbortSignals listener cleanup (track and remove all listeners)
- Fix ListMcpResourcesTool indentation and add error logging to catch block
- Add cache.clear() compatibility shims on getClients/getMCPTools/getMCPCommands
- Add tests: MCPClientManager lifecycle, connection internals, content normalization
- Use normalizeAnthropicUsage/createAnthropicUsage for Usage type compliance
- Replace Hunk import with StructuredPatchHunk from diff@9
- Remove @anthropic-ai/sdk/shims/node import (no longer exists)
- Use normalizeImageMediaType for safe image content type conversion
- Add ToolUseLikeBlockParam type for mcp_tool_use/server_tool_use handling
- Fix ContentBlock text property access with proper type narrowing
- Fix ToolUseBlock caller property and Message container/stop_details fields
@im10furry im10furry merged commit dff4f95 into main Jun 9, 2026
3 checks passed
@im10furry im10furry deleted the fix/windows-wsl-startup-bash-completion branch June 9, 2026 06:52
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