Skip to main content
Glama
by microsoft
net.ts1.17 kB
/** * Finds a random open port on the system. * * @returns A promise that resolves to an available port number. */ export function findRandomOpenPort(): Promise<number> { return new Promise<number>((resolve, reject) => { const server = require("net").createServer() server.unref() server.on("error", reject) server.listen(0, () => { const port = server.address().port server.close(() => resolve(port)) }) }) } /** * Checks if a specific port is in use. * * @param port The port number to check. * @returns A promise that resolves to true if the port is in use, or false otherwise. */ export function isPortInUse(port: number): Promise<boolean> { return new Promise<boolean>((resolve, reject) => { const server = require("net").createServer() server.once("error", (err: any) => { if (err.code === "EADDRINUSE") { resolve(true) } else { reject(err) } }) server.once("listening", () => { server.close(() => resolve(false)) }) server.listen(port) }) }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/microsoft/genaiscript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server