Skip to content

Commit 16c5602

Browse files
committed
fix: support node20
1 parent 2275553 commit 16c5602

File tree

9 files changed

+46
-7
lines changed

9 files changed

+46
-7
lines changed

.github/workflows/run-tests.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- windows-latest
2121
- macos-latest
2222
node:
23+
- 20
2324
- 22
2425
- 24
2526
steps:
@@ -32,17 +33,26 @@ jobs:
3233
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
3334
with:
3435
cache: npm
35-
node-version: ${{ matrix.node }}
36+
node-version: 22
3637

3738
- name: Install dependencies
3839
run: npm ci
3940

41+
- name: Build
42+
run: npm run build
43+
44+
- name: Set up Node.js
45+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
46+
with:
47+
cache: npm
48+
node-version: ${{ matrix.node }}
49+
4050
- name: Disable AppArmor
4151
if: ${{ matrix.os == 'ubuntu-latest' }}
4252
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
4353

4454
- name: Run tests
45-
run: npm run test
55+
run: npm run test:no-build
4656

4757
# Gating job for branch protection.
4858
test-success:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MCP clients.
2626

2727
## Requirements
2828

29-
- [Node.js 22](https://nodejs.org/) or newer.
29+
- [Node.js 20](https://nodejs.org/) or newer.
3030
- [Chrome](https://www.google.com/chrome/) current stable version or newer.
3131
- [npm](https://www.npmjs.com/).
3232

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"generate-docs": "npm run build && node --experimental-strip-types scripts/generate-docs.ts",
1616
"start": "npm run build && node build/src/index.js",
1717
"start-debug": "DEBUG=mcp:* DEBUG_COLORS=false npm run build && node build/src/index.js",
18-
"test": "npm run build && node --require ./build/tests/setup.js --test-reporter spec --test-force-exit --test 'build/tests/**/*.test.js'",
18+
"test:no-build": "node --require ./build/tests/setup.js --test-reporter spec --test-force-exit --test 'build/tests'",
19+
"test": "npm run build && npm run test:no-build",
1920
"test:only": "npm run build && node --require ./build/tests/setup.js --test-reporter spec --test-force-exit --test --test-only 'build/tests/**/*.test.js'",
2021
"test:only:no-build": "node --require ./build/tests/setup.js --test-reporter spec --test-force-exit --test --test-only 'build/tests/**/*.test.js'",
2122
"test:update-snapshots": "npm run build && node --require ./build/tests/setup.js --test-force-exit --test --test-update-snapshots 'build/tests/**/*.test.js'",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8+
import './polyfill.js';
9+
810
import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js';
911
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';
1012
import {

src/polyfill.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// For Node 20.
8+
if (!Promise.withResolvers) {
9+
Promise.withResolvers = function <T>() {
10+
let resolve, reject;
11+
const promise = new Promise<T>((_resolve, _reject) => {
12+
resolve = _resolve;
13+
reject = _reject;
14+
});
15+
return {promise, resolve, reject} as unknown as ReturnType<
16+
typeof Promise.withResolvers<T>
17+
>;
18+
};
19+
}

tests/setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
import {it} from 'node:test';
77

8+
if (!it.snapshot) {
9+
it.snapshot = {
10+
setResolveSnapshotPath: () => {},
11+
setDefaultSnapshotSerializers: () => {},
12+
};
13+
}
14+
815
// This is run by Node when we execute the tests via the --require flag.
916
it.snapshot.setResolveSnapshotPath(testPath => {
1017
// By default the snapshots go into the build directory, but we want them

tests/tools/performance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('performance', () => {
161161
context,
162162
);
163163

164-
t.assert.snapshot(response.responseLines.join('\n'));
164+
t.assert.snapshot?.(response.responseLines.join('\n'));
165165
});
166166
});
167167

tests/trace-processing/parse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ describe('Trace parsing', async () => {
2626
assert.ok(result?.insights);
2727

2828
const output = getTraceSummary(result);
29-
t.assert.snapshot(output);
29+
t.assert.snapshot?.(output);
3030
});
3131
});

tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
6+
import '../src/polyfill.js';
77
import puppeteer, {Browser} from 'puppeteer';
88
import {HTTPRequest, HTTPResponse} from 'puppeteer-core';
99
import {McpResponse} from '../src/McpResponse.js';

0 commit comments

Comments
 (0)