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.
61 lines (60 loc) • 2.87 kB
TypeScript
import * as s from "jsonv-ts";
import type { MaybePromise } from "./utils";
declare const annotationSchema: s.ObjectSchema<{
readonly title: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly readOnlyHint: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly destructiveHint: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly idempotentHint: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly openWorldHint: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
export type ToolAnnotation = s.Static<typeof annotationSchema>;
export type ToolConfig = {
title?: string;
description?: string;
inputSchema?: s.ObjectSchema<any, any>;
outputSchema?: s.ObjectSchema<any, any>;
annotations?: ToolAnnotation;
_meta?: {
[key: string]: unknown;
};
};
export type ToolHandler<Config extends ToolConfig | undefined = undefined, Context extends object = {}> = (params: Config extends ToolConfig ? Config["inputSchema"] extends s.Schema ? s.Static<Config["inputSchema"]> : never : never, ctx: ToolHandlerCtx<Context>) => MaybePromise<ToolResponse>;
export type ToolHandlerCtx<Context extends object = object> = {
text: (text: string) => ToolResponseText;
json: (json: object) => ToolResponseText;
context: Context;
raw?: unknown;
};
export type ToolResponseText = {
type: "text";
text: string;
};
export type ToolResponse = ToolResponseText;
export type ToolJson = ReturnType<Tool["toJSON"]>;
export declare class Tool<Name extends string = string, Config extends ToolConfig | undefined = undefined, InputSchema = Config extends ToolConfig ? Config["inputSchema"] : undefined, Params = InputSchema extends s.Schema ? s.Static<InputSchema> : object> {
readonly name: Name;
readonly config: Config;
readonly handler: (params: Params, ctx: ToolHandlerCtx<any>) => MaybePromise<ToolResponse>;
constructor(name: Name, config: Config, handler: (params: Params, ctx: ToolHandlerCtx<any>) => MaybePromise<ToolResponse>);
call(params: Params, context: object, raw?: unknown): Promise<ToolResponse>;
toJSON(): {
name: Name;
title: string | undefined;
description: string | undefined;
inputSchema: s.JSONSchemaDefinition;
outputSchema: s.JSONSchemaDefinition | undefined;
annotations: {
title?: string | undefined;
readOnlyHint?: boolean | undefined;
destructiveHint?: boolean | undefined;
idempotentHint?: boolean | undefined;
openWorldHint?: boolean | undefined;
} | undefined;
_meta: {
[key: string]: unknown;
} | undefined;
};
}
export {};