UNPKG

muppet

Version:

Toolkit for building MCPs on Honojs

118 lines (111 loc) 5.41 kB
import { MiddlewareHandler, Env, BlankEnv, Schema, BlankSchema, BlankInput, Next, TypedResponse } from 'hono/types'; import { P as PromptDescribeOptions, T as ToolDescribeOptions, M as MuppetConfiguration, B as BaseEnv, a as Promisify$1, R as Resource, H as HasUndefined, L as Logger } from './types-BmsEku3v.js'; export { i as ClientToServerNotifications, C as CompletionFn, h as ConceptConfiguration, c as CreateMuppetOptions, D as DescribeOptions, r as McpPrimitives, s as McpPrimitivesValue, q as MuppetEnv, e as PromptConfiguration, o as PromptContentResponseType, p as PromptResponseType, f as ResourceConfiguration, l as ResourceFetcherFn, g as ResourceResponse, S as ServerConfiguration, j as ServerToClientNotifications, k as SubscriptionEvents, m as ToolContentResponseType, b as ToolHandlerResponse, n as ToolResponseType, d as ToolsConfiguration, u as uniqueSymbol } from './types-BmsEku3v.js'; import { Hono, Env as Env$1, Input, Context, Handler, ValidationTargets, MiddlewareHandler as MiddlewareHandler$1, Schema as Schema$1 } from 'hono'; import { StatusCode, ContentfulStatusCode } from 'hono/utils/http-status'; import { JSONValue, SimplifyDeepArray, InvalidJSONValue, JSONParsed } from 'hono/utils/types'; import { Hook } from '@hono/standard-validator'; import { StandardSchemaV1 } from '@standard-schema/spec'; import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import 'events'; import 'http'; import 'worker_threads'; import '@modelcontextprotocol/sdk/types.js'; /** * Describe prompt's name and description */ declare const describePrompt: (docs?: PromptDescribeOptions | undefined) => MiddlewareHandler; /** * Describe tool's name and description */ declare const describeTool: (docs?: ToolDescribeOptions | undefined) => MiddlewareHandler; declare function muppet<E extends Env = BlankEnv, S extends Schema = BlankSchema, P extends string = string>(hono: Hono<E, S, P>, config: MuppetConfiguration): Promise<Hono<BaseEnv<E, S, P>, BlankSchema, "/">>; type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">; declare function registerResources<E extends Env$1 = BlankEnv, P extends string = string, I extends Input = BlankInput>(handler: (c: Context<E, P, I>, next: Next) => Promisify$1<Resource[]>): Handler<E, P, I, JSONRespondReturn<Resource[], ContentfulStatusCode>>; /** * Create a validator middleware. Use this only for muppet tools. * @param target Target for validation * @param schema Standard Schema * @param hook Hook for validation * @returns Middleware handler */ declare function mValidator<Schema extends StandardSchemaV1, Target extends keyof ValidationTargets, E extends Env$1, P extends string, In = StandardSchemaV1.InferInput<Schema>, Out = StandardSchemaV1.InferOutput<Schema>, I extends Input = { in: HasUndefined<In> extends true ? { [K in Target]?: In extends ValidationTargets[K] ? In : { [K2 in keyof In]?: ValidationTargets[K][K2]; }; } : { [K in Target]: In extends ValidationTargets[K] ? In : { [K2 in keyof In]: ValidationTargets[K][K2]; }; }; out: { [K in Target]: Out; }; }, V extends I = I>(target: Target, schema: Schema, hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>): MiddlewareHandler$1<E, P, V>; type Promisify<T> = T | Promise<T>; type BridgeOptions<E extends Env$1 = any, S extends Schema$1 = BlankSchema, P extends string = string> = { /** * The Muppet app instance */ mcp: Promisify<Hono<E, S, P>>; /** * The transport that will be used to send and receive messages */ transport: Transport; /** * The logger that will be used to log messages */ logger?: Logger; }; /** * Bridge aka Bifrost, the connection between the app and the transport * @param options */ declare function bridge(options: BridgeOptions): Promise<void>; type HandleMessageOptions<E extends Env$1 = any, S extends Schema$1 = BlankSchema, P extends string = string> = { /** * The Muppet app instance */ mcp: Hono<E, S, P>; /** * The message received from the MCP Client */ message: unknown; /** * The logger that will be used to log messages */ logger?: Logger; }; /** * Processes the message and generates the response for the MCPs. * @param options */ declare function handleMessage(options: HandleMessageOptions): Promise<{ method: string; jsonrpc: "2.0"; params?: { [x: string]: unknown; _meta?: { [x: string]: unknown; } | undefined; } | undefined; } | { jsonrpc: "2.0"; id: string | number; result: { [x: string]: unknown; _meta?: { [x: string]: unknown; } | undefined; }; } | { jsonrpc: "2.0"; id: string | number; error: { code: number; message: string; data?: unknown; }; } | null>; export { BaseEnv, type BridgeOptions, type HandleMessageOptions, HasUndefined, MuppetConfiguration, Promisify$1 as Promisify, PromptDescribeOptions, Resource, ToolDescribeOptions, bridge, describePrompt, describeTool, handleMessage, mValidator, muppet, registerResources };