Skip to content

fix(module): generate typed return values from tool outputSchema#210

Merged
HugoRCD merged 5 commits intonuxt-modules:mainfrom
Mat4m0:fix/codemode-output-types
Apr 7, 2026
Merged

fix(module): generate typed return values from tool outputSchema#210
HugoRCD merged 5 commits intonuxt-modules:mainfrom
Mat4m0:fix/codemode-output-types

Conversation

@Mat4m0
Copy link
Copy Markdown
Contributor

@Mat4m0 Mat4m0 commented Apr 6, 2026

The problem

Code mode returns Promise<unknown> for all tools, even those with outputSchema

All tool methods in code mode type definitions show => Promise<unknown> regardless of whether the tool defines an outputSchema. Agents must call a tool and inspect the result to learn its shape, wasting a round trip.

// Before — agent has no idea what comes back
declare const codemode: {
  workspace_overview: () => Promise<unknown>; // Get workspace stats
};

Root cause

generateToolTypeInfo() in types.ts only processes inputSchema for parameter types. The outputSchema field is ignored entirely, so every tool's return type defaults to Promise<unknown>.

Solution

After input schema processing, generateToolTypeInfo() now also processes tool.outputSchema using the same schema-to-TypeScript generation path:

  • Small schemas (<=3 primitive fields) are inlined: Promise<{ id: string; ok: boolean }>
  • Larger schemas get named interfaces: Promise<WorkspaceOverviewOutput>
  • No outputSchema falls back to Promise<unknown> (unchanged behavior)
  • Non-identifier property names are emitted safely with quotes, so generated declarations remain valid TypeScript
// After — agent sees the full return type
interface WorkspaceOverviewOutput {
  ok: boolean;
  data: { total: number; public: number; drafts: number };
}

declare const codemode: {
  workspace_overview: () => Promise<WorkspaceOverviewOutput>;
};

Catalog entries (generateToolCatalog) also include output interface declarations, so progressive-mode search results show return types too.

Note: runtime alignment for returning structured output is handled separately in PR #207. This PR is limited to generating the typed return declarations.

Files changed

File What
packages/nuxt-mcp-toolkit/src/runtime/server/mcp/codemode/types.ts Output type generation in generateToolTypeInfo(), shared schema-to-TypeScript generation, valid TS property-key emission, updated generateTypesFromTools() and generateToolCatalog()
packages/nuxt-mcp-toolkit/test/codemode.test.ts Added coverage for output type generation, including quoted property names in generated declarations

Test plan

  • pnpm test passes
  • pnpm lint passes

AI tools used

  • Claude Opus 4.6
  • GPT 5.4

Mat4m0 added 2 commits April 6, 2026 22:29
Tools with outputSchema now emit typed Promise return values in code
mode type definitions instead of Promise<unknown>. Small schemas (<=3 primitive fields) are inlined; larger schemas get named interfaces.
…pe generation

Added a new function to format TypeScript property keys, ensuring non-safe identifiers are quoted. Introduced a utility to generate schema type information, streamlining the handling of input and output schemas in tools. This improves type safety and clarity in generated type definitions.
@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
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Thank you for following the naming conventions! 🙏

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

pkg-pr-new bot commented Apr 6, 2026

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

commit: 7cb0985

@HugoRCD HugoRCD merged commit 3f109e3 into nuxt-modules:main Apr 7, 2026
7 of 8 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