8000 fix(codegen): handle empty 2xx responses and skip undefined body fields by ghorhh-coder · Pull Request #167 · taskade/mcp · GitHub
[go: up one dir, main page]

Skip to content

fix(codegen): handle empty 2xx responses and skip undefined body fields - #167

Open
ghorhh-coder wants to merge 1 commit into
taskade:mainfrom
ghorhh-coder:fix/runtime-empty-responses-and-undefined-body
Open

ghorhh-coder wants to merge 1 commit into
taskade:mainfrom
ghorhh-coder:fix/runtime-empty-responses-and-undefined-body

Conversation

@ghorhh-coder
Copy link
Copy Markdown

Fixes two runtime issues in @taskade/mcp-openapi-codegen (src/runtime.ts, inlined into the generated server tool files):

  1. Skip undefined input keys when building body in prepareToolCallOperation

    • Previously, undefined properties in operation.input were copied into body, making Object.keys(body).length > 0 true and attaching Content-Type: application/json + body: "{}" even on GET/HEAD requests (which throws TypeError: Request with GET/HEAD method cannot have body in fetch).
    • Explicit null values are still preserved in body.
  2. Handle 204/205, empty, and plain-text 2xx responses in defaultExecuteToolCall

    • Previously, defaultExecuteToolCall unconditionally called response.json(), turning successful 204 No Content or empty 2xx responses into isError: true (SyntaxError: Unexpected end of JSON input).
    • Now returns null on 204/205 or empty response bodies, returns raw text when content-type is non-JSON, preserves the .json() fallback when a custom fetch mock omits .text(), and still surfaces invalid JSON when content-type is JSON.
    • normaliseResponse also guards JSON.stringify(response) ?? 'null' so text is always a string.

Verification

  • yarn build (regenerated tools.generated.ts and tools.v2.generated.ts)
  • yarn lint
  • yarn hosted-tools:check
  • yarn test (11 test files, 106 tests passing, including 5 new tests in runtime.test.ts)
  • npm pack smoke test in packages/openapi-codegen

@changeset-bot
changeset-bot Bot commented Dec 4, 2026
Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11368ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@taskade/mcp-openapi-codegen Patch
@taskade/mcp-server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0