@@ -56,6 +56,70 @@ tidewave({
5656});
5757```
5858
59+ ### HTTP MCP via Next.js Integration
60+
61+ Tidewave provides seamless integration with Next.js through a handler function.
62+ Add the handler to your API routes ** and** ` middleware.ts ` :
63+
64+ > [ !WARNING] Note that the below helper functions will only work on development
65+ > mode ` NODE_ENV === 'development' ` if the validation fails, an Error will be
66+ > thrown
67+
68+ ** Pages Router** - Create ` pages/api/tidewave/[...all].ts ` :
69+
70+ ``` typescript
71+ import { tidewaveHandler } from ' tidewave/next-js' ;
72+
73+ export default await tidewaveHandler ();
74+
75+ // Next.js specific config
76+ export const config = {
77+ runtime: ' nodejs' ,
78+ api: {
79+ bodyParser: false , // tidewave already parses the body internally
80+ },
81+ };
82+ ```
83+
84+ This exposes MCP endpoints at ` /api/tidewave/mcp ` and ` /api/tidewave/shell ` .
85+
86+ Then create ` middleware.ts ` with:
87+
88+ ``` typescript
89+ import { tidewaveMiddleware } from ' tidewave/next-js' ;
90+
91+ export const middleware = tidewaveMiddleware ();
92+
93+ export const config = {
94+ matcher: ' /tidewave/(.*)' ,
95+ };
96+ ```
97+
98+ In case you already have an existing ` middleware.ts ` :
99+
100+ ``` typescript
101+ import { tidewaveMiddleware } from ' tidewave/next-js' ;
102+
103+ const withTidewave = tidewaveMiddleware ();
104+
105+ export function middleware(req : NextRequest ): Promise <NextResponse > {
106+ // This will return a unchanged NextResponse.next()
107+ // if path doesn't match with `/tidewave`
108+ // if does match it will rewrite to `/api/tidewave` instead
109+ withTidewave (req , (req : NextRequest ) => {
110+ // your own logic
111+ return NextResponse .json ({ message: ' hello, world!' });
112+ });
113+ }
114+
115+ export const config = {
116+ matcher: [
117+ ' /tidewave/(.*)' , // tidewave specific matcher
118+ ' /your/route/' , // your specific matcher
119+ ],
120+ };
121+ ```
122+
59123### CLI Usage
60124
61125Tidewave also provides the MCP features over a CLI tool. Use it directly via
0 commit comments