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.

94 lines 2.85 kB
/** * JSON-RPC Helper Utilities * * Common utilities for creating JSON-RPC notifications, requests, and error responses. */ /** * JSON-RPC notification object structure */ export interface JsonRpcNotification { jsonrpc: "2.0"; method: string; params?: Record<string, unknown>; } /** * JSON-RPC request object structure */ export interface JsonRpcRequest { jsonrpc: "2.0"; id: string | number; method: string; params?: Record<string, unknown>; } /** * JSON-RPC error response object structure */ export interface JsonRpcError { jsonrpc: "2.0"; error: { code: number; message: string; data?: unknown; }; id: string | number | null; } /** * Create a JSON-RPC notification object * * Notifications are one-way messages that don't expect a response. * * @param method - The notification method name * @param params - Optional parameters to include in the notification * @returns JSON-RPC notification object * * @example * ```typescript * const notification = createNotification("notifications/resources/list_changed"); * const notificationWithParams = createNotification("custom/alert", { message: "Hello" }); * ``` */ export declare function createNotification(method: string, params?: Record<string, unknown>): JsonRpcNotification; /** * Create a JSON-RPC request object * * Requests are two-way messages that expect a response. * * @param id - Unique request identifier * @param method - The request method name * @param params - Optional parameters to include in the request * @returns JSON-RPC request object * * @example * ```typescript * const request = createRequest("123", "roots/list", {}); * ``` */ export declare function createRequest(id: string | number, method: string, params?: Record<string, unknown>): JsonRpcRequest; /** * Create a JSON-RPC error response object * * @param code - Error code (e.g., -32000 for application errors) * @param message - Human-readable error message * @param id - Request ID (null if error occurred before ID could be determined) * @param data - Optional additional error data * @returns JSON-RPC error response object * * @example * ```typescript * const error = createJsonRpcError(-32000, "Session not found", "123"); * const errorNoId = createJsonRpcError(-32600, "Invalid Request", null); * ``` */ export declare function createJsonRpcError(code: number, message: string, id?: string | number | null, data?: unknown): JsonRpcError; /** * Common JSON-RPC error codes */ export declare const JsonRpcErrorCode: { readonly PARSE_ERROR: -32700; readonly INVALID_REQUEST: -32600; readonly METHOD_NOT_FOUND: -32601; readonly INVALID_PARAMS: -32602; readonly INTERNAL_ERROR: -32603; readonly APPLICATION_ERROR: -32000; }; //# sourceMappingURL=jsonrpc-helpers.d.ts.map