tidewave 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,129 +1,174 @@
1
1
  # Tidewave
2
2
 
3
+ > Tidewave Web for Next.js is currently in alpha testing!
4
+
3
5
  Tidewave is the coding agent for full-stack web app development.
4
6
  [See our website](https://tidewave.ai) for more information.
5
7
 
6
- Our current release connects your editor's assistant to your web framework
7
- runtime via [MCP](https://modelcontextprotocol.io/). Support for Tidewave Web
8
- will come in future releases.
8
+ This package is recommended for JavaScript-powered backends as well as
9
+ JavaScript libraries/applications using a backend as a service (such as
10
+ Supabase). If you are using React with Phoenix, Rails, Django, or another
11
+ server-side framework, [follow the steps here instead](http://hexdocs.pm/tidewave/react.html).
9
12
 
10
- ## Usage
13
+ This project can also be used as a standalone Model Context Protocol (MCP)
14
+ server for your editors.
11
15
 
12
- ### Standalone MCP
16
+ ## Installation
13
17
 
14
- Tidewave's MCP server gives your editor and coding agents access to the
15
- documentation, type annotations, and source file locations of the packages being
16
- currently used by your project, without relying on external systems.
18
+ ### Next.js
17
19
 
18
- Simply configure your editor to run `tidewave` in the same directory as your
19
- `package.json` as a STDIO MCP Server:
20
+ Install it with:
20
21
 
21
- ```bash
22
- npx tidewave mcp
23
- # or with Bun
24
- bunx tidewave mcp
25
- # or with Deno
26
- deno run npm:tidewave mcp
22
+ ```sh
23
+ $ npm install -D tidewave
24
+ # or
25
+ $ yarn add -D tidewave
26
+ # or
27
+ $ pnpm add --save-dev tidewave
28
+ # or
29
+ $ bun add --dev tidewave
27
30
  ```
28
31
 
29
- Available MCP options:
32
+ Then create `pages/api/tidewave.ts` with:
30
33
 
31
- - `--prefix path` - Specify the directory to find the `package.json` file
34
+ ```typescript
35
+ import type { NextApiRequest, NextApiResponse } from 'next';
36
+
37
+ export default async function handler(
38
+ req: NextApiRequest,
39
+ res: NextApiResponse,
40
+ ) {
41
+ if (process.env.NODE_ENV === 'development') {
42
+ const { tidewaveHandler } = await import('tidewave/next-js');
43
+ const handler = await tidewaveHandler();
44
+ return handler(req, res);
45
+ } else {
46
+ res.status(404).end();
47
+ }
48
+ }
32
49
 
33
- ### HTTP MCP via Vite Plugin
50
+ export const config = {
51
+ runtime: 'nodejs',
52
+ api: {
53
+ bodyParser: false, // Tidewave already parses the body internally
54
+ },
55
+ };
56
+ ```
34
57
 
35
- Tidewave also provides HTTP-based MCP access through a Vite plugin for
36
- development environments. Add the plugin to your `vite.config.js`:
58
+ _Note: this uses the **Pages Router**, however it works regardless of the router
59
+ type you use in your application._
37
60
 
38
- ```javascript
39
- import { defineConfig } from 'vite';
40
- import tidewave from 'tidewave/vite-plugin';
61
+ Then create (or modify) `middleware.ts` with:
41
62
 
42
- export default defineConfig({
43
- plugins: [tidewave()],
44
- });
45
- ```
63
+ ```typescript
64
+ import { NextRequest, NextResponse } from 'next/server';
46
65
 
47
- This exposes MCP endpoints at `/tidewave/mcp` and `/tidewave/shell` during
48
- development.
66
+ export function middleware(req: NextRequest): NextResponse {
67
+ if (req.nextUrl.pathname.startsWith('/tidewave')) {
68
+ return NextResponse.rewrite(new URL(`/api/tidewave`, req.url));
69
+ }
49
70
 
50
- Configuration options:
71
+ // Here you could add your own logic or different middlewares.
72
+ return NextResponse.next();
73
+ }
51
74
 
52
- ```javascript
53
- tidewave({
54
- allowRemoteAccess: false, // Allow access from remote IPs
55
- allowedOrigins: ['localhost'], // Allowed origins: defaults to the Vite's host+port
56
- });
75
+ export const config = {
76
+ matcher: ['/tidewave/:path*'],
77
+ };
57
78
  ```
58
79
 
59
- ### HTTP MCP via Next.js Integration
80
+ Finally, we recommend creating the `instrumentation.ts` file below,
81
+ to expose your application's spans, events, and logs to Tidewave/MCP:
60
82
 
61
- Tidewave provides seamless integration with Next.js through a handler function.
62
- Add the handler to your API routes **and** `middleware.ts`:
83
+ ```typescript
84
+ // instrumentation.ts
85
+ import { NodeSDK } from '@opentelemetry/sdk-node';
86
+ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node';
87
+
88
+ export async function register() {
89
+ const runtime = process.env.NEXT_RUNTIME;
90
+ const env = process.env.NODE_ENV;
91
+
92
+ // Add your app own processes here existing configuration
93
+ const sdkConfig = {
94
+ spanProcessors: [],
95
+ logRecordProcessors: [],
96
+ };
97
+
98
+ // Conditionally add Tidewave processors in development
99
+ if (runtime === 'nodejs' && env === 'development') {
100
+ const { TidewaveSpanProcessor, TidewaveLogRecordProcessor } = await import(
101
+ 'tidewave/next-js/instrumentation'
102
+ );
103
+
104
+ sdkConfig.spanProcessors.push(new TidewaveSpanProcessor());
105
+ sdkConfig.logRecordProcessors.push(new TidewaveLogRecordProcessor());
106
+ }
107
+
108
+ const sdk = new NodeSDK(sdkConfig);
109
+ sdk.start();
110
+ }
111
+ ```
63
112
 
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
113
+ ### React + Vite
67
114
 
68
- **Pages Router** - Create `pages/api/tidewave/[...all].ts`:
115
+ Install it with:
69
116
 
70
- ```typescript
71
- import { tidewaveHandler } from 'tidewave/next-js';
117
+ ```sh
118
+ $ npm install -D tidewave
119
+ # or
120
+ $ yarn add -D tidewave
121
+ # or
122
+ $ pnpm add --save-dev tidewave
123
+ # or
124
+ $ bun add --dev tidewave
125
+ ```
72
126
 
73
- export default await tidewaveHandler();
127
+ Then configure your `vite.config.js` (also works for `.ts` and `.mjs`):
74
128
 
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
- };
129
+ ```javascript
130
+ import { defineConfig } from 'vite';
131
+ import tidewave from 'tidewave/vite-plugin';
132
+
133
+ export default defineConfig({
134
+ plugins: [tidewave()],
135
+ });
82
136
  ```
83
137
 
84
- This exposes MCP endpoints at `/api/tidewave/mcp` and `/api/tidewave/shell`.
138
+ ### Configuration
85
139
 
86
- Then create `middleware.ts` with:
140
+ Next.js' `tidewaveHandler` and Vite's `tidewave` accept the configuration options below:
87
141
 
88
- ```typescript
89
- import { tidewaveMiddleware } from 'tidewave/next-js';
142
+ - `allow_remote_access:` allow remote connections when true (default false)
143
+ - `allowed_origins:` defaults to the current host/port
144
+ - `team`: enable Tidewave Web for teams
90
145
 
91
- export const middleware = tidewaveMiddleware();
146
+ ## CLI
92
147
 
93
- export const config = {
94
- matcher: '/tidewave/(.*)',
95
- };
96
- ```
148
+ Tidewave.js also comes with a CLI for developers who want to use it
149
+ as a standalone MCP or query its functionality directly. Note this
150
+ functionality is separate from Tidewave Web.
97
151
 
98
- In case you already have an existing `middleware.ts`:
152
+ ### STDIO MCP
99
153
 
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
- }
154
+ Configure your editor to run `tidewave` in the same directory as your
155
+ `package.json` as a STDIO MCP Server:
114
156
 
115
- export const config = {
116
- matcher: [
117
- '/tidewave/(.*)', // tidewave specific matcher
118
- '/your/route/', // your specific matcher
119
- ],
120
- };
157
+ ```bash
158
+ npx tidewave mcp
159
+ # or with Bun
160
+ bunx tidewave mcp
161
+ # or with Deno
162
+ deno run npm:tidewave mcp
121
163
  ```
122
164
 
123
- ### CLI Usage
165
+ Available options:
166
+
167
+ - `--prefix path` - Specify the directory to find the `package.json` file
168
+
169
+ ### Get docs / get source
124
170
 
125
- Tidewave also provides the MCP features over a CLI tool. Use it directly via
126
- npx/bunx/deno:
171
+ Fetch docs or retrieve the source location for classes, types, methods, etc:
127
172
 
128
173
  ```bash
129
174
  # Extract documentation for a symbol
@@ -149,14 +194,6 @@ npx tidewave source ./src/utils:formatDate
149
194
  npx tidewave source typescript:createProgram
150
195
  ```
151
196
 
152
- ### Runtime Support
153
-
154
- Tidewave JavaScript supports multiple JavaScript runtimes:
155
-
156
- - **Node.js** - Full support with npm/npx
157
- - **Bun** - Native support with bunx
158
- - **Deno** - Support via npm: protocol
159
-
160
197
  ## Contributing
161
198
 
162
199
  ```bash