mcp-use 2.0.0-beta.28 → 2.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { type ServerEventBus } from "@modelcontextprotocol/server";
2
+ import { Hono, type Env, type MiddlewareHandler } from "hono";
2
3
  import { type ServerBranding } from "./branding.js";
3
4
  import { type ServerConfig } from "./config.js";
4
- import { type FetchHandler, type FrameworkHandler } from "./fetch-app.js";
5
5
  import { type McpEventListenerFnFor, type McpEventPattern, type McpMiddlewareFnFor, type McpMiddlewarePattern } from "./middleware/mcp-middleware.js";
6
- import type { NodeRequestHandler } from "./node-bridge.js";
7
6
  import type { FromOpenAPIOptions } from "./openapi/types.js";
8
7
  import type { InferPromptInput, PromptCallback, PromptDefinition } from "./prompts.js";
9
8
  import type { InferTemplateParams, ResourceCallback, ResourceDefinition, ResourceTemplateCallback, ResourceTemplateDefinition } from "./resources.js";
@@ -11,26 +10,11 @@ import type { ProxyConnection, ProxyServerConfig } from "./mcp-proxy.js";
11
10
  import type { InferToolInput, InferToolName, InferToolOutput, ToolCallback, ToolDefinition, ToolRef } from "./tools.js";
12
11
  import { registerViews, type ViewsManifest } from "./views/index.js";
13
12
  type HasOAuth<TUser> = [TUser] extends [never] ? false : true;
14
- /**
15
- * Optional Node-listener routes registered while the framework mounts its
16
- * production Fetch handler, before requests are accepted.
17
- *
18
- * This lets CLI-owned integrations add narrowly scoped routes while retaining
19
- * `listen()`'s host validation and OAuth resource initialization.
20
- */
13
+ /** Options accepted by {@link MCPServer.listen}. */
21
14
  export interface ListenOptions {
22
- /** Additional routes protected by the server's normal middleware stack. */
23
- routes?: readonly ListenRoute[];
24
15
  /** Explicit bind host; takes precedence over `HOST` and configured `host`. */
25
16
  host?: string;
26
17
  }
27
- /** An additional route owned by a caller of {@link MCPServer.listen}. */
28
- export interface ListenRoute {
29
- /** Whether this route handles a request. */
30
- match: (request: Request) => boolean;
31
- /** Handler invoked when {@link match} returns `true`. */
32
- handler: FetchHandler;
33
- }
34
18
  /**
35
19
  * MCP server with declarative tool/resource/prompt registration, served
36
20
  * statelessly over a composed fetch handler.
@@ -52,8 +36,32 @@ export interface ListenRoute {
52
36
  * await server.listen(3000);
53
37
  * ```
54
38
  */
55
- export declare class MCPServer<TUser = never> {
39
+ export declare class MCPServer<TUser = never, TEnv extends Env = Env> {
56
40
  #private;
41
+ /** Hono application that owns HTTP middleware and routes. */
42
+ readonly app: Hono<TEnv>;
43
+ /** Register a typed `GET` route on {@link MCPServer.app}. */
44
+ readonly get: Hono<TEnv>["get"];
45
+ /** Register a typed `POST` route on {@link MCPServer.app}. */
46
+ readonly post: Hono<TEnv>["post"];
47
+ /** Register a typed `PUT` route on {@link MCPServer.app}. */
48
+ readonly put: Hono<TEnv>["put"];
49
+ /** Register a typed `PATCH` route on {@link MCPServer.app}. */
50
+ readonly patch: Hono<TEnv>["patch"];
51
+ /** Register a typed `DELETE` route on {@link MCPServer.app}. */
52
+ readonly delete: Hono<TEnv>["delete"];
53
+ /** Register a typed route for every HTTP method on {@link MCPServer.app}. */
54
+ readonly all: Hono<TEnv>["all"];
55
+ /**
56
+ * Canonical Web-standard handler for edge runtimes and framework mounting.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * export default server;
61
+ * // or: export const POST = server.fetch;
62
+ * ```
63
+ */
64
+ readonly fetch: (...args: Parameters<Hono<TEnv>["fetch"]>) => Promise<Response>;
57
65
  /**
58
66
  * Create an MCP server from a parsed, bundled OpenAPI document.
59
67
  *
@@ -81,7 +89,7 @@ export declare class MCPServer<TUser = never> {
81
89
  * is both the MCP route and the path of the OAuth protected-resource
82
90
  * identity, so any explicit OAuth resource URL must use that exact path.
83
91
  * Nothing binds or listens until {@link MCPServer.listen} or
84
- * {@link MCPServer.getHandler} is called.
92
+ * the first request reaches {@link MCPServer.fetch}.
85
93
  */
86
94
  constructor(config: ServerConfig<TUser>);
87
95
  /**
@@ -112,15 +120,21 @@ export declare class MCPServer<TUser = never> {
112
120
  * ```
113
121
  */
114
122
  get branding(): ServerBranding;
123
+ /** @deprecated Use {@link MCPServer.fetch} directly. */
124
+ getHandler(): typeof this.fetch;
115
125
  /**
116
126
  * Register a tool. Input is validated against `inputSchema` before the callback
117
127
  * runs; results carrying `structuredContent` are type-checked against
118
128
  * `outputSchema` at the callback's return position.
119
129
  *
130
+ * Assign static registrations to exported constants so `mcp-env.d.ts` can
131
+ * expose their {@link ToolRef} types to views:
132
+ * `export const search = server.tool(...)`.
133
+ *
120
134
  * @returns A {@link ToolRef} carrying the tool name and phantom types for
121
135
  * inference-based view typing.
122
136
  */
123
- tool<const T extends ToolDefinition>(definition: T, callback: ToolCallback<InferToolInput<T>, InferToolOutput<T>, TUser, HasOAuth<TUser>>): ToolRef<InferToolName<T>, InferToolInput<T>, InferToolOutput<T>>;
137
+ tool<const T extends ToolDefinition>(definition: T, callback: ToolCallback<InferToolInput<T>, InferToolOutput<T>, TUser, HasOAuth<TUser>, TEnv>): ToolRef<InferToolName<T>, InferToolInput<T>, InferToolOutput<T>>;
124
138
  /**
125
139
  * Prime the views registry from build/dev registry data.
126
140
  *
@@ -154,7 +168,7 @@ export declare class MCPServer<TUser = never> {
154
168
  projectRoot?: string;
155
169
  }): void;
156
170
  /** Register a static resource readable at `definition.uri`. */
157
- resource(definition: ResourceDefinition, callback: ResourceCallback<TUser, HasOAuth<TUser>>): this;
171
+ resource(definition: ResourceDefinition, callback: ResourceCallback<TUser, HasOAuth<TUser>, TEnv>): this;
158
172
  /**
159
173
  * Register a parameterized resource. Reads matching `uriTemplate` invoke
160
174
  * the callback with the extracted variables.
@@ -166,12 +180,12 @@ export declare class MCPServer<TUser = never> {
166
180
  */
167
181
  resourceTemplate<const TUriTemplate extends string>(definition: ResourceTemplateDefinition<TUriTemplate>, callback: ResourceTemplateCallback<InferTemplateParams<{
168
182
  uriTemplate: TUriTemplate;
169
- }>, TUser, HasOAuth<TUser>>): this;
183
+ }>, TUser, HasOAuth<TUser>, TEnv>): this;
170
184
  /**
171
185
  * Register a prompt template. Schema fields wrapped with `completable()`
172
186
  * gain autocomplete via `completion/complete`.
173
187
  */
174
- prompt<T extends PromptDefinition>(definition: T, callback: PromptCallback<InferPromptInput<T>, TUser, HasOAuth<TUser>>): this;
188
+ prompt<T extends PromptDefinition>(definition: T, callback: PromptCallback<InferPromptInput<T>, TUser, HasOAuth<TUser>, TEnv>): this;
175
189
  /**
176
190
  * Compose upstream MCP servers into this server.
177
191
  *
@@ -217,61 +231,32 @@ export declare class MCPServer<TUser = never> {
217
231
  */
218
232
  proxy(connection: ProxyConnection): Promise<void>;
219
233
  /**
220
- * Web-standard request handler for the whole app (MCP endpoint included) —
221
- * usable directly on serverless/edge runtimes or in tests.
222
- *
223
- * The handler never binds a socket, so no Host/Origin validation applies
224
- * by default: DNS rebinding targets locally bound servers, and platform
225
- * edges (Vercel, Cloudflare, …) only route hostnames assigned to the
226
- * deployment. Set `allowedHosts`/`allowedOrigins` to opt into validation
227
- * (additive — localhost-class values stay allowed).
234
+ * Register HTTP middleware or typed MCP operation middleware.
228
235
  *
229
- * Pass the same `bus` to multiple server instances when their handlers
230
- * replace one another while existing `subscriptions/listen` streams remain
231
- * open. The bus is fixed when this instance first mounts.
236
+ * MCP patterns always use an `mcp:` prefix (for example
237
+ * `mcp:tools/call`, `mcp:*`). Every other overload is Hono middleware and
238
+ * may target all routes or a path pattern.
232
239
  *
233
- * @param options - Optional handler wiring.
234
- *
235
- * @example
236
- * ```ts
237
- * const handler = server.getHandler();
238
- * export default { fetch: handler };
239
- * ```
240
- */
241
- getHandler(options?: {
242
- bus?: ServerEventBus;
243
- }): FrameworkHandler;
244
- /**
245
- * Node `(req, res) => void` handler for composing with an existing
246
- * `http.Server`. Uses the same internal `toNodeHandler` bridge as
247
- * {@link MCPServer.listen}; MCPServer users do not need to import
248
- * `mcp-use/node`.
249
- *
250
- * @example
251
- * ```ts
252
- * import { createServer } from "node:http";
253
- * const httpServer = createServer(await server.getNodeHandler());
254
- * httpServer.listen(3000);
255
- * ```
256
- */
257
- getNodeHandler(): Promise<NodeRequestHandler>;
258
- /**
259
- * Register MCP operation middleware that intercepts JSON-RPC dispatch.
260
- *
261
- * Patterns use an `mcp:` prefix (for example `mcp:tools/call`, `mcp:*`).
262
240
  * Exact methods may transform their typed result. The global `mcp:*` pattern
263
241
  * is pass-through middleware. Middleware runs in registration order; call
264
242
  * `next()` to continue the chain.
265
243
  *
266
244
  * @example
267
245
  * ```ts
246
+ * server.use("/api/*", async (c, next) => {
247
+ * c.set("requestId", crypto.randomUUID());
248
+ * await next();
249
+ * });
250
+ *
268
251
  * server.use("mcp:tools/call", async (ctx, next) => {
269
252
  * console.log(`Calling tool: ${ctx.params.name}`);
270
253
  * return next();
271
254
  * });
272
255
  * ```
273
256
  */
274
- use<P extends McpMiddlewarePattern>(pattern: P, handler: McpMiddlewareFnFor<P>): this;
257
+ use<P extends McpMiddlewarePattern>(pattern: P, handler: McpMiddlewareFnFor<P, TEnv>): this;
258
+ use(handler: MiddlewareHandler<TEnv>): this;
259
+ use(path: `/${string}` | "*", ...handlers: MiddlewareHandler<TEnv>[]): this;
275
260
  /**
276
261
  * Register a read-only MCP observer. Unlike {@link MCPServer.use}, listeners
277
262
  * cannot block, override, or mutate params. Throwing is logged and does not
@@ -287,7 +272,16 @@ export declare class MCPServer<TUser = never> {
287
272
  * });
288
273
  * ```
289
274
  */
290
- on<P extends McpEventPattern>(pattern: P, handler: McpEventListenerFnFor<P>): this;
275
+ on<P extends McpEventPattern>(pattern: P, handler: McpEventListenerFnFor<P, TEnv>): this;
276
+ /**
277
+ * Attach the shared development event bus before the first request.
278
+ *
279
+ * @param bus - Bus retained across hot-reloaded server instances.
280
+ * @internal
281
+ */
282
+ __setEventBus(bus: ServerEventBus): void;
283
+ /** Mount and validate the Hono/MCP application without serving a request. @internal */
284
+ __mount(): void;
291
285
  /**
292
286
  * Publish a tools-list change to v2 clients with active subscriptions.
293
287
  *
@@ -343,7 +337,7 @@ export declare class MCPServer<TUser = never> {
343
337
  * requests accepted before then are queued. Public/wildcard listeners must
344
338
  * configure the resource before calling this method.
345
339
  *
346
- * @throws If called on a localhost-class bind after {@link MCPServer.getHandler}
340
+ * @throws If called on a localhost-class bind after {@link MCPServer.fetch}
347
341
  * already mounted the app without Host validation.
348
342
  */
349
343
  listen(port?: number | undefined, options?: ListenOptions): Promise<{
@@ -354,7 +348,7 @@ export declare class MCPServer<TUser = never> {
354
348
  * Abort in-flight MCP exchanges and stop the HTTP listener.
355
349
  *
356
350
  * A closed server is done for good — the underlying MCP handler stays
357
- * closed, so `listen()`/`getHandler()` cannot revive it. Create a new
351
+ * closed, so `listen()`/`fetch()` cannot revive it. Create a new
358
352
  * instance to serve again.
359
353
  */
360
354
  close(): Promise<void>;
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CallToolResult, InputRequiredResult, MetaObject, StandardSchemaWithJSON, ToolAnnotations } from "@modelcontextprotocol/server";
2
+ import type { Env } from "hono";
2
3
  import type { McpUiResourceCsp } from "@modelcontextprotocol/ext-apps";
3
4
  import type { RequestContext } from "./context.js";
4
5
  import type { UiPermissions } from "./views/types.js";
@@ -116,9 +117,9 @@ export interface ToolRef<Name extends string = string, Input = Record<string, un
116
117
  }
117
118
  /**
118
119
  * Result a tool callback may return, keyed by the tool's inferred output
119
- * type. Completed calls use the SDK's raw {@link CallToolResult}; interactive
120
- * calls may return an {@link InputRequiredResult}. There is no
121
- * framework-specific result layer.
120
+ * type. Prefer the SDK's raw {@link CallToolResult}; interactive calls may
121
+ * return an {@link InputRequiredResult}. Deprecated response helpers
122
+ * (`text`, `object`, …) return the same envelope and remain accepted.
122
123
  *
123
124
  * Without an `outputSchema` (`TOutput = never`) any `CallToolResult` is
124
125
  * accepted. With one, the result must carry `structuredContent` matching the
@@ -173,4 +174,4 @@ export type InferToolName<T> = T extends {
173
174
  * an `outputSchema` must return matching `structuredContent` or an `isError`
174
175
  * result; tools without one accept any {@link CallToolResult}.
175
176
  */
176
- export type ToolCallback<TInput = Record<string, unknown>, TOutput = never, TUser = never, HasOAuth extends boolean = false> = (params: TInput, ctx: RequestContext<TUser, HasOAuth>) => ToolResult<TOutput> | Promise<ToolResult<TOutput>>;
177
+ export type ToolCallback<TInput = Record<string, unknown>, TOutput = never, TUser = never, HasOAuth extends boolean = false, TEnv extends Env = Env> = (params: TInput, ctx: RequestContext<TUser, HasOAuth, TEnv>) => ToolResult<TOutput> | Promise<ToolResult<TOutput>>;
@@ -23,7 +23,7 @@ export declare function createViewAssetsHandler(basePath: string, views: Readonl
23
23
  * cross-origin sandboxed view iframes.
24
24
  *
25
25
  * Node filesystem modules load only on the first public-asset request so the
26
- * library entry stays edge-safe for `getHandler()`-only deployments.
26
+ * library entry stays edge-safe for `server.fetch` deployments.
27
27
  *
28
28
  * @param basePath - MCP mount prefix (e.g. `/mcp`).
29
29
  * @param views - Primed view registry; empty skips mounting.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-use",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.28",
4
+ "version": "2.0.0-beta.30",
5
5
  "description": "MCP framework and CLI built on the official v2 SDK",
6
6
  "author": "mcp-use, Inc.",
7
7
  "license": "MIT",
@@ -87,9 +87,10 @@
87
87
  "@modelcontextprotocol/core": "https://pkg.pr.new/@modelcontextprotocol/core@f60b40179b0f090f6d64248be1312245a160b5ee",
88
88
  "@modelcontextprotocol/ext-apps": "https://pkg.pr.new/@modelcontextprotocol/ext-apps@432d42bb02a569078ab31ab6458428df6027809d",
89
89
  "@modelcontextprotocol/server": "https://pkg.pr.new/@modelcontextprotocol/server@f60b40179b0f090f6d64248be1312245a160b5ee",
90
+ "hono": "^4.12.27",
90
91
  "jose": "^6.1.3",
91
- "@mcp-use/cli": "4.0.0-beta.4",
92
- "@mcp-use/inspector": "20.0.0-beta.20"
92
+ "@mcp-use/cli": "4.0.0-beta.6",
93
+ "@mcp-use/inspector": "20.0.0-beta.22"
93
94
  },
94
95
  "peerDependencies": {
95
96
  "@mcp-use/client": "^2.0.0-alpha.0",
@@ -123,7 +124,7 @@
123
124
  "vitest": "^4.1.9",
124
125
  "zod": "^4.4.3",
125
126
  "@mcp-use/client": "2.0.0-beta.11",
126
- "mcp-use": "2.0.0-beta.28"
127
+ "mcp-use": "2.0.0-beta.30"
127
128
  },
128
129
  "publishConfig": {
129
130
  "access": "public"