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';
6
6
import type { NextRequest } from 'next/server' ;
7
7
import { z } from 'zod' ;
8
8
9
- async function handler ( request : NextRequest , { params } : { params : Promise < RouteLayoutParams > } ) {
9
+ async function handler (
10
+ nextRequest : NextRequest ,
11
+ { params } : { params : Promise < RouteLayoutParams > }
12
+ ) {
10
13
const { context } = await getStaticSiteContext ( await params ) ;
11
14
const { dataFetcher, linker, site } = context ;
12
15
@@ -66,9 +69,7 @@ async function handler(request: NextRequest, { params }: { params: Promise<Route
66
69
}
67
70
) ;
68
71
} ,
69
- {
70
- // Optional server options
71
- } ,
72
+ { } ,
72
73
{
73
74
basePath : context . linker . toPathInSite ( '~gitbook/' ) ,
74
75
streamableHttpEndpoint : '/mcp' ,
@@ -78,6 +79,13 @@ async function handler(request: NextRequest, { params }: { params: Promise<Route
78
79
}
79
80
) ;
80
81
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 ) ;
81
89
return mcpHandler ( request ) ;
82
90
}
83
91
You can’t perform that action at this time.
0 commit comments