File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
packages/gitbook/src/app/sites/static/[mode]/[siteURL]/[siteData]/~gitbook/mcp Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ import { createMcpHandler } from 'mcp-handler';
66import type { NextRequest } from 'next/server' ;
77import { z } from 'zod' ;
88
9- async function handler ( request : NextRequest , { params } : { params : Promise < RouteLayoutParams > } ) {
9+ async function handler (
10+ nextRequest : NextRequest ,
11+ { params } : { params : Promise < RouteLayoutParams > }
12+ ) {
1013 const { context } = await getStaticSiteContext ( await params ) ;
1114 const { dataFetcher, linker, site } = context ;
1215
@@ -66,9 +69,7 @@ async function handler(request: NextRequest, { params }: { params: Promise<Route
6669 }
6770 ) ;
6871 } ,
69- {
70- // Optional server options
71- } ,
72+ { } ,
7273 {
7374 basePath : context . linker . toPathInSite ( '~gitbook/' ) ,
7475 streamableHttpEndpoint : '/mcp' ,
@@ -78,6 +79,13 @@ async function handler(request: NextRequest, { params }: { params: Promise<Route
7879 }
7980 ) ;
8081
82+ // Next.js request.url is the original URL and not the rewritten one from the middleware
83+ const requestURL = new URL (
84+ context . linker . toAbsoluteURL ( context . linker . toPathInSite ( '~gitbook/mcp' ) )
85+ ) ;
86+ requestURL . search = nextRequest . nextUrl . search ;
87+
88+ const request = new Request ( requestURL , nextRequest ) ;
8189 return mcpHandler ( request ) ;
8290}
8391
You can’t perform that action at this time.
0 commit comments