Skip to content

Commit 0bbbf1d

Browse files
author
zoey
authored
feat: next.js support (#18)
1 parent 74a5701 commit 0bbbf1d

17 files changed

Lines changed: 1253 additions & 41 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,7 @@ vite.config.ts.timestamp-*
7171
# Coding agents
7272
CLAUDE.md
7373
.claude/
74-
.mcp.json
74+
.mcp.json
75+
76+
/.yalc/
77+
yalc.lock

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

61125
Tidewave also provides the MCP features over a CLI tool. Use it directly via

bun.lock

Lines changed: 96 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ export default [
1717
globals: {
1818
...globals.node,
1919
...globals.es2021,
20+
BufferEncoding: 'readonly',
2021
},
2122
},
2223
plugins: {
2324
'@typescript-eslint': tseslint,
2425
},
2526
rules: {
27+
'no-unused-vars': 'off',
2628
// TypeScript rules
27-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
29+
'@typescript-eslint/no-unused-vars': [
30+
'error',
31+
{
32+
args: 'after-used',
33+
argsIgnorePattern: '^_',
34+
varsIgnorePattern: '^_',
35+
caughtErrorsIgnorePattern: '^_',
36+
},
37+
],
2838
'@typescript-eslint/explicit-function-return-type': 'warn',
2939
'@typescript-eslint/no-explicit-any': 'warn',
3040
'@typescript-eslint/no-var-requires': 'error',

justfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ curl-mcp body='{}' port='5001':
33
-H 'accept: application/json,text/event-stream' \
44
-H 'content-type: application/json' \
55
-d '{{body}}' \
6+
-i \
67
http://localhost:{{port}}/tidewave/mcp
78

89
initialize-mcp:
@@ -14,8 +15,9 @@ list-tools-mcp port='5001':
1415
curl-shell command port='5001':
1516
curl -X POST http://localhost:{{port}}/tidewave/shell \
1617
-H 'content-type: application/json' \
17-
-H 'accept: text/event-stream,application/json' \
18+
-H 'accept: application/json,text/event-stream' \
1819
-d '{"command": "{{command}}"}' \
20+
-i \
1921
--output -
2022

2123
default:

0 commit comments

Comments
 (0)