Skip to content

feat: Reduce MCP server memory footprint (~370 MB RSS per stdio process) #1641

@reinamora137

Description

@reinamora137

"Each Claude Code session spawns a dedicated task-master-ai Node.js process via stdio MCP, consuming ~370 MB RSS. At scale (15 parent + 50 subprocess sessions = 65 processes), this is ~24 GB just for TaskMaster."

Motivation

The MCP server loads 60+ npm dependencies including 10+ AI SDK providers (Anthropic, OpenAI, Google, Mistral, xAI, Perplexity, OpenRouter, AWS Bedrock, Azure), Sentry, googleapis, etc. — all at startup. However, 80% of MCP calls are pure JSON file I/O (reads, status updates, task additions) that never touch AI providers.

In environments with many concurrent sessions (agentic orchestration, multi-terminal development), memory consumption becomes the dominant resource constraint.

Proposed Solution

Lazy-load AI SDK providers — only import AI dependencies when an AI operation is actually requested:

  • Core ops (80% of calls): get_tasks, get_task, set_task_status, add_task (manual fields), use_tag, list_tags — need only fs, path, JSON parsing
  • AI ops (20% of calls): expand_task, parse_prd, update_task (with prompt) — need AI SDK

This could reduce idle RSS from ~370 MB to ~50-80 MB for sessions that primarily do read/status operations.

High-Level Workflow

  1. At startup, load only core modules (fs, path, JSON, git)
  2. Register all MCP tools with their schemas
  3. When an AI operation is called, dynamically import the required AI SDK provider
  4. Cache the imported provider for subsequent AI calls in the same session

Key Elements

  • Lazy import() for AI SDK packages (@anthropic-ai/sdk, openai, etc.)
  • Only load the provider configured in .taskmaster/config.json (main, research, fallback)
  • Consider TASK_MASTER_TOOLS mode — core mode should never load AI deps
  • Sentry could also be lazy-loaded or made opt-in

Example Workflow

# Current: All 370 MB loaded immediately
$ node task-master-ai  # RSS: 370 MB

# Proposed: Core only at startup
$ node task-master-ai  # RSS: ~50-80 MB
# First AI operation triggers lazy load
$ expand_task(...)     # RSS grows to ~200 MB (only loads configured provider)

Implementation Considerations

  • AI SDK lazy loading must handle async import gracefully
  • Provider selection already exists in config — extend to lazy init
  • Backward compatible — no API changes
  • core and standard modes benefit most (no AI ops expected)

Benchmarks (from our Python replacement)

We built a Python MCP server replacement that handles core ops natively:

  • Python server RSS: ~44 MB (handles 27 of 44 tools)
  • Node.js server RSS: ~370 MB (all 44 tools)
  • Savings at 65 processes: ~22 GB reduction

Out of Scope (Future Considerations)

  • HTTP/SSE transport for shared server (separate feature request)
  • Splitting into separate core/AI packages

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ai-modelsAI model integration and configurationarea:mcpMCP server and integrationenhancementNew feature or requestmedium-priorityImportant but not urgentrefactorChanges needed to code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions