UNPKG

mcp-use

Version:

Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.

63 lines (59 loc) 1.51 kB
import { __name } from "./chunk-3GQAWCBQ.js"; // src/server/utils/jsonrpc-helpers.ts function createNotification(method, params) { return { jsonrpc: "2.0", method, ...params && { params } }; } __name(createNotification, "createNotification"); function createRequest(id, method, params) { return { jsonrpc: "2.0", id, method, ...params && { params } }; } __name(createRequest, "createRequest"); // src/server/sessions/notifications.ts async function sendNotificationToAll(sessions, method, params) { const notification = createNotification(method, params); for (const [sessionId, session] of sessions.entries()) { try { await session.transport.send(notification); } catch (error) { console.warn( `[MCP] Failed to send notification to session ${sessionId}:`, error ); } } } __name(sendNotificationToAll, "sendNotificationToAll"); async function sendNotificationToSession(sessions, sessionId, method, params) { const session = sessions.get(sessionId); if (!session) { return false; } const notification = createNotification(method, params); try { await session.transport.send(notification); return true; } catch (error) { console.warn( `[MCP] Failed to send notification to session ${sessionId}:`, error ); return false; } } __name(sendNotificationToSession, "sendNotificationToSession"); export { createRequest, sendNotificationToAll, sendNotificationToSession };