Skip to main content
Glama

discover_client

Identify and optionally initiate an MCP client like Claude or Cline on macOS using the MCP Bridge Server to facilitate communication between AI clients.

Instructions

Find and optionally start an MCP client

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
autoStartNo
clientTypeYes
timeoutNo

Implementation Reference

  • The primary handler function that implements the logic for the 'discover_client' tool. It checks for connected or discovered clients and optionally starts a new client process if autoStart is enabled.
    private async handleClientDiscovery(params: any): Promise<ClientDiscoveryResult> { const { clientType, autoStart = false, timeout = this.config.clientStartupTimeoutMs || 30000 } = params; this.logger.info(`Discovering client of type: ${clientType}, autoStart: ${autoStart}`); // Check if client is already connected const connectedClients = this.connectionManager.getConnectedClientsByType(clientType); if (connectedClients.length > 0) { this.logger.info(`Found connected client: ${connectedClients[0].id}`); return { found: true, client: connectedClients[0] }; } // Try to find a discovered but not connected client const discoveredClients = this.discoveryManager.getClientsByType(clientType); if (discoveredClients.length > 0) { this.logger.info(`Found discovered client: ${discoveredClients[0].id}`); // Attempt to connect to the client this.connectionManager.handleRegistration(JSON.stringify( this.registrationProtocol.createRegisterMessage( clientType, { supportedMethods: ['tools/call'], supportedTransports: ['unix-socket'], targetType: clientType }, 'unix-socket', discoveredClients[0].id, discoveredClients[0].socketPath ) )); return { found: true, client: discoveredClients[0] }; } // If autoStart is true, attempt to start the client if (autoStart) { try { const startupOptions = this.getClientStartupOptions(clientType); if (!startupOptions) { this.logger.warn(`No startup configuration available for client type: ${clientType}`); return { found: false, error: `No startup configuration available for client type: ${clientType}` }; } const client = await this.startClient(clientType, startupOptions, timeout); this.logger.info(`Started client: ${client.id}`); return { found: true, client, startupAttempted: true, startupSuccessful: true }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; this.logger.error(`Failed to start client: ${errorMessage}`); return { found: false, error: `Failed to start client: ${errorMessage}`, startupAttempted: true, startupSuccessful: false }; } } this.logger.warn(`No ${clientType} clients available`); return { found: false, error: `No ${clientType} clients available` }; }
  • The input schema definition for the 'discover_client' tool, registered in the MCP server capabilities.
    'discover_client': { description: 'Find and optionally start an MCP client', inputSchema: { type: 'object', properties: { clientType: { type: 'string', enum: ['claude', 'cline'] }, autoStart: { type: 'boolean' }, timeout: { type: 'number' } }, required: ['clientType'] } },
  • src/server.ts:125-133 (registration)
    The request handler registration for tool calls, dispatching 'discover_client' requests to the handleClientDiscovery method.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === 'discover_client') { return this.handleClientDiscovery(request.params.arguments); } if (request.params.name === 'tools/call') { return this.handleToolCall(request.params.arguments); } throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`); });
  • Helper function to start a new client process when autoStart is requested in discover_client.
    private async startClient( clientType: string, options: ClientStartupOptions, timeout: number ): Promise<ClientInfo> { return new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { reject(new Error(`Client startup timed out after ${timeout}ms`)); }, timeout); try { const childProcess = spawn(options.command!, options.args || [], { env: { ...process.env, ...options.env }, cwd: options.cwd }); const client: ClientInfo = { id: randomUUID(), type: clientType as 'claude' | 'cline', transport: 'stdio', connected: true, lastSeen: new Date(), state: ConnectionState.CONNECTING, processId: childProcess.pid }; this.stateManager.registerClient(client); // Wait for initial connection childProcess.once('spawn', () => { clearTimeout(timeoutId); client.state = ConnectionState.CONNECTED; this.stateManager.updateClientState(client.id, ConnectionState.CONNECTED); resolve(client); }); childProcess.on('error', (error: Error) => { clearTimeout(timeoutId); reject(error); }); childProcess.on('exit', (code: number) => { if (code !== 0) { reject(new Error(`Client process exited with code ${code}`)); } }); } catch (error) { clearTimeout(timeoutId); reject(error); } }); }

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/glassBead-tc/SubspaceDomain'

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