Skip to content

fix(module): prefer structuredContent in code mode dispatch#207

Merged
HugoRCD merged 2 commits intonuxt-modules:mainfrom
Mat4m0:fix/structured-content-dispatch
Apr 7, 2026
Merged

fix(module): prefer structuredContent in code mode dispatch#207
HugoRCD merged 2 commits intonuxt-modules:mainfrom
Mat4m0:fix/structured-content-dispatch

Conversation

@Mat4m0
Copy link
Copy Markdown
Contributor

@Mat4m0 Mat4m0 commented Apr 6, 2026

The problem

structuredContent silently dropped in code mode dispatch (data loss)

When a tool handler returns structuredContent (the MCP spec's typed data channel), the dispatch function in buildDispatchFunctions() ignores it entirely and falls through to extracting text from result.content[].text. This silently loses IDs, booleans, and nested objects — the agent receives a stringified summary instead of the actual structured data.

This breaks any workflow that chains operations using returned data:

// Tool returns: { structuredContent: { ok: true, data: { id: "abc123" } } }
const created = await codemode.create_item({ title: "Test" });

// Expected: created.data.id === "abc123"
// Actual:   created === "Created item 'Test' successfully" (text fallback)
//           created.data is undefined → follow-up call fails

Root cause

buildDispatchFunctions() went straight to result.content text extraction without ever checking result.structuredContent.

Solution

Added a structuredContent check before the text extraction fallback:

// Prefer structuredContent when available (preserves typed data)
if (result.structuredContent != null) {
  return result.structuredContent
}

When structuredContent is present, it is returned directly — preserving typed fields (booleans, numbers, nested objects, IDs) for use in sandbox code. When absent, the existing content[].text extraction continues to work unchanged.

Files changed

File What changed
index.ts buildDispatchFunctions(): check result.structuredContent before text extraction
codemode.test.ts 5 new tests covering structuredContent dispatch

Test coverage

5 new tests in test/codemode.test.ts:

  • structuredContent preferred over text content — verifies the structured object is returned, not the text summary
  • typed fields preserved — booleans, numbers, nested objects pass through intact
  • operation chaining — create → use returned ID → update works end-to-end
  • text fallback unchanged — tools without structuredContent still work via content[].text
  • structuredContent-only result — handles results with no content array

All 150 tests pass (20 test files).

Test plan

  • pnpm test passes (150/150)
  • Tool returning structuredContent with an ID → sandbox code receives the ID, uses it in a follow-up call
  • Tool returning only content[].text (no structuredContent) → existing behavior unchanged

AI tools used

  • Claude Opus 4.6

Mat4m0 added 2 commits April 6, 2026 21:53
When a tool handler returns structuredContent (the MCP spec's typed data channel), buildDispatchFunctions() ignored it and fell through to extracting text from content[].text — silently losing IDs, booleans, and nested objects. This broke operation chaining where a returned ID is needed for follow-up calls.
…edContent handling

Updated the codemode tests to utilize a mockMcpExtra function, ensuring that structuredContent is correctly processed in tool handlers. Changed tool definitions from McpToolDefinition to McpToolDefinitionListItem for better type alignment.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 6, 2026

@Mat4m0 is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the bug Something isn't working label Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Thank you for following the naming conventions! 🙏

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 6, 2026

npm i https://pkg.pr.new/@nuxtjs/mcp-toolkit@207

commit: 736a70c

@HugoRCD HugoRCD merged commit 09ef513 into nuxt-modules:main Apr 7, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants