@modelfetch/core
Version:
Core utilities for MCP servers built with ModelFetch
72 lines • 1.92 kB
TypeScript
/**
* This module provides the foundational components for creating MCP servers that can be deployed
* across various JavaScript/TypeScript runtimes.
*
* @example Basic Example
* ```ts
* import { createApp } from "@modelfetch/core";
* import server from "./server";
*
* const app = createApp(server);
* ```
*
* @example Advanced Example
* ```ts
* import { createApp } from "@modelfetch/core";
* import server from "./server";
*
* const app = createApp({
* server,
* base: "/api",
* path: "/mcp",
* middleware: [authMiddleware, loggingMiddleware],
* pre: (app) => {
* app.get("/health", (c) => c.text("OK"));
* },
* post: (app) => {
* app.notFound((c) => c.text("Not found", 404));
* }
* });
* ```
*
* @module
*/
import type { MiddlewareHandler } from "hono";
import { StreamableHTTPTransport } from "@hono/mcp";
import { Hono } from "hono";
/**
* MCP server application.
*/
export type App = Hono;
/**
* MCP server implementation.
*/
export interface Server {
connect: (transport: StreamableHTTPTransport) => Promise<void>;
}
/**
* MCP server configuration.
*/
export interface Config {
/** MCP server implementation. */
server: Server;
/** Base path for all routes. */
base?: string;
/** Custom path for the MCP endpoint (defaults to "/mcp"). */
path?: string;
/** Middleware to apply to the MCP endpoint. */
middleware?: MiddlewareHandler[];
/** Hook to configure routes before the MCP endpoint. */
pre?: (app: Hono) => void;
/** Hook to configure routes after the MCP endpoint. */
post?: (app: Hono) => void;
}
/**
* MCP server implementation or configuration.
*/
export type ServerOrConfig = Server | Config;
/**
* Creates an MCP server application from an MCP server implementation or configuration.
*/
export declare function createApp(arg: ServerOrConfig): App;
//# sourceMappingURL=index.d.ts.map