Skip to content

Comments

fix(plugin-mcp): pass MCP request context through tool callbacks to fetch#2553

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mcp-header-passing
Draft

fix(plugin-mcp): pass MCP request context through tool callbacks to fetch#2553
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mcp-header-passing

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

MCP-generated tool handlers were discarding the RequestHandlerExtra (2nd arg of server.tool() callbacks), so callers had no way to propagate auth headers or other request context to the underlying API fetch.

Changes

  • plugin-client/src/components/Client.tsx — adds optional requestParam?: string prop; when set, appends , ${requestParam}?: unknown to the generated function signature and passes it as the second arg to fetch (non-configurable path only)
  • plugin-mcp/src/generators/mcpGenerator.tsx — passes requestParam="request" to Client so every MCP handler accepts and forwards request context
  • plugin-mcp/src/components/Server.tsx — updates server.tool() callback templates to capture and thread request through to handlers:
    • with params: async (params, request) => handler(params, request)
    • no params: async (_, request) => handler(request)

Generated output (before → after)

Before:

server.tool('getAll', 'Get all', { params }, async ({ params }) => {
  return getAllHandler({ params })
})

export async function getAllHandler({ params }: { params?: Params }): Promise<CallToolResult> {
  const res = await fetch({ method: 'GET', url: `/items`, params })
  // ...
}

After:

server.tool('getAll', 'Get all', { params }, async ({ params }, request) => {
  return getAllHandler({ params }, request)
})

export async function getAllHandler({ params }: { params?: Params }, request?: unknown): Promise<CallToolResult> {
  const res = await fetch({ method: 'GET', url: `/items`, params }, request)
  // ...
}

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is for the docs (no release).
Original prompt

This section details on the original issue you should resolve

<issue_title>MCP is not passing down headers to fetch</issue_title>
<issue_description>### What version of kubb is running?

4.22.0

What kind of platform do you use?

None

Your kubb.config.ts config file?

import { defineConfig } from '@kubb/core';
import { pluginOas } from '@kubb/plugin-oas';
import { pluginTs } from '@kubb/plugin-ts';
import { pluginMcp } from '@kubb/plugin-mcp';
import { pluginZod } from '@kubb/plugin-zod';

export default defineConfig({
  input: {
    path: './swagger-v1.json',
  },
  output: {
    format: 'prettier',
    path: './src/generated/v1',
    extension: { '.ts': '' },
    clean: true,
  },
  plugins: [
    pluginOas(),
    pluginTs(),
    pluginZod(),
    pluginMcp({
      output: {
        path: './mcp',
        barrelType: false,
      },
      client: {
        importPath: '../../client',
      },
      group: {
        type: 'tag',
        name: ({ group }) => `${group}Handlers`,
      },
    }),
  ],
});

Swagger/OpenAPI file?

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

What steps can reproduce the bug?

kubb generates such MCP tool

server.tool(
  'Project_getAll',
  'Get all',
  { params },
  async ({ params }) => {
    return projectGetAllHandler({ params });
  },
);

ideally it should pass down request (2nd argument in tool) to client and then client can pull out headers (auth, traceId) and pass it down to API call

// MCP tool
server.tool(
  'Project_getAll',
  'Get all',
  { params },
  async ({ params }, request) => {
    return projectGetAllHandler({ params }, request);
  },
);
import fetch from '../../../../client';

// Handler
export async function projectGetAllHandler({
  params,
}: { params }, request): Promise<
  Promise<CallToolResult>
> {
  const res = await fetch({ method: 'GET', url: `/project`, params }, request);
  return {
    content: [
      {
        type: 'text',
        text: JSON.stringify(res.data),
      },
    ],
  };
}

How often does this bug happen?

None

What is the expected behavior?

No response

Additional information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

⚠️ No Changeset found

Latest commit: c46b0eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MCP not passing down headers to fetch fix(plugin-mcp): pass MCP request context through tool callbacks to fetch Feb 22, 2026
Copilot AI requested a review from stijnvanhulle February 22, 2026 15:04
@github-actions github-actions bot added the bug Something isn't working label Feb 22, 2026
@autofix-ci
Copy link
Contributor

autofix-ci bot commented Feb 22, 2026

Auto fix applied for linting and formating

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

More templates

@kubb/agent

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/agent@2553

@kubb/cli

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/cli@2553

@kubb/core

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/core@2553

kubb

npm i https://pkg.pr.new/kubb-labs/kubb@2553

@kubb/mcp

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/mcp@2553

@kubb/oas

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/oas@2553

@kubb/plugin-client

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-client@2553

@kubb/plugin-cypress

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-cypress@2553

@kubb/plugin-faker

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-faker@2553

@kubb/plugin-mcp

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-mcp@2553

@kubb/plugin-msw

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-msw@2553

@kubb/plugin-oas

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-oas@2553

@kubb/plugin-react-query

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-react-query@2553

@kubb/plugin-redoc

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-redoc@2553

@kubb/plugin-solid-query

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-solid-query@2553

@kubb/plugin-svelte-query

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-svelte-query@2553

@kubb/plugin-swr

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-swr@2553

@kubb/plugin-ts

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-ts@2553

@kubb/plugin-vue-query

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-vue-query@2553

@kubb/plugin-zod

npm i https://pkg.pr.new/kubb-labs/kubb/@kubb/plugin-zod@2553

unplugin-kubb

npm i https://pkg.pr.new/kubb-labs/kubb/unplugin-kubb@2553

commit: c46b0eb

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.

MCP is not passing down headers to fetch

2 participants