UNPKG

tryaii-mcp-server

Version:

MCP Server for TryAII - Lightweight proxy to TryAII API service

57 lines (56 loc) 2.1 kB
class TryAIIApiClient { baseUrl; apiKey; constructor(config) { this.baseUrl = config.baseUrl; this.apiKey = config.apiKey; } async makeRequest(endpoint, method = 'POST', body) { const url = `${this.baseUrl}${endpoint}`; const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` }; const requestOptions = { method, headers, }; if (body && method === 'POST') { requestOptions.body = JSON.stringify(body); } try { const response = await fetch(url, requestOptions); if (!response.ok) { const errorText = await response.text(); throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorText}`); } const data = await response.json(); return data; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to communicate with TryAII service: ${error.message}`); } throw new Error('Unknown error occurred while communicating with TryAII service'); } } async chatWithModel(params) { return this.makeRequest('/api/chat', 'POST', params); } async compareModels(params) { return this.makeRequest('/api/compare', 'POST', params); } async brains(params) { params.temperature = Math.max(0.5, (params.temperature || 0.7)); params.maxTokens = params.maxTokens ? params.maxTokens < 2000 ? 2000 : params.maxTokens : 2000; return this.makeRequest('/api/brains', 'POST', params); } async getModelInfo(params) { return this.makeRequest('/api/model-info', 'POST', params); } async getAvailableModels(provider) { const endpoint = provider ? `/api/available-models?provider=${encodeURIComponent(provider)}` : '/api/available-models'; return this.makeRequest(endpoint, 'GET'); } } export { TryAIIApiClient };