MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / getFreePort

Function getFreePort

test/server/streamableHttp.test.ts:12–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10import { listenOnRandomPort } from '../helpers/http.js';
11
12async function getFreePort() {
13 return new Promise(res => {
14 const srv = netCreateServer();
15 srv.listen(0, () => {
16 const address = srv.address()!;
17 if (typeof address === 'string') {
18 throw new Error('Unexpected address type: ' + typeof address);
19 }
20 const port = (address as AddressInfo).port;
21 srv.close(_err => res(port));
22 });
23 });
24}
25
26/**
27 * Test server configuration for StreamableHTTPServerTransport tests

Callers 2

Calls 1

closeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…