Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
Looks good: embedded text resources from MCP prompts now reach the session prompt, both after an instruction and on their own. I copied the new tests onto the base branch, where the two embedded-resource cases fail; on this branch all 5 command-plugin tests pass, and typecheck in packages/core passes. Dropping the plain-string branch is safe, because getPrompt results are validated against the MCP schema before they get here, so content is always a typed object. Text resources are handled the same way as in tool results in mcp/client.ts.
Public API: unchanged (internal helper only).
One small point: the plain-text and media/blob test cases already pass on the base branch, so they don't cover the fix. They could be dropped to keep the change minimal.
|
Thanks for the review. Removed the standalone plain-text and media/blob cases in 125a79e so the new coverage stays focused on embedded text resources. The two resource regressions and the existing built-in command test all pass (3/3). I've updated the PR description to match. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #55181
Type of change
What does this PR do?
MCP prompt commands can return an instruction together with an embedded text resource containing the document, code, or other reference material the instruction depends on. OpenCode currently keeps the instruction but silently drops the resource body when it converts the MCP response into a session prompt. If the resource is the only message in the response, the generated prompt text is empty.
For example, a
prompts/getresponse containingReview this policy:followed by an embedded JSON resource withtext: '{"region":"EU"}'currently submits onlyReview this policy:. With this change, the session receives both pieces in order:Review this policy:\n{"region":"EU"}. A resource-only response likewise retains its text instead of becoming an empty prompt.The problem is in
promptMessageTextin the built-in command plugin. The surrounding code already walks all returned messages and joins their converted content, but the helper recognizes only ordinary text messages. Embedded resources are a valid MCP prompt content type and may already carry the complete body inresource.text. There is no need to read the URI again or change MCP discovery, transport, or session admission to preserve that body.This PR adds a text-resource branch to that helper and gives its parameter the existing
Mcp.PromptResultmessage-content type. The response is already validated by the MCP client, so the helper can distinguish the supported content forms directly instead of acceptingunknownand repeating generic object and property checks. Ordinary text still returnscontent.text; an embedded resource with atextfield returnscontent.resource.text; the remaining content forms retain the existing empty-string result.The check is based on the resource representation, rather than a
text/plainMIME restriction. JSON, Markdown, and source files can all be represented as text resources, and the server has already supplied their text. The mixed-message regression usesapplication/jsonspecifically to protect this behavior. The resource body is passed through directly, consistent with the existing text-resource handling in the MCP client. This does not add a URI prefix or otherwise change prompt formatting.The scope is deliberately limited to embedded text resources. Images, audio, and resources represented by base64
blobfields are not decoded or turned into prompt text. This PR does not introduce media attachments, additional network requests, or changes to message-role handling. The fix is shared by callers of the built-in MCP command path.How did you verify your code works?
Added two regression cases to the existing command-plugin test file. They register and execute the real command through
Command.Service, provide controlled MCP responses using the existing test fixture, and capture the resulting session prompt. This checks the full conversion path rather than a separate copy of the helper's logic.The cases cover an instruction followed by an embedded JSON text resource and a prompt containing only an embedded plain-text resource. Both assert the exact text submitted to the session. The original built-in
initandreviewcommand test also continues to pass.Validation:
cd packages/core && bun test test/plugin/command.test.ts: all 3 tests passed with the focused resource regressions and the existing built-in command test.cd packages/core && bun typecheck: passed for the changed core source and tests, withGOMAXPROCS=2andGOMEMLIMIT=1GiB.git diff origin/dev --check: passed.The change touches only the command conversion and its regression tests.
Screenshots / recordings
Not applicable. This changes the text submitted to a session, with exact input and output assertions in the regression tests.
Checklist