Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugin/controller/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MCPControllerRegister } from './lib/impl/mcp/MCPControllerRegister';
// 1. await add load unit is ready, controller may depend other load unit
// 2. load ${app_base_dir}app/controller file
// 3. ControllerRegister register controller implement
const majorVersion = parseInt(process.versions.node.split('.')[0], 10);

export default class ControllerAppBootHook {
private readonly app: Application;
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class ControllerAppBootHook {

// init http root proto middleware
this.prepareMiddleware(this.app.config.coreMiddleware);
if (this.app.mcpProxy) {
if (majorVersion >= 18) {
this.controllerRegisterFactory.registerControllerRegister(ControllerType.MCP, MCPControllerRegister.create);
// Don't let the mcp's body be consumed
this.app.config.coreMiddleware.unshift('mcpBodyMiddleware');
Expand Down Expand Up @@ -113,7 +114,7 @@ export default class ControllerAppBootHook {
}

async willReady() {
if (this.app.mcpProxy) {
if (majorVersion >= 18) {
await MCPControllerRegister.connectStatelessStreamTransport();
}
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/mcp-proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ export const MCPProxyHook: MCPControllerHook = {
await self.app.mcpProxy.registerClient(id, process.pid);
self.app.mcpProxy.setProxyHandler(MCPProtocols.SSE, async (req, res) => {
const sessionId = req.query?.sessionId ?? querystring.parse(url.parse(req.url).query ?? '').sessionId as string;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
self.app.RequestClass = EggRequest;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
self.app.ResponseClass = EggResponse;
const ctx = new EggContext(self.app as any, req, res) as any;
if (MCPControllerRegister.hooks.length > 0) {
for (const hook of MCPControllerRegister.hooks) {
await hook.preProxy?.(self.app.currentContext, req, res);
await hook.preProxy?.(ctx, req, res);
}
}
let transport: SSEServerTransport;
Expand Down
Loading