createAIBridge
Establish OpenAI-compatible API communication with another AI agent by configuring unique identifiers, endpoints, models, and API keys for efficient interaction.
Instructions
Create a bridge to communicate with another AI agent via OpenAI-compatible API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | API key if required | |
| bridgeId | Yes | Unique identifier for this bridge | |
| endpoint | No | API endpoint URL (required for custom provider) | |
| endpointName | Yes | Name of configured endpoint or custom URL | |
| model | No | Model to use |
Input Schema (JSON Schema)
{
"properties": {
"apiKey": {
"description": "API key if required",
"type": "string"
},
"bridgeId": {
"description": "Unique identifier for this bridge",
"type": "string"
},
"endpoint": {
"description": "API endpoint URL (required for custom provider)",
"type": "string"
},
"endpointName": {
"description": "Name of configured endpoint or custom URL",
"type": "string"
},
"model": {
"description": "Model to use",
"type": "string"
}
},
"required": [
"bridgeId",
"endpointName"
],
"type": "object"
}
Implementation Reference
- MCP tool handler for 'createAIBridge'. Parses args, checks for existing bridge, creates AIBridge using factory function, stores in map, returns success status.createAIBridge: async (args: any) => { try { const { bridgeId, endpointName, model, apiKey } = args; if (bridges.has(bridgeId)) { return { success: false, error: `Bridge ${bridgeId} already exists`, }; } const config: Partial<AIBridgeConfig> = { ...(model && { model }), ...(apiKey && { apiKey }), }; const bridge = createAIBridge(endpointName, config); bridges.set(bridgeId, bridge); logger.info(`Created AI bridge: ${bridgeId} (${endpointName}/${model || 'default'})`); return { success: true, bridgeId, endpointName, model: model || 'default', message: `AI bridge ${bridgeId} created successfully`, }; } catch (error) { logger.error('Failed to create AI bridge:', error); return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } },
- Input schema definition for the 'createAIBridge' MCP tool, specifying parameters like bridgeId, endpointName, etc.name: 'createAIBridge', description: 'Create a bridge to communicate with another AI agent via OpenAI-compatible API', inputSchema: { type: 'object', properties: { bridgeId: { type: 'string', description: 'Unique identifier for this bridge', }, endpointName: { type: 'string', description: 'Name of configured endpoint or custom URL', }, endpoint: { type: 'string', description: 'API endpoint URL (required for custom provider)', }, model: { type: 'string', description: 'Model to use', }, apiKey: { type: 'string', description: 'API key if required', }, }, required: ['bridgeId', 'endpointName'], }, },
- src/consciousness-rag-server-clean.ts:98-119 (registration)Server request handler dispatch for 'createAIBridge' and other AI bridge tools, calling the corresponding aiBridgeHandlers function.// AI Bridge tools case 'createAIBridge': case 'transferToAgent': case 'testAIConnection': case 'listAIBridges': case 'listConfiguredEndpoints': case 'closeAIBridge': { const handler = aiBridgeHandlers[name as keyof typeof aiBridgeHandlers]; if (!handler) { throw new Error(`AI Bridge handler not found: ${name}`); } const result = await handler(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/consciousness-rag-server-clean.ts:61-68 (registration)Tool listing handler that includes aiBridgeTools (containing createAIBridge) in the list of available tools.const consciousnessTools = Object.entries(consciousnessProtocolTools).map(([name, tool]) => ({ name, ...tool, })); return { tools: [...consciousnessTools, ...aiBridgeTools], };
- src/ai-bridge.ts:151-170 (helper)Factory function to create AIBridge instances from endpoint names or URLs, used by the MCP tool handler.export function createAIBridge(endpointName: string, config?: Partial<AIBridgeConfig>): AIBridge { const endpointConfig = AIBridgeConfigManager.getEndpoint(endpointName); if (!endpointConfig) { // If not a configured endpoint, treat as custom endpoint URL return new AIBridge({ endpoint: endpointName, model: config?.model || 'default', ...config, } as AIBridgeConfig); } // Use configured endpoint return new AIBridge({ endpoint: endpointConfig.endpoint, model: config?.model || endpointConfig.defaultModel || 'default', apiKey: config?.apiKey || endpointConfig.apiKey, ...config, } as AIBridgeConfig); }