UNPKG

@jeanmemory/node

Version:

Node.js SDK for Jean Memory - Power your Next.js and other Node.js backends with a perfect memory

41 lines 1.5 kB
"use strict"; /** * Jean Memory Node.js SDK - MCP Utility * Model Context Protocol request handling */ Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMCPRequest = makeMCPRequest; let requestId = 0; async function makeMCPRequest(userToken, apiKey, toolName, arguments_, apiBase = 'https://jean-memory-api-virginia.onrender.com', clientName = 'node-sdk') { const id = ++requestId; const mcpRequest = { jsonrpc: '2.0', id, method: 'tools/call', params: { name: toolName, arguments: arguments_ } }; // Extract user_id from token (handles both test_user_ and user_ prefixes) if (!userToken) { throw new Error('User token is required for MCP requests'); } const userId = userToken.replace('test_user_', '').replace('user_', ''); const response = await fetch(`${apiBase}/mcp/${clientName}/messages/${userId}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${userToken}`, // 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(); } //# sourceMappingURL=mcp.js.map