Skip to content

Commit 6a4dceb

Browse files
committed
Switching to undici to avoid node >18 dep
1 parent 71cf478 commit 6a4dceb

File tree

9 files changed

+27
-61
lines changed

9 files changed

+27
-61
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"scripts": {
2222
"build": "tsup src/index.ts --dts --format esm --external xdg-app-paths",
2323
"postbuild": "shx chmod +x dist/*.js",
24+
"check": "tsc --noEmit",
2425
"build:watch": "pnpm build --watch"
2526
},
2627
"dependencies": {
2728
"@iarna/toml": "^2.2.5",
2829
"@modelcontextprotocol/sdk": "^0.6.0",
2930
"chalk": "^5.3.0",
3031
"dotenv": "^16.4.5",
31-
"node-fetch": "^3.3.2",
32+
"undici": "^7.0.0",
3233
"xdg-app-paths": "^8.3.0",
3334
"zod": "^3.23.8"
3435
},
@@ -39,5 +40,8 @@
3940
"shx": "^0.3.4",
4041
"tsup": "^8.3.5",
4142
"typescript": "^5.6.2"
43+
},
44+
"engines": {
45+
"node": ">=16.17.0"
4246
}
4347
}

pnpm-lock.yaml

Lines changed: 9 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ export async function init(accountTag: string | undefined) {
3434
)
3535

3636
startSection(`Checking for existing Wrangler auth info`, `Step 1 of 3`)
37+
updateStatus(chalk.gray(`If anything goes wrong, try running 'npx wrangler@latest login' manually and retrying.`))
3738

3839
try {
3940
getAuthTokens()
4041
} catch (e: any) {
4142
updateStatus(`${chalk.underline.red('Warning:')} ${chalk.gray(e.message)}`, false)
42-
updateStatus(`Running '${chalk.yellow('npx wrangler login')}' and retrying...`)
43+
updateStatus(`Running '${chalk.yellow('npx wrangler login')}' and retrying...`, false)
4344

4445
const { stderr, stdout } = await execAsync('npx wrangler@latest login')
45-
if (stderr) {
46-
throw new Error(stderr)
47-
}
46+
if (stderr) updateStatus(chalk.gray(stderr))
47+
4848
getAuthTokens()
4949
}
5050

@@ -55,7 +55,7 @@ export async function init(accountTag: string | undefined) {
5555
if (await refreshToken()) {
5656
updateStatus('Successfully refreshed access token')
5757
} else {
58-
updateStatus('Failed to refresh access token')
58+
throw new Error('Failed to refresh access token')
5959
}
6060
}
6161

src/tools/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Tool } from '@modelcontextprotocol/sdk/types.js'
2-
import fetch from 'node-fetch'
2+
import { fetch } from 'undici'
33
import { config } from '../utils/helpers'
44
import { ToolHandlers } from '../utils/types'
55

src/tools/d1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add D1 tool definitions
22
import { config, log } from '../utils/helpers'
3-
import fetch from 'node-fetch'
3+
import { fetch } from 'undici'
44
import { Tool } from '@modelcontextprotocol/sdk/types.js'
55
import { ToolHandlers } from '../utils/types'
66

@@ -133,7 +133,7 @@ export async function handleD1CreateDatabase(name: string) {
133133
throw new Error(`Failed to create D1 database: ${error}`)
134134
}
135135

136-
const data = await response.json()
136+
const data = (await response.json()) as CloudflareD1DatabasesResponse
137137
return data.result
138138
}
139139

src/tools/kv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { config, log } from '../utils/helpers'
2-
import fetch from 'node-fetch'
2+
import { fetch } from 'undici'
33
import { ToolHandlers } from '../utils/types'
44
import { Tool } from '@modelcontextprotocol/sdk/types.js'
55

src/tools/r2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add R2 tool definitions
22
import { config, log } from '../utils/helpers'
3-
import fetch from 'node-fetch'
3+
import { fetch } from 'undici'
44
import { ToolHandlers } from '../utils/types'
55
import { Tool } from '@modelcontextprotocol/sdk/types.js'
66

src/tools/workers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { config, log } from '../utils/helpers'
2-
import fetch from 'node-fetch'
2+
import { fetch, FormData } from 'undici'
33
import { ToolHandlers } from '../utils/types'
44
import { Tool } from '@modelcontextprotocol/sdk/types.js'
55

src/utils/wrangler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import xdgAppPaths from 'xdg-app-paths'
1010
import TOML from '@iarna/toml'
1111
import assert from 'node:assert'
1212
import { mcpCloudflareVersion } from './helpers'
13+
import { fetch, Headers, Response, RequestInit, HeadersInit } from 'undici'
1314

1415
export function isDirectory(configPath: string) {
1516
try {
@@ -406,7 +407,7 @@ function cloneHeaders(headers: HeadersInit | undefined): Record<string, string>
406407
? Object.fromEntries(headers.entries())
407408
: Array.isArray(headers)
408409
? Object.fromEntries(headers)
409-
: { ...headers }
410+
: ({ ...headers } as Record<string, string>)
410411
}
411412

412413
function addAuthorizationHeaderIfUnspecified(headers: Record<string, string>, auth: ApiCredentials): void {

0 commit comments

Comments
 (0)