Skip to main content
Glama

checkConnectivity

Test TCP connectivity to a specified host and port, with configurable timeout, to diagnose network reachability and troubleshoot connection issues.

Instructions

Test TCP connectivity to a host and port

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesTarget host
portYesTarget port
timeoutNoConnection timeout in milliseconds

Implementation Reference

  • The async handler function that tests TCP connectivity to the specified host and port using node:net.createConnection. Handles connection events, timeout, errors, and resolves with a JSON stringified NetworkConnectivityResult.
    handler: async ({ host, port, timeout = 5000 }: { host: string; port: number; timeout?: number }) => { return new Promise<{ content: Array<{ type: string, text: string }> }>((resolve) => { const result: NetworkConnectivityResult = { connected: false }; const socket = createConnection(port, host); socket.setTimeout(timeout); socket.on('connect', () => { result.connected = true; socket.end(); }); socket.on('timeout', () => { result.error = 'Connection timed out'; socket.destroy(); }); socket.on('error', (err) => { result.error = err.message; }); socket.on('close', () => { resolve({ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }); }); }); }
  • JSON schema for tool inputs: required host (string) and port (number), optional timeout (number, default 5000 ms).
    inputSchema: { type: 'object', properties: { host: { type: 'string', description: 'Target host' }, port: { type: 'number', description: 'Target port' }, timeout: { type: 'number', description: 'Connection timeout in milliseconds', default: 5000 } }, required: ['host', 'port'] },
  • Tool definition and registration as part of the exported networkTools object, which is later spread into allTools in src/index.ts for MCP server handling.
    checkConnectivity: { name: 'checkConnectivity', description: 'Test TCP connectivity to a host and port', inputSchema: { type: 'object', properties: { host: { type: 'string', description: 'Target host' }, port: { type: 'number', description: 'Target port' }, timeout: { type: 'number', description: 'Connection timeout in milliseconds', default: 5000 } }, required: ['host', 'port'] }, handler: async ({ host, port, timeout = 5000 }: { host: string; port: number; timeout?: number }) => { return new Promise<{ content: Array<{ type: string, text: string }> }>((resolve) => { const result: NetworkConnectivityResult = { connected: false }; const socket = createConnection(port, host); socket.setTimeout(timeout); socket.on('connect', () => { result.connected = true; socket.end(); }); socket.on('timeout', () => { result.error = 'Connection timed out'; socket.destroy(); }); socket.on('error', (err) => { result.error = err.message; }); socket.on('close', () => { resolve({ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }); }); }); } },

Other Tools

Related Tools

Latest Blog Posts

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/cyanheads/toolkit-mcp-server'

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