MCPcopy Index your code
hub / github.com/anomalyco/opencode / getFreeLoopbackPort

Function getFreeLoopbackPort

packages/opencode/test/mcp/oauth-callback.test.ts:6–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { parseRedirectUri } from "../../src/mcp/oauth-provider"
5
6async function getFreeLoopbackPort(): Promise<number> {
7 return new Promise((resolve, reject) => {
8 const probe = createNetServer()
9 probe.once("error", reject)
10 probe.listen(0, "127.0.0.1", () => {
11 const address = probe.address()
12 probe.close(() => {
13 if (typeof address === "object" && address) {
14 resolve(address.port)
15 return
16 }
17 reject(new Error("Could not allocate a loopback port"))
18 })
19 })
20 })
21}
22
23async function canConnect(host: string, port: number): Promise<boolean> {
24 return new Promise((resolve) => {

Callers 1

Calls 3

resolveFunction · 0.50
rejectFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected