MCP plugin disconnects when context is compacted (/compact)

Resolved 💬 3 comments Opened Apr 12, 2026 by parkhyeonjea-collab Closed Apr 16, 2026

Description

The Telegram MCP plugin (and likely other stdio-based MCP plugins) disconnects every time context compaction occurs — either manually via /compact or automatically when approaching context limits.

Steps to Reproduce

  1. Start Claude Code with the Telegram channel plugin: claude --channels plugin:telegram@claude-plugins-official
  2. Use the Telegram MCP tools normally (reply, react, etc.)
  3. Trigger context compaction via /compact or let it happen automatically
  4. After compaction, the MCP tools become unavailable with "MCP server disconnected"

Root Cause Analysis

The plugin server uses StdioServerTransport (stdin/stdout). When Claude Code compacts context, the stdin pipe is closed/reset, triggering the shutdown handler:

process.stdin.on("end", shutdown)
process.stdin.on("close", shutdown)

The shutdown() function then kills the bot process and exits. This is intentional for zombie prevention, but it causes the plugin to die during normal context management operations.

Expected Behavior

MCP plugin connections should survive context compaction. The plugin process should remain alive and reconnect after compaction completes.

Actual Behavior

Every /compact or automatic context compression kills the MCP connection. The plugin process terminates. Users must restart Claude Code to restore the connection.

Impact

  • In long conversations, context compaction is frequent — the plugin disconnects multiple times per session
  • Users lose the ability to send/receive Telegram messages mid-conversation
  • The only workaround is restarting Claude Code entirely

Environment

  • Claude Code: latest (installed via npm)
  • OS: Linux (WSL2)
  • Plugin: plugin:telegram@claude-plugins-official v0.0.5
  • MCP SDK: @modelcontextprotocol/sdk ^1.0.0

Suggested Fix

Either:

  1. Preserve stdio pipes across context compaction (do not close/reopen MCP connections)
  2. Automatically reconnect MCP plugins after compaction
  3. Provide a mechanism for plugins to distinguish compaction reset from session ended

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗