Skip to main content
Glama

checkConnectivity

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

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 core handler function implementing the TCP connectivity check using Node.js net module. It creates a socket connection, handles connect, timeout, error, and close events, and resolves with a JSON-formatted result.
    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)
            }]
          });
        });
      });
    }
  • Input schema defining the parameters for the checkConnectivity tool: host (string, required), port (number, required), timeout (number, optional default 5000).
    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']
    },
  • The complete tool definition object for 'checkConnectivity', including name, description, inputSchema, and handler, exported as part of networkTools.
    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)
              }]
            });
          });
        });
      }
    },
  • TypeScript interface defining the structure of the connectivity check result: connected (boolean) and optional error (string). Used in the handler.
    export interface NetworkConnectivityResult {
      connected: boolean;
      error?: string;
    }
  • src/index.ts:28-35 (registration)
    Registration of all tools including networkTools (which contains checkConnectivity) into the allTools object used by MCP server handlers for listing and calling tools.
    const allTools: ToolKit = {
      ...systemTools,
      ...networkTools,
      ...geoTools,
      ...generatorTools,
      ...dateTimeTools,
      ...securityTools
    };

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