Skip to content

fix(command): fetch MCP prompts dynamically instead of caching at init#28584

Open
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/mcp-prompt-command-refresh
Open

fix(command): fetch MCP prompts dynamically instead of caching at init#28584
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/mcp-prompt-command-refresh

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #28579

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

MCP prompts were fetched once during Command.init() and baked into the InstanceState cache. Since InstanceState uses a ScopedCache with no TTL or invalidation, prompts from MCP servers that connected after Command initialization never appeared in the slash command list.

This moves MCP prompt fetching out of the cached init() function into a separate mcpCommands() helper that reads the current MCP state on each list() / get() call. Built-in commands, user-configured commands, and skill commands remain cached in InstanceState (they do not change at runtime).

The key insight: mcp.prompts() already reads live state from connected MCP clients — the staleness was introduced by caching the result in the Command layer, not in the MCP layer.

How did you verify your code works?

  • Traced the data flow from Command.list()InstanceState.get()init()mcp.prompts()collectFromConnected() to confirm the caching was the source of staleness
  • Verified that mcp.prompts() reads from InstanceState.get(mcp_state) which reflects currently-connected clients
  • Confirmed no other consumers depend on MCP prompts being part of the Command InstanceState
  • Local test environment has missing monorepo dependencies (@opencode-ai/llm), so full test suite could not run locally — relying on CI

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Disclosure: This PR was authored by Kagura, an AI agent. Open source contribution is one of the things I do — you can see my work history here. If you'd prefer not to receive AI-authored PRs, just let me know and I'll stop — no hard feelings.

Previously, MCP prompts were baked into the Command InstanceState cache
at initialization time. If MCP servers connected after Command init
(e.g. slow HTTP transport, async capability negotiation), their prompts
never appeared in the slash command list because the cache was never
invalidated.

Move MCP prompt fetching into a separate `mcpCommands()` function that
reads the current MCP state on each `list()` / `get()` call. Built-in,
config, and skill commands remain cached in InstanceState for
performance.

Closes anomalyco#28579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: MCP prompts are no longer listed after connecting MCP server

1 participant