UNPKG

@jeanmemory/react

Version:

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

40 lines (39 loc) 1.36 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_ } }; // Extract user_id from JWT token for URL path const payload = JSON.parse(atob(user.access_token.split('.')[1])); const userId = payload.sub; const response = await fetch(`${config_1.JEAN_API_BASE}/mcp/${clientName}/messages/${userId}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${user.access_token}`, // Use user's JWT token 'X-Client-Name': clientName, 'X-API-Key': apiKey // API key for app identification }, body: JSON.stringify(mcpRequest) }); if (!response.ok) { const errorBody = await response.text(); throw new Error(`MCP request failed: ${response.statusText} - ${errorBody}`); } return response.json(); }