From 37bba552f2d35c1c2ddef8d6ec7a8ac946753e40 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Tue, 27 Jan 2026 19:49:17 +0800 Subject: [PATCH 1/2] fix: mcp header --- plugin/controller/lib/impl/mcp/MCPControllerRegister.ts | 4 ---- .../apps/mcp-app/hook-plugin/lib/MCPControllerHook.ts | 1 - .../test/fixtures/apps/mcp-proxy/app/controller/app.ts | 3 --- 3 files changed, 8 deletions(-) diff --git a/plugin/controller/lib/impl/mcp/MCPControllerRegister.ts b/plugin/controller/lib/impl/mcp/MCPControllerRegister.ts index bd740f61..d8f7ef96 100644 --- a/plugin/controller/lib/impl/mcp/MCPControllerRegister.ts +++ b/plugin/controller/lib/impl/mcp/MCPControllerRegister.ts @@ -219,7 +219,6 @@ export class MCPControllerRegister implements ControllerRegister { ctx.respond = false; ctx.set({ 'content-type': 'text/event-stream', - 'transfer-encoding': 'chunked', }); await ctx.app.ctxStorage.run(ctx, async () => { await mw(ctx, async () => { @@ -352,7 +351,6 @@ export class MCPControllerRegister implements ControllerRegister { ctx.set({ 'content-type': 'text/event-stream', - 'transfer-encoding': 'chunked', }); await mcpServerHelper.server.connect(transport); @@ -402,7 +400,6 @@ export class MCPControllerRegister implements ControllerRegister { ctx.respond = false; ctx.set({ 'content-type': 'text/event-stream', - 'transfer-encoding': 'chunked', }); await ctx.app.ctxStorage.run(ctx, async () => { @@ -471,7 +468,6 @@ export class MCPControllerRegister implements ControllerRegister { self.transports[id] = transport; ctx.set({ 'content-type': 'text/event-stream', - 'transfer-encoding': 'chunked', }); ctx.respond = false; const mcpServerHelper = self.mcpServerHelperMap[name ?? 'default'](); diff --git a/plugin/controller/test/fixtures/apps/mcp-app/hook-plugin/lib/MCPControllerHook.ts b/plugin/controller/test/fixtures/apps/mcp-app/hook-plugin/lib/MCPControllerHook.ts index e0207736..474a86ca 100644 --- a/plugin/controller/test/fixtures/apps/mcp-app/hook-plugin/lib/MCPControllerHook.ts +++ b/plugin/controller/test/fixtures/apps/mcp-app/hook-plugin/lib/MCPControllerHook.ts @@ -6,7 +6,6 @@ export const GetAlipayTeggHook = (app: Application) => { ctx.set({ 'content-type': 'text/event-stream', 'cache-control': 'no-cache', - 'transfer-encoding': 'chunked', }); try { const auth = ctx.get('authorization'); diff --git a/plugin/mcp-proxy/test/fixtures/apps/mcp-proxy/app/controller/app.ts b/plugin/mcp-proxy/test/fixtures/apps/mcp-proxy/app/controller/app.ts index d0898c96..ffc304f4 100644 --- a/plugin/mcp-proxy/test/fixtures/apps/mcp-proxy/app/controller/app.ts +++ b/plugin/mcp-proxy/test/fixtures/apps/mcp-proxy/app/controller/app.ts @@ -166,7 +166,6 @@ export default class App extends Controller { this.ctx.set({ 'content-type': 'text/event-stream', 'cache-control': 'no-cache', - 'transfer-encoding': 'chunked', }); const self = this; const transport = new SSEServerTransport('/message', this.ctx.res); @@ -255,7 +254,6 @@ export default class App extends Controller { this.ctx.set({ 'content-type': 'text/event-stream', 'cache-control': 'no-cache', - 'transfer-encoding': 'chunked', }); const eventStore = new InMemoryEventStore(); const self = this; @@ -305,7 +303,6 @@ export default class App extends Controller { this.ctx.set({ 'content-type': 'text/event-stream', 'cache-control': 'no-cache', - 'transfer-encoding': 'chunked', }); const transport = transports[sessionId] as StreamableHTTPServerTransport; await transport.handleRequest(this.ctx.req, this.ctx.res); From 3ae66785da1f4eaf25846eb92b1ed4f476e35c49 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Tue, 27 Jan 2026 20:38:50 +0800 Subject: [PATCH 2/2] fix: add ut --- plugin/mcp-proxy/test/proxy.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugin/mcp-proxy/test/proxy.test.ts b/plugin/mcp-proxy/test/proxy.test.ts index 1e8b05ac..fd14448d 100644 --- a/plugin/mcp-proxy/test/proxy.test.ts +++ b/plugin/mcp-proxy/test/proxy.test.ts @@ -4,6 +4,7 @@ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { CallToolRequest, CallToolResultSchema, ListToolsRequest, ListToolsResultSchema, LoggingMessageNotificationSchema } from '@modelcontextprotocol/sdk/types.js'; import assert from 'assert'; +import { fetch } from 'urllib'; async function listTools(client: Client) { const toolsRequest: ListToolsRequest = { @@ -133,7 +134,17 @@ describe('plugin/mcp-proxy/test/proxy.test.ts', () => { }); const baseUrl = await app.httpRequest() .post('/stream').url; - const streamableTransport = new StreamableHTTPClientTransport(new URL(baseUrl)); + const streamableTransport = new StreamableHTTPClientTransport(new URL(baseUrl), { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + fetch: async (...args) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const res = await fetch(...args); + assert.deepEqual(res.headers.has('content-length'), !res.headers.has('transfer-encoding')); + return res; + }, + }); const streamableNotifications: { level: string, data: string }[] = []; streamableClient.setNotificationHandler(LoggingMessageNotificationSchema, notification => { streamableNotifications.push({ level: notification.params.level, data: notification.params.data as string });