fix(command): fetch MCP prompts dynamically instead of caching at init#28584
Open
kagura-agent wants to merge 1 commit into
Open
fix(command): fetch MCP prompts dynamically instead of caching at init#28584kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #28579
Type of change
What does this PR do?
MCP prompts were fetched once during
Command.init()and baked into theInstanceStatecache. SinceInstanceStateuses aScopedCachewith 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 separatemcpCommands()helper that reads the current MCP state on eachlist()/get()call. Built-in commands, user-configured commands, and skill commands remain cached inInstanceState(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?
Command.list()→InstanceState.get()→init()→mcp.prompts()→collectFromConnected()to confirm the caching was the source of stalenessmcp.prompts()reads fromInstanceState.get(mcp_state)which reflects currently-connected clientsInstanceState@opencode-ai/llm), so full test suite could not run locally — relying on CIChecklist
🤖 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.