Skip to content

Preserve prompt message structure through vMCP relay#4334

Merged
JAORMX merged 1 commit intomainfrom
fix-prompt-messages
Mar 24, 2026
Merged

Preserve prompt message structure through vMCP relay#4334
JAORMX merged 1 commit intomainfrom
fix-prompt-messages

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented Mar 24, 2026

Summary

The vMCP relay was flattening prompt messages into a single "[role] text\n" string, losing individual message roles, content types (images, audio), and multi-message structure. AI clients receiving prompts through the relay got a degraded single-string representation instead of the structured messages the backend MCP server returned.

This changes PromptGetResult.Messages from string to []PromptMessage, preserving each message's role and full content structure through the entire relay path (backend → session → client → handler factory → MCP response).

  • Add PromptMessage type with Role and Content fields to vmcp.types
  • Replace lossy ConvertPromptMessages (string concatenation) with ConvertMCPPromptMessages / ToMCPPromptMessages round-trip converters
  • Update handler factory to relay structured messages instead of wrapping a flat string in a synthetic "assistant" message
  • Update all tests to assert on structured message content

Type of change

  • Bug fix

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)

Does this introduce a user-facing change?

Prompt responses from virtual MCP servers now preserve the original message structure (roles, content types) from backend servers, instead of flattening them into a single text string.

Special notes for reviewers

This is one of three related PRs fixing vMCP relay fidelity:

  • This PR: prompt message structure
  • fix-resource-relay: resource text/blob distinction and per-item metadata
  • fix-content-annotations: per-content annotations (audience, priority, lastModified)

Generated with Claude Code

The vMCP prompt relay flattened all backend messages into a single
string with "[role] text\n" format, discarding non-text content and
individual message roles. The handler then wrapped this flat string
as a single "assistant" message, losing the original conversation
structure.

Replace the lossy ConvertPromptMessages with structured
ConvertMCPPromptMessages/ToMCPPromptMessages that preserve individual
messages with their original roles and full content types (text, image,
audio, embedded resource, resource link). This removes the documented
"Phase 1 limitation" for prompt message handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the size/S Small PR: 100-299 lines changed label Mar 24, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.10%. Comparing base (5769a5d) to head (ed0b7b8).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/conversion/content.go 80.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4334      +/-   ##
==========================================
- Coverage   69.32%   69.10%   -0.23%     
==========================================
  Files         478      478              
  Lines       48415    48432      +17     
==========================================
- Hits        33564    33469      -95     
- Misses      12266    12303      +37     
- Partials     2585     2660      +75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JAORMX JAORMX merged commit df1a5cd into main Mar 24, 2026
69 of 70 checks passed
@JAORMX JAORMX deleted the fix-prompt-messages branch March 24, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants