UNPKG

jsonv-ts

Version:

JSON Schema builder and validator for TypeScript with static type inference, Hono middleware for OpenAPI generation and validation, and MCP server/client implementation. Lightweight, dependency-free, and built on Web Standards.

103 lines (102 loc) 4.37 kB
import * as s from "jsonv-ts"; import type { McpServer } from "./server"; declare const rpcRequest: s.ObjectSchema<{ readonly method: s.StringSchema<s.IStringOptions> & s.IStringOptions; readonly params: { [x: string]: any; [x: number]: any; } & s.Schema<s.ISchemaOptions, any, any>; readonly jsonrpc: s.StringSchema<{ readonly const: "2.0"; }> & { readonly const: "2.0"; }; readonly id: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; } & s.Schema<s.ISchemaOptions, string | number | undefined, any>; }, s.IObjectOptions> & s.IObjectOptions; declare const rpcResponse: s.ObjectSchema<{ readonly result: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; properties: {}; additionalProperties?: (s.Schema | false) | undefined; patternProperties?: Record<string, s.Schema> | undefined; required: string[] | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; propertyNames?: s.Schema | undefined; $defs?: Record<string, s.Schema> | undefined; strict: () => s.ObjectSchema<{}, s.Merge<s.IObjectOptions & { additionalProperties: false; }>>; partial: () => s.ObjectSchema<{}, s.IObjectOptions>; } & s.Schema<s.ISchemaOptions, { [x: string]: unknown; } | undefined, { [x: string]: unknown; } | undefined>; readonly error: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; properties: {}; additionalProperties?: (s.Schema | false) | undefined; patternProperties?: Record<string, s.Schema> | undefined; required: string[] | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; propertyNames?: s.Schema | undefined; $defs?: Record<string, s.Schema> | undefined; strict: () => s.ObjectSchema<{}, s.Merge<s.IObjectOptions & { additionalProperties: false; }>>; partial: () => s.ObjectSchema<{}, s.IObjectOptions>; } & s.Schema<s.ISchemaOptions, { [x: string]: unknown; } | undefined, { [x: string]: unknown; } | undefined>; readonly jsonrpc: s.StringSchema<{ readonly const: "2.0"; }> & { readonly const: "2.0"; }; readonly id: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; } & s.Schema<s.ISchemaOptions, string | number | undefined, any>; }, s.IObjectOptions> & s.IObjectOptions; export type TRpcRawRequest = s.Static<typeof rpcRequest>; export interface TRpcRequest<S extends s.Schema | unknown = unknown> extends Omit<TRpcRawRequest, "params"> { params: S extends s.Schema ? s.Static<S> : S; } export type TRpcResponse<Result = object> = Omit<s.Static<typeof rpcResponse>, "result"> & { result?: Result; }; export type TRpcMessage = TRpcRawRequest | TRpcResponse; export type TRpcId = string | number; export type TRpcMessageResponse<T extends RpcMessage> = Awaited<ReturnType<T["respond"]>>; export type TRpcMessageResult<T extends RpcMessage> = TRpcMessageResponse<T> extends TRpcResponse<infer R> ? R : never; export type TRpcMessageParams<T extends RpcMessage> = T extends RpcMessage<any, infer P> ? s.Static<P> : never; export declare abstract class RpcMessage<Method extends string = string, Params extends s.Schema = s.Schema> { protected readonly server: McpServer; abstract readonly method: Method; abstract readonly params: Params; constructor(server: McpServer); static isValidMessage(message: unknown): message is TRpcRawRequest; is(message: TRpcRawRequest): boolean; abstract respond(message: TRpcRequest | TRpcRawRequest, raw?: unknown): Promise<TRpcResponse>; protected formatRespond<Result = object>(message: TRpcRequest, result: Result): TRpcResponse<Result>; } export declare abstract class RpcNotification<Method extends string = string> extends RpcMessage<Method> { readonly params: s.Schema<s.IAnyOptions, any, any> & s.IAnyOptions; constructor(server: McpServer); abstract handle(message: TRpcRequest): Promise<void>; respond(message: TRpcRequest): Promise<any>; } export {};