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.
70 lines (69 loc) • 3.07 kB
TypeScript
import type { Env, MiddlewareHandler, ValidationTargets } from "hono/types";
import { Tool, type ToolConfig } from "../tool";
import { type ResourceConfig, type TResourceUri } from "../resource";
import type { Hono } from "hono";
import { type RouteInfo } from "jsonv-ts/hono";
import { Schema, type ObjectSchema } from "jsonv-ts";
import { McpServer } from "../server";
import { type McpOptionsBase } from "./mcp.middleware";
declare const $symbol: unique symbol;
export type McpFeatureTool = {
type: "tool";
tool: {
name: string;
config: Omit<ToolConfig, "inputSchema"> & {
inputSchema?: Partial<Record<keyof ValidationTargets, ObjectSchema>>;
noErrorCodes?: number[];
};
};
};
export type McpFeatureResource = {
type: "resource";
resource: {
name: string;
uri: TResourceUri;
config: ResourceConfig;
};
};
export type McpFeature = McpFeatureTool | McpFeatureResource;
export type McpFeatureWithRouteInfo<T extends McpFeature = McpFeature> = T & {
info: RouteInfo<{
useSchemas: true;
}>;
path: string;
};
export declare const mcpTool: <E extends Env, P extends string>(name: string, config?: McpFeatureTool["tool"]["config"]) => MiddlewareHandler<E, P> & {
[$symbol]: {
type: string;
tool: {
name: string;
config: Omit<ToolConfig, "inputSchema"> & {
inputSchema?: Partial<Record<keyof ValidationTargets, ObjectSchema>>;
noErrorCodes?: number[];
};
};
};
};
export declare const mcpResource: <E extends Env, P extends string>(name: string, uri: TResourceUri, config?: ResourceConfig) => MiddlewareHandler<E, P> & {
[$symbol]: {
type: string;
resource: {
name: string;
uri: `${string}://${string}`;
config: ResourceConfig;
};
};
};
export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
export declare function infoValidationTargetsToSchema(validation?: Partial<Record<keyof ValidationTargets, ObjectSchema>>, opts?: {
noSpecialTargetKeys?: boolean;
}): ObjectSchema<import("jsonv-ts").TProperties, import("jsonv-ts").IObjectOptions> | undefined;
export declare function payloadToValidationTargetPayload(payload: object, schema: Schema): Partial<Record<keyof ValidationTargets, Record<string, any>>>;
export declare function featureInfoToRequest(feature: McpFeatureWithRouteInfo, params: any, opts?: {
headers?: Record<string, string | undefined>;
inputSchema?: ObjectSchema;
}): Request;
export declare function getMcpFeatures(hono: Hono<any>): McpFeatureWithRouteInfo<McpFeature>[];
export declare function getMcpServer(hono: Hono<any>): McpServer<{}, Tool<any, any, any, any>[], import("..").Resource<any, any, any, any>[]>;
export declare function withMcp<H extends Hono<any>>(hono: H, opts?: Omit<McpOptionsBase, "server">): import("hono/hono-base").HonoBase<{}, import("hono/types").BlankSchema, "/">;
export {};