SkillPedia Skills Encyclopedia
中文 EN

Skills 2026-05-29 02:16 UTC

skills-compat-manager

Committed by hnaymyh123-henry. Update Category: Performance & Efficiency Optimizations. Commit details: perf(mcp_server): lazy-init runtime context to fix MCP startup timeout. This update improves response speed and lowers resource consumption.

hnaymyh123-henry 8be1357 hnaymyh123-henry/skills-compat-manager

CommitRaw commit message

perf(mcp_server): lazy-init runtime context to fix MCP startup timeout

Before this change, importing app.mcp_server eagerly ran three expensive
operations at module load time:

  - build_skill_descriptions(SKILL_LIBRARY): reads SKILL.md (first 500
    bytes) from every skill in the library.
  - detect_runtime_context(): scans installed Python packages, CLI tools,
    and env vars.
  - load_runtime_snapshot + compute_runtime_diff + save_runtime_snapshot.

On a library with ~150 skills this totalled 7-10s on Windows, and the
result returned to the client's MCP initialize handshake only after
~12s — past Claude Code's ~10s MCP startup timeout. The server was
silently killed before its 8 tools (list_skills, get_skill, etc.) ever
became visible to the agent.

Fix: move the runtime-context work into get_runtime_context(), which
now lazy-initialises on first call and caches. Replace the embedded
{_skill_catalog} in get_skill's tool description with a static pointer
to list_skills(), since the f-string substitution was evaluated at
decorator-application time (i.e. at import).

refresh_runtime and apply_fix kept their force-reset semantics but now
fall back to the on-disk snapshot as old_context when no in-memory
context exists yet, so the diff still reports cross-session changes.

Measured on Windows 11, Python 3.11, library of 157 skills:
  - Module import:     7.76s -> 3.36s  (remainder is FastMCP import)
  - Init handshake:    12.29s -> 2.15s
  - First list_skills: n/a (server never started) -> 5.18s end-to-end

All 17 existing tests in tests/test_mcp_server.py pass unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>