Skip to content

Commit cf2051e

Browse files
facundofariasclaude
andcommitted
fix: Add Node 16+ compatibility with node-fetch
Replace undici with node-fetch v2 to support Node.js 16+, which is commonly used by Claude Desktop/Code installations. Changes: - Replace undici with node-fetch@2 for broader Node.js compatibility - Update engine requirement from >=20.0.0 to >=16.0.0 - Add @types/node-fetch for TypeScript support - Update tsconfig.json to include node types - Simplify fetch implementation using node-fetch types - Update documentation to reflect Node 16+ requirement This fixes the "fetch is not defined" and "ReadableStream is not defined" errors encountered when Claude Desktop/Code uses Node v16. Tested with Node v16.20.2 (Claude Desktop default) and Node v24.5.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0e6a39d commit cf2051e

File tree

7 files changed

+159
-13
lines changed

7 files changed

+159
-13
lines changed

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Restart Claude Desktop to test.
7070
**Shared Core:**
7171
- `src/mcp-server.ts`: Factory function `createMCPServer(username, password, account)` that returns a configured MCP Server instance. Used by both stdio and hosted modes.
7272
- `src/tools.ts`: Defines 6 MCP tools (list_projects, get_project, list_servers, list_deployments, get_deployment, create_deployment) with Zod validation schemas
73-
- `src/api-client.ts`: DeployHQClient class for HTTP Basic Auth API calls to DeployHQ REST API
73+
- `src/api-client.ts`: DeployHQClient class for HTTP Basic Auth API calls to DeployHQ REST API. Uses node-fetch for Node 16+ compatibility.
7474

7575
**Transport Handlers (hosted mode only):**
7676
- `src/transports/sse-handler.ts`: Server-Sent Events transport
@@ -159,4 +159,4 @@ For stdio testing, use absolute path to `dist/stdio.js` in client configs to avo
159159

160160
## Important: Node Version
161161

162-
Requires Node.js >=20.0.0 (specified in package.json engines). The stdio transport uses modern Node.js features.
162+
Requires Node.js >=16.0.0 (specified in package.json engines). The server uses node-fetch for HTTP requests to ensure compatibility with Node 16+, which is commonly used by Claude Desktop/Code installations.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ Once configured, you can ask Claude to interact with DeployHQ:
132132

133133
## 📦 Prerequisites
134134

135-
- Node.js 20+
135+
- **Node.js 16+** (Node 20+ recommended)
136136
- DeployHQ account with API access
137137

138+
**Note**: The server uses `node-fetch` for HTTP requests, providing compatibility with Node.js 16 and above.
139+
138140
## 🔧 Local Development
139141

140142
### 1. Clone the repository

docs/USER_GUIDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This guide will help you configure and use the DeployHQ MCP Server with Claude D
2727

2828
- **Claude Desktop** (for GUI) or **Claude Code CLI** (for terminal) installed
2929
- DeployHQ account with API access
30-
- Node.js 20 or higher installed
30+
- Node.js 16 or higher installed (Node 20+ recommended)
3131
- For development: Git and npm/npx
3232

3333
### Getting Your DeployHQ Credentials
@@ -423,12 +423,12 @@ Choose the scope that best fits your needs. For most users, `--scope user` or us
423423

424424
**Possible Causes**:
425425
- Node.js not installed
426-
- Node.js version too old (requires v20+)
426+
- Node.js version too old (requires v16+, v20+ recommended)
427427
- PATH not configured correctly
428428

429429
**Solution**:
430-
1. Install Node.js 20 or higher: `brew install node` (macOS) or download from nodejs.org
431-
2. Verify installation: `node --version`
430+
1. Install Node.js 16 or higher: `brew install node` (macOS) or download from nodejs.org
431+
2. Verify installation: `node --version` (should show v16.0.0 or higher)
432432
3. Restart Claude Desktop/Code after installing Node.js
433433
4. For development builds, ensure you ran `npm run build`
434434

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"type": "module",
1010
"engines": {
11-
"node": ">=20.0.0"
11+
"node": ">=16.0.0"
1212
},
1313
"scripts": {
1414
"dev": "tsx --watch src/index.ts",
@@ -29,13 +29,15 @@
2929
"license": "MIT",
3030
"dependencies": {
3131
"@modelcontextprotocol/sdk": "^1.0.4",
32-
"express": "^4.21.1",
3332
"dotenv": "^16.4.5",
33+
"express": "^4.21.1",
34+
"node-fetch": "^2.7.0",
3435
"zod": "^3.23.8"
3536
},
3637
"devDependencies": {
3738
"@types/express": "^5.0.0",
3839
"@types/node": "^22.9.0",
40+
"@types/node-fetch": "^2.6.13",
3941
"@typescript-eslint/eslint-plugin": "^8.13.0",
4042
"@typescript-eslint/parser": "^8.13.0",
4143
"eslint": "^9.14.0",

src/api-client.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Provides type-safe access to DeployHQ API endpoints
44
*/
55

6+
// Import fetch for Node 16+ compatibility
7+
import fetch, { RequestInit as NodeFetchRequestInit } from 'node-fetch';
8+
69
/**
710
* Custom error class for DeployHQ API errors
811
*/
@@ -153,23 +156,24 @@ export class DeployHQClient {
153156
* @param options - Fetch options
154157
* @returns Parsed JSON response
155158
*/
156-
private async request<T>(path: string, options: RequestInit = {}): Promise<T> {
159+
private async request<T>(path: string, options: NodeFetchRequestInit = {}): Promise<T> {
157160
const url = `${this.baseUrl}${path}`;
158161

159162
const controller = new AbortController();
160163
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
161164

162165
try {
163166
const response = await fetch(url, {
164-
...options,
167+
method: options.method || 'GET',
165168
headers: {
166169
'Authorization': this.authHeader,
167170
'Accept': 'application/json',
168171
'Content-Type': 'application/json',
169-
...options.headers,
172+
...(options.headers as Record<string, string> || {}),
170173
},
174+
body: options.body,
171175
signal: controller.signal,
172-
});
176+
} as NodeFetchRequestInit);
173177

174178
clearTimeout(timeoutId);
175179

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"module": "NodeNext",
55
"moduleResolution": "NodeNext",
66
"lib": ["ES2022"],
7+
"types": ["node"],
78
"outDir": "./dist",
89
"rootDir": "./src",
910
"strict": true,

0 commit comments

Comments
 (0)