UNPKG

@mondaydotcomorg/atp-mcp-adapter

Version:

MCP compatibility adapter for Agent Tool Protocol

86 lines 2.55 kB
export class MCPHttpConnector { baseUrl; headers; constructor(baseUrl, headers = {}) { this.baseUrl = baseUrl.replace(/\/$/, ''); this.headers = { 'Content-Type': 'application/json', ...headers, }; } async makeRequest(method, params) { const body = { jsonrpc: '2.0', id: Date.now(), method, }; if (params) { body.params = params; } const response = await fetch(this.baseUrl, { method: 'POST', headers: this.headers, body: JSON.stringify(body), }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = (await response.json()); if (data.error) { throw new Error(`MCP Error: ${data.error.message || JSON.stringify(data.error)}`); } return data.result; } async listTools() { const result = (await this.makeRequest('tools/list')); return result.tools || []; } async listPrompts() { try { const result = (await this.makeRequest('prompts/list')); return result.prompts || []; } catch (error) { return []; } } async getPrompt(name, args) { const result = (await this.makeRequest('prompts/get', { name, arguments: args, })); return { messages: result.messages.map((msg) => ({ role: msg.role, content: typeof msg.content === 'string' ? msg.content : msg.content.text, })), }; } async callTool(name, input) { const result = (await this.makeRequest('tools/call', { name, arguments: input, })); if (!result.content || result.content.length === 0) { return null; } const firstBlock = result.content[0]; if (result.content.length === 1 && firstBlock && firstBlock.type === 'text') { const text = firstBlock.text || ''; try { return JSON.parse(text); } catch { return text; } } return result.content.map((block) => { if (block.type === 'text') { return block.text; } return block; }); } async disconnect() { } } //# sourceMappingURL=http-connector.js.map