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: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ vite.config.ts.timestamp-*
# Coding agents
CLAUDE.md
.claude/
.mcp.json
.mcp.json

/.yalc/
yalc.lock
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,70 @@ tidewave({
});
```

### HTTP MCP via Next.js Integration

Tidewave provides seamless integration with Next.js through a handler function.
Add the handler to your API routes **and** `middleware.ts`:

> [!WARNING] Note that the below helper functions will only work on development
> mode `NODE_ENV === 'development'` if the validation fails, an Error will be
> thrown

**Pages Router** - Create `pages/api/tidewave/[...all].ts`:

```typescript
import { tidewaveHandler } from 'tidewave/next-js';

export default await tidewaveHandler();

// Next.js specific config
export const config = {
runtime: 'nodejs',
api: {
bodyParser: false, // tidewave already parses the body internally
},
};
```

This exposes MCP endpoints at `/api/tidewave/mcp` and `/api/tidewave/shell`.
Comment thread
zoedsoupe marked this conversation as resolved.

Then create `middleware.ts` with:

```typescript
import { tidewaveMiddleware } from 'tidewave/next-js';

export const middleware = tidewaveMiddleware();

export const config = {
matcher: '/tidewave/(.*)',
};
```

In case you already have an existing `middleware.ts`:

```typescript
import { tidewaveMiddleware } from 'tidewave/next-js';

const withTidewave = tidewaveMiddleware();

export function middleware(req: NextRequest): Promise<NextResponse> {
// This will return a unchanged NextResponse.next()
// if path doesn't match with `/tidewave`
// if does match it will rewrite to `/api/tidewave` instead
withTidewave(req, (req: NextRequest) => {
// your own logic
return NextResponse.json({ message: 'hello, world!' });
});
}

export const config = {
matcher: [
'/tidewave/(.*)', // tidewave specific matcher
'/your/route/', // your specific matcher
],
};
```

### CLI Usage

Tidewave also provides the MCP features over a CLI tool. Use it directly via
Expand Down
97 changes: 96 additions & 1 deletion bun.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ export default [
globals: {
...globals.node,
...globals.es2021,
BufferEncoding: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
},
rules: {
'no-unused-vars': 'off',
// TypeScript rules
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-var-requires': 'error',
Expand Down
4 changes: 3 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ curl-mcp body='{}' port='5001':
-H 'accept: application/json,text/event-stream' \
-H 'content-type: application/json' \
-d '{{body}}' \
-i \
http://localhost:{{port}}/tidewave/mcp

initialize-mcp:
Expand All @@ -14,8 +15,9 @@ list-tools-mcp port='5001':
curl-shell command port='5001':
curl -X POST http://localhost:{{port}}/tidewave/shell \
-H 'content-type: application/json' \
-H 'accept: text/event-stream,application/json' \
-H 'accept: application/json,text/event-stream' \
-d '{"command": "{{command}}"}' \
-i \
--output -

default:
Expand Down
Loading