UNPKG

@jeanmemory/react

Version:

React SDK for Jean Memory - Build personalized AI chatbots in 5 lines of code

37 lines (36 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMCPRequest = makeMCPRequest; /** * Jean Memory React SDK - MCP Utility * Shared logic for making MCP requests */ const config_1 = require("./config"); let requestId = 0; async function makeMCPRequest(user, apiKey, toolName, arguments_, clientName = 'react-sdk') { const id = ++requestId; const mcpRequest = { jsonrpc: '2.0', id, method: 'tools/call', params: { name: toolName, arguments: arguments_ } }; const response = await fetch(`${config_1.JEAN_API_BASE}/mcp/${clientName}/messages/${user.user_id}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-User-Id': user.user_id, 'X-Client-Name': clientName, 'X-API-Key': apiKey }, body: JSON.stringify(mcpRequest) }); if (!response.ok) { const errorBody = await response.text(); throw new Error(`MCP request failed: ${response.statusText} - ${errorBody}`); } return response.json(); }