@casys/mcp-server 0.26.0 → 0.27.0
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/CHANGELOG.md +1779 -0
- package/LICENSE +21 -0
- package/README.md +19 -5
- package/esm/_dnt.polyfills.d.ts +12 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +48 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +106 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +636 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +67 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +1393 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +44 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +117 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +103 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +96 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +159 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +22 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +29 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +19 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +30 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +9 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +81 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +20 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +6 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +4 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +13 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +51 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +53 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +79 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +91 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +100 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +111 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +104 -0
- package/esm/mod.d.ts +102 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +103 -0
- package/esm/package.json +3 -0
- package/esm/src/auth/as-metadata-proxy.d.ts +112 -0
- package/esm/src/auth/as-metadata-proxy.d.ts.map +1 -0
- package/esm/src/auth/as-metadata-proxy.js +171 -0
- package/esm/src/auth/config.d.ts +117 -0
- package/esm/src/auth/config.d.ts.map +1 -0
- package/esm/src/auth/config.js +219 -0
- package/esm/src/auth/jwt-provider.d.ts +157 -0
- package/esm/src/auth/jwt-provider.d.ts.map +1 -0
- package/esm/src/auth/jwt-provider.js +187 -0
- package/esm/src/auth/middleware.d.ts +61 -0
- package/esm/src/auth/middleware.d.ts.map +1 -0
- package/esm/src/auth/middleware.js +209 -0
- package/esm/src/auth/mod.d.ts +23 -0
- package/esm/src/auth/mod.d.ts.map +1 -0
- package/esm/src/auth/mod.js +27 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts +131 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts.map +1 -0
- package/esm/src/auth/multi-tenant-middleware.js +128 -0
- package/esm/src/auth/presets.d.ts +231 -0
- package/esm/src/auth/presets.d.ts.map +1 -0
- package/esm/src/auth/presets.js +223 -0
- package/{src/auth/provider.ts → esm/src/auth/provider.d.ts} +13 -15
- package/esm/src/auth/provider.d.ts.map +1 -0
- package/esm/src/auth/provider.js +34 -0
- package/esm/src/auth/scope-middleware.d.ts +30 -0
- package/esm/src/auth/scope-middleware.d.ts.map +1 -0
- package/esm/src/auth/scope-middleware.js +48 -0
- package/esm/src/auth/static-token-provider.d.ts +155 -0
- package/esm/src/auth/static-token-provider.d.ts.map +1 -0
- package/esm/src/auth/static-token-provider.js +256 -0
- package/esm/src/auth/types.d.ts +151 -0
- package/esm/src/auth/types.d.ts.map +1 -0
- package/esm/src/auth/types.js +64 -0
- package/esm/src/client-auth/callback-server.d.ts +34 -0
- package/esm/src/client-auth/callback-server.d.ts.map +1 -0
- package/esm/src/client-auth/callback-server.js +141 -0
- package/esm/src/client-auth/client-id-metadata.d.ts +29 -0
- package/esm/src/client-auth/client-id-metadata.d.ts.map +1 -0
- package/esm/src/client-auth/client-id-metadata.js +149 -0
- package/esm/src/client-auth/connect.d.ts +32 -0
- package/esm/src/client-auth/connect.d.ts.map +1 -0
- package/esm/src/client-auth/connect.js +47 -0
- package/esm/src/client-auth/mod.d.ts +19 -0
- package/esm/src/client-auth/mod.d.ts.map +1 -0
- package/{src/client-auth/mod.ts → esm/src/client-auth/mod.js} +1 -26
- package/esm/src/client-auth/provider.d.ts +78 -0
- package/esm/src/client-auth/provider.d.ts.map +1 -0
- package/esm/src/client-auth/provider.js +246 -0
- package/esm/src/client-auth/token-store/file-store.d.ts +20 -0
- package/esm/src/client-auth/token-store/file-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/file-store.js +62 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts +14 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/memory-store.js +25 -0
- package/esm/src/client-auth/types.d.ts +89 -0
- package/esm/src/client-auth/types.d.ts.map +1 -0
- package/esm/src/client-auth/types.js +10 -0
- package/esm/src/concurrency/rate-limiter.d.ts +87 -0
- package/esm/src/concurrency/rate-limiter.d.ts.map +1 -0
- package/esm/src/concurrency/rate-limiter.js +165 -0
- package/esm/src/concurrency/request-queue.d.ts +71 -0
- package/esm/src/concurrency/request-queue.d.ts.map +1 -0
- package/esm/src/concurrency/request-queue.js +128 -0
- package/esm/src/http/body.d.ts +20 -0
- package/esm/src/http/body.d.ts.map +1 -0
- package/esm/src/http/body.js +63 -0
- package/esm/src/http/request-guards.d.ts +54 -0
- package/esm/src/http/request-guards.d.ts.map +1 -0
- package/esm/src/http/request-guards.js +114 -0
- package/esm/src/http/wire.d.ts +26 -0
- package/esm/src/http/wire.d.ts.map +1 -0
- package/{src/http/wire.ts → esm/src/http/wire.js} +13 -19
- package/esm/src/inspector/launcher.d.ts +48 -0
- package/esm/src/inspector/launcher.d.ts.map +1 -0
- package/esm/src/inspector/launcher.js +100 -0
- package/esm/src/mcp-app.d.ts +728 -0
- package/esm/src/mcp-app.d.ts.map +1 -0
- package/esm/src/mcp-app.js +3530 -0
- package/{src/middleware/backpressure.ts → esm/src/middleware/backpressure.d.ts} +2 -14
- package/esm/src/middleware/backpressure.d.ts.map +1 -0
- package/esm/src/middleware/backpressure.js +31 -0
- package/esm/src/middleware/mod.d.ts +11 -0
- package/esm/src/middleware/mod.d.ts.map +1 -0
- package/{src/middleware/mod.ts → esm/src/middleware/mod.js} +0 -10
- package/{src/middleware/rate-limit.ts → esm/src/middleware/rate-limit.d.ts} +2 -25
- package/esm/src/middleware/rate-limit.d.ts.map +1 -0
- package/esm/src/middleware/rate-limit.js +33 -0
- package/esm/src/middleware/runner.d.ts +32 -0
- package/esm/src/middleware/runner.d.ts.map +1 -0
- package/esm/src/middleware/runner.js +49 -0
- package/esm/src/middleware/types.d.ts +76 -0
- package/esm/src/middleware/types.d.ts.map +1 -0
- package/esm/src/middleware/types.js +9 -0
- package/esm/src/middleware/validation.d.ts +24 -0
- package/esm/src/middleware/validation.d.ts.map +1 -0
- package/esm/src/middleware/validation.js +30 -0
- package/esm/src/mrtr/capability-check.d.ts +75 -0
- package/esm/src/mrtr/capability-check.d.ts.map +1 -0
- package/esm/src/mrtr/capability-check.js +233 -0
- package/esm/src/mrtr/mod.d.ts +18 -0
- package/esm/src/mrtr/mod.d.ts.map +1 -0
- package/esm/src/mrtr/mod.js +12 -0
- package/esm/src/mrtr/replay-store.d.ts +50 -0
- package/esm/src/mrtr/replay-store.d.ts.map +1 -0
- package/esm/src/mrtr/replay-store.js +61 -0
- package/esm/src/mrtr/request-state.d.ts +181 -0
- package/esm/src/mrtr/request-state.d.ts.map +1 -0
- package/esm/src/mrtr/request-state.js +313 -0
- package/esm/src/mrtr/retry-guard.d.ts +61 -0
- package/esm/src/mrtr/retry-guard.d.ts.map +1 -0
- package/esm/src/mrtr/retry-guard.js +53 -0
- package/esm/src/mrtr/types.d.ts +99 -0
- package/esm/src/mrtr/types.d.ts.map +1 -0
- package/esm/src/mrtr/types.js +14 -0
- package/esm/src/observability/metrics.d.ts +104 -0
- package/esm/src/observability/metrics.d.ts.map +1 -0
- package/esm/src/observability/metrics.js +207 -0
- package/{src/observability/mod.ts → esm/src/observability/mod.d.ts} +2 -11
- package/esm/src/observability/mod.d.ts.map +1 -0
- package/esm/src/observability/mod.js +11 -0
- package/esm/src/observability/otel.d.ts +73 -0
- package/esm/src/observability/otel.d.ts.map +1 -0
- package/esm/src/observability/otel.js +260 -0
- package/esm/src/runtime/runtime.d.ts +10 -0
- package/esm/src/runtime/runtime.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.d.ts +50 -0
- package/esm/src/runtime/runtime.deno.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.js +120 -0
- package/{src/runtime/runtime.ts → esm/src/runtime/runtime.js} +5 -14
- package/esm/src/runtime/runtime.node.d.ts +51 -0
- package/esm/src/runtime/runtime.node.d.ts.map +1 -0
- package/esm/src/runtime/runtime.node.js +268 -0
- package/{src/runtime/types.ts → esm/src/runtime/types.d.ts} +28 -51
- package/esm/src/runtime/types.d.ts.map +1 -0
- package/esm/src/runtime/types.js +12 -0
- package/esm/src/security/channel-hmac.d.ts +43 -0
- package/esm/src/security/channel-hmac.d.ts.map +1 -0
- package/{src/security/channel-hmac.ts → esm/src/security/channel-hmac.js} +12 -17
- package/esm/src/security/csp.d.ts +50 -0
- package/esm/src/security/csp.d.ts.map +1 -0
- package/esm/src/security/csp.js +63 -0
- package/esm/src/security/message-signer.d.ts +88 -0
- package/esm/src/security/message-signer.d.ts.map +1 -0
- package/esm/src/security/message-signer.js +166 -0
- package/esm/src/subscriptions/subscription-registry.d.ts +256 -0
- package/esm/src/subscriptions/subscription-registry.d.ts.map +1 -0
- package/esm/src/subscriptions/subscription-registry.js +406 -0
- package/{src/tasks/mod.ts → esm/src/tasks/mod.d.ts} +3 -23
- package/esm/src/tasks/mod.d.ts.map +1 -0
- package/esm/src/tasks/mod.js +11 -0
- package/esm/src/tasks/task-store.d.ts +342 -0
- package/esm/src/tasks/task-store.d.ts.map +1 -0
- package/esm/src/tasks/task-store.js +649 -0
- package/esm/src/transport/request-headers.d.ts +145 -0
- package/esm/src/transport/request-headers.d.ts.map +1 -0
- package/esm/src/transport/request-headers.js +525 -0
- package/esm/src/types.d.ts +776 -0
- package/esm/src/types.d.ts.map +1 -0
- package/esm/src/types.js +92 -0
- package/esm/src/ui/viewer-utils.d.ts +45 -0
- package/esm/src/ui/viewer-utils.d.ts.map +1 -0
- package/esm/src/ui/viewer-utils.js +97 -0
- package/esm/src/validation/schema-validator.d.ts +115 -0
- package/esm/src/validation/schema-validator.d.ts.map +1 -0
- package/esm/src/validation/schema-validator.js +249 -0
- package/package.json +35 -23
- package/mod.ts +0 -302
- package/src/auth/as-metadata-proxy.ts +0 -288
- package/src/auth/config.ts +0 -368
- package/src/auth/jwt-provider.ts +0 -327
- package/src/auth/middleware.ts +0 -257
- package/src/auth/mod.ts +0 -89
- package/src/auth/multi-tenant-middleware.ts +0 -236
- package/src/auth/presets.ts +0 -351
- package/src/auth/scope-middleware.ts +0 -59
- package/src/auth/static-token-provider.ts +0 -197
- package/src/auth/types.ts +0 -207
- package/src/client-auth/callback-server.ts +0 -166
- package/src/client-auth/client-id-metadata.ts +0 -260
- package/src/client-auth/connect.ts +0 -72
- package/src/client-auth/provider.ts +0 -300
- package/src/client-auth/token-store/file-store.ts +0 -73
- package/src/client-auth/token-store/memory-store.ts +0 -32
- package/src/client-auth/types.ts +0 -95
- package/src/concurrency/rate-limiter.ts +0 -190
- package/src/concurrency/request-queue.ts +0 -140
- package/src/http/body.ts +0 -72
- package/src/http/request-guards.ts +0 -137
- package/src/inspector/launcher.ts +0 -131
- package/src/mcp-app.ts +0 -4426
- package/src/middleware/runner.ts +0 -63
- package/src/middleware/types.ts +0 -104
- package/src/middleware/validation.ts +0 -28
- package/src/mrtr/capability-check.ts +0 -303
- package/src/mrtr/mod.ts +0 -46
- package/src/mrtr/replay-store.ts +0 -103
- package/src/mrtr/request-state.ts +0 -435
- package/src/mrtr/types.ts +0 -107
- package/src/observability/metrics.ts +0 -336
- package/src/observability/otel.ts +0 -330
- package/src/runtime/runtime.deno.ts +0 -149
- package/src/runtime/runtime.node.ts +0 -324
- package/src/security/csp.ts +0 -89
- package/src/security/message-signer.ts +0 -223
- package/src/subscriptions/subscription-registry.ts +0 -558
- package/src/tasks/task-store.ts +0 -1014
- package/src/testdata/stdio-e2e-server.ts +0 -110
- package/src/transport/request-headers.ts +0 -661
- package/src/types.ts +0 -907
- package/src/ui/viewer-utils.ts +0 -117
- package/src/validation/schema-validator.ts +0 -307
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the MCP Concurrent Server Framework
|
|
3
|
+
*
|
|
4
|
+
* This module provides TypeScript types for building high-performance
|
|
5
|
+
* MCP servers with built-in concurrency control and backpressure.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/server/types
|
|
8
|
+
*/
|
|
9
|
+
import type { ClientCapabilities, Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Rate limit configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface RateLimitOptions {
|
|
14
|
+
/** Maximum requests per window */
|
|
15
|
+
maxRequests: number;
|
|
16
|
+
/** Time window in milliseconds */
|
|
17
|
+
windowMs: number;
|
|
18
|
+
/**
|
|
19
|
+
* Function to extract client identifier from request context
|
|
20
|
+
* Default: uses "default" for all requests (global rate limit)
|
|
21
|
+
*/
|
|
22
|
+
keyExtractor?: (context: RateLimitContext) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Behavior when rate limit is exceeded
|
|
25
|
+
* - 'reject': Return error immediately
|
|
26
|
+
* - 'wait': Wait for slot with backoff (default)
|
|
27
|
+
*/
|
|
28
|
+
onLimitExceeded?: "reject" | "wait";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Context passed to rate limit key extractor
|
|
32
|
+
*/
|
|
33
|
+
export interface RateLimitContext {
|
|
34
|
+
/** Tool being called */
|
|
35
|
+
toolName: string;
|
|
36
|
+
/** Tool arguments */
|
|
37
|
+
args: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuration options for McpApp
|
|
41
|
+
*/
|
|
42
|
+
export interface McpAppOptions {
|
|
43
|
+
/** Server name (shown in MCP protocol) */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Server version */
|
|
46
|
+
version: string;
|
|
47
|
+
/** Maximum concurrent requests (default: 10) */
|
|
48
|
+
maxConcurrent?: number;
|
|
49
|
+
/** Backpressure strategy when at capacity (default: 'sleep') */
|
|
50
|
+
backpressureStrategy?: "sleep" | "queue" | "reject";
|
|
51
|
+
/** Sleep duration in ms for 'sleep' strategy (default: 10) */
|
|
52
|
+
backpressureSleepMs?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Rate limiting configuration
|
|
55
|
+
* If provided, requests will be rate limited per client
|
|
56
|
+
*/
|
|
57
|
+
rateLimit?: RateLimitOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Enable JSON Schema validation for tool arguments (default: false)
|
|
60
|
+
* When enabled, validates arguments against tool's inputSchema before execution
|
|
61
|
+
*/
|
|
62
|
+
validateSchema?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated No-op as of 0.24.0. The SamplingBridge was removed in the
|
|
65
|
+
* MCP 2026-07-28 spec drop. Passing this option has zero effect and emits
|
|
66
|
+
* a console warning at startup. Will be removed in 0.25.0.
|
|
67
|
+
*/
|
|
68
|
+
enableSampling?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Instructions for the LLM on how to use this server's tools.
|
|
71
|
+
* Sent in the MCP initialize response. The LLM sees this before any tool call.
|
|
72
|
+
*/
|
|
73
|
+
instructions?: string;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated No-op as of 0.24.0. The SamplingBridge was removed in the
|
|
76
|
+
* MCP 2026-07-28 spec drop. Passing this option has zero effect and emits
|
|
77
|
+
* a console warning at startup. Will be removed in 0.25.0.
|
|
78
|
+
*/
|
|
79
|
+
samplingClient?: SamplingClient;
|
|
80
|
+
/** Custom logger function (default: console.error) */
|
|
81
|
+
logger?: (msg: string) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Custom error handler for tool execution errors.
|
|
84
|
+
*
|
|
85
|
+
* When set, errors thrown by tool handlers are passed to this function.
|
|
86
|
+
* Return a message string to produce `{ content: [{type:"text", text: msg}], isError: true }`
|
|
87
|
+
* instead of re-throwing. Return null to rethrow as a JSON-RPC error.
|
|
88
|
+
*
|
|
89
|
+
* Default: undefined (all errors are re-thrown, existing behaviour).
|
|
90
|
+
*/
|
|
91
|
+
toolErrorMapper?: ToolErrorMapper;
|
|
92
|
+
/**
|
|
93
|
+
* OAuth2/Bearer authentication configuration.
|
|
94
|
+
* When provided, HTTP requests require a valid Bearer token.
|
|
95
|
+
* STDIO transport is unaffected (local, no auth needed).
|
|
96
|
+
*/
|
|
97
|
+
auth?: import("./auth/types.js").AuthOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Content Security Policy for HTML resources (MCP Apps).
|
|
100
|
+
* When provided, injects a CSP `<meta>` tag into HTML content before serving.
|
|
101
|
+
* This protects against XSS even in STDIO mode where HTTP headers are unavailable.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* resourceCsp: { allowInline: true }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
resourceCsp?: import("./security/csp.js").CspOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Pre-declare the `resources` capability before transport connection.
|
|
111
|
+
*
|
|
112
|
+
* When true, installs `resources/list` and `resources/read` handlers at
|
|
113
|
+
* construction time (before start/startHttp). Resources can then be added
|
|
114
|
+
* dynamically after startup via registerResource() without hitting the
|
|
115
|
+
* SDK's "Cannot register capabilities after connecting to transport" error.
|
|
116
|
+
*
|
|
117
|
+
* Use this when resources are discovered asynchronously (e.g., MCP relay/proxy
|
|
118
|
+
* that discovers child servers after the stdio handshake).
|
|
119
|
+
*/
|
|
120
|
+
expectResources?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* HTTP transport mode. Only `"stateless"` is supported as of spec 2026-07-28.
|
|
123
|
+
*
|
|
124
|
+
* Per-request transport: no handshake, no `Mcp-Session-Id`.
|
|
125
|
+
* `protocolVersion` is read from
|
|
126
|
+
* `params._meta["io.modelcontextprotocol/protocolVersion"]` on every
|
|
127
|
+
* request. `GET /mcp` returns 405; use `subscriptions/listen` instead.
|
|
128
|
+
*/
|
|
129
|
+
transport?: "stateless";
|
|
130
|
+
/**
|
|
131
|
+
* Cache hints emitted on list and read results (spec 2026-07-28,
|
|
132
|
+
* `CacheableResult`, SEP-2549).
|
|
133
|
+
*
|
|
134
|
+
* `ttlMs` and `cacheScope` are **required** fields of those results, so the
|
|
135
|
+
* framework always emits them. The defaults are deliberately inert:
|
|
136
|
+
*
|
|
137
|
+
* - `ttlMs: 0` — "revalidate every time", the HTTP `max-age=0` equivalent.
|
|
138
|
+
* Caching is a per-deployment decision: a server whose tool list is built
|
|
139
|
+
* from a live database must not have a stale window chosen for it. Opt in
|
|
140
|
+
* with a real value.
|
|
141
|
+
* - `cacheScope: "private"` — shared intermediaries must not cache the
|
|
142
|
+
* response. Anything else would be unsafe by default here, since results can
|
|
143
|
+
* be scoped to the authenticated principal or tenant. Use `"public"` only for
|
|
144
|
+
* a server whose lists are genuinely identical for every caller.
|
|
145
|
+
*/
|
|
146
|
+
cache?: {
|
|
147
|
+
/** Freshness window in milliseconds. Default `0`. */
|
|
148
|
+
ttlMs?: number;
|
|
149
|
+
/** Whether shared caches may store the response. Default `"private"`. */
|
|
150
|
+
scope?: "public" | "private";
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Authorization key a task is bound to, derived from the request that created it.
|
|
154
|
+
*
|
|
155
|
+
* A task can only be read, answered or cancelled by a caller whose key matches.
|
|
156
|
+
* The default is the authenticated subject, which is right for a
|
|
157
|
+
* single-authority deployment and **not enough** for anything that authorizes on
|
|
158
|
+
* more than identity: a tenant-scoped server where the same subject may act for
|
|
159
|
+
* several tenants needs the tenant in the key, or a task created under one
|
|
160
|
+
* tenant stays reachable from another.
|
|
161
|
+
*
|
|
162
|
+
* The framework cannot derive that itself — tenancy lives in a consumer's own
|
|
163
|
+
* middleware — so it is a hook rather than a guess. Return a stable string; it is
|
|
164
|
+
* compared verbatim.
|
|
165
|
+
*
|
|
166
|
+
* **It must derive everything from its two arguments.** `tasks/*` requests do
|
|
167
|
+
* not run the middleware pipeline, so anything a middleware injects into the
|
|
168
|
+
* pipeline context — the built-in tenant middleware's `tenantId`, for instance —
|
|
169
|
+
* is NOT visible here. Read the header, or resolve it yourself; the hook may be
|
|
170
|
+
* async precisely so a lookup is possible. A hook that expects pipeline state
|
|
171
|
+
* silently sees `undefined` on every call, which collapses every caller onto one
|
|
172
|
+
* key.
|
|
173
|
+
*
|
|
174
|
+
* Returning an empty or non-string value is refused rather than accepted, since
|
|
175
|
+
* that is what the obvious implementation yields when the value it reads is
|
|
176
|
+
* absent, and accepting it would share tasks between callers.
|
|
177
|
+
*
|
|
178
|
+
* Called on task creation and on every `tasks/get` / `tasks/update` /
|
|
179
|
+
* `tasks/cancel`. It must return the same key for the same caller across those
|
|
180
|
+
* calls, or the creator stops being able to reach its own task (fail-closed).
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* taskOwnerKey: (authInfo, request) =>
|
|
185
|
+
* `${authInfo?.subject}@${request.headers.get("x-tenant-id")}`
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
taskOwnerKey?: (authInfo: import("./auth/types.js").AuthInfo | undefined, request: Request) => string | Promise<string>;
|
|
189
|
+
/**
|
|
190
|
+
* Multi Round-Trip Requests (spec 2026-07-28, SEP-2322).
|
|
191
|
+
*
|
|
192
|
+
* Configures how `requestState` is protected when a tool handler asks the
|
|
193
|
+
* client for input mid-call. Consulted by stateless HTTP and by the v2 stdio
|
|
194
|
+
* serving entry. On a legacy stdio connection the SDK fulfils the embedded
|
|
195
|
+
* requests through its compatibility shim, then re-enters the same verified
|
|
196
|
+
* handler; application code keeps one MRTR contract across both eras.
|
|
197
|
+
*
|
|
198
|
+
* Without `signingKey`, `requestState` travels unprotected and the server logs
|
|
199
|
+
* a warning at startup. That is only acceptable when tampering with it can
|
|
200
|
+
* cause nothing worse than the request failing.
|
|
201
|
+
*/
|
|
202
|
+
mrtr?: import("./mrtr/mod.js").MrtrOptions;
|
|
203
|
+
/**
|
|
204
|
+
* Protocol extensions this server declares (spec 2026-07-28).
|
|
205
|
+
*
|
|
206
|
+
* Keyed by reverse-DNS extension identifier — e.g.
|
|
207
|
+
* `{ "io.modelcontextprotocol/tasks": {} }`. Surfaced under
|
|
208
|
+
* `capabilities.extensions` on `server/discover` and `initialize`, and only
|
|
209
|
+
* when non-empty: an empty object would assert "no extensions supported",
|
|
210
|
+
* which is a claim the framework cannot make on a consumer's behalf.
|
|
211
|
+
*
|
|
212
|
+
* Declaring an extension here does not implement it — it advertises what the
|
|
213
|
+
* consumer has wired up.
|
|
214
|
+
*/
|
|
215
|
+
extensions?: Readonly<Record<string, unknown>>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* MCP Apps UI metadata for tools (SEP-1865 + PML extensions)
|
|
219
|
+
*
|
|
220
|
+
* Mirrors the structural fields of the official MCP Apps `McpUiToolMeta`
|
|
221
|
+
* contract and adds PML-specific `emits`/`accepts` fields for cross-UI sync
|
|
222
|
+
* rules. Keeping this public declaration structural avoids leaking the
|
|
223
|
+
* upstream package's internal declaration-module layout into Node consumers.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const tool: MCPTool = {
|
|
228
|
+
* name: "query_table",
|
|
229
|
+
* description: "Query database table",
|
|
230
|
+
* inputSchema: { ... },
|
|
231
|
+
* _meta: {
|
|
232
|
+
* ui: {
|
|
233
|
+
* resourceUri: "ui://mcp-std/table-viewer",
|
|
234
|
+
* emits: ["filter", "select"],
|
|
235
|
+
* accepts: ["setData", "highlight"]
|
|
236
|
+
* }
|
|
237
|
+
* }
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export interface McpUiToolMeta {
|
|
242
|
+
/**
|
|
243
|
+
* Resource URI for the UI. MUST use ui:// scheme.
|
|
244
|
+
* Narrows the optional base field to required for server tools.
|
|
245
|
+
* @example "ui://mcp-std/table-viewer"
|
|
246
|
+
*/
|
|
247
|
+
resourceUri: string;
|
|
248
|
+
/**
|
|
249
|
+
* Who can access this tool. Defaults to both the model and the app.
|
|
250
|
+
*/
|
|
251
|
+
visibility?: Array<"model" | "app">;
|
|
252
|
+
/** CSP belongs on the UI resource, not on tool metadata. */
|
|
253
|
+
csp?: never;
|
|
254
|
+
/** Permissions belong on the UI resource, not on tool metadata. */
|
|
255
|
+
permissions?: never;
|
|
256
|
+
/**
|
|
257
|
+
* Events this UI can emit (PML extension for sync rules)
|
|
258
|
+
* Used by PML orchestrator to build cross-UI event routing
|
|
259
|
+
* @example ["filter", "select", "sort", "paginate"]
|
|
260
|
+
*/
|
|
261
|
+
emits?: string[];
|
|
262
|
+
/**
|
|
263
|
+
* Events this UI can accept (PML extension for sync rules)
|
|
264
|
+
* Used by PML orchestrator to build cross-UI event routing
|
|
265
|
+
* @example ["setData", "highlight", "scrollTo"]
|
|
266
|
+
*/
|
|
267
|
+
accepts?: string[];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* MCP Tool metadata container.
|
|
271
|
+
*
|
|
272
|
+
* Carries optional UI hints and routing metadata for MCP Apps (SEP-1865).
|
|
273
|
+
*/
|
|
274
|
+
export interface MCPToolMeta {
|
|
275
|
+
/** UI configuration for rendering this tool's output in an MCP App */
|
|
276
|
+
ui?: McpUiToolMeta;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* MCP Resource definition for registration
|
|
280
|
+
*/
|
|
281
|
+
export interface MCPResource {
|
|
282
|
+
/**
|
|
283
|
+
* Resource URI. SHOULD use ui:// scheme for MCP Apps.
|
|
284
|
+
* @example "ui://mcp-std/table-viewer"
|
|
285
|
+
*/
|
|
286
|
+
uri: string;
|
|
287
|
+
/** Human-readable name */
|
|
288
|
+
name: string;
|
|
289
|
+
/** Description of the resource */
|
|
290
|
+
description?: string;
|
|
291
|
+
/** Optional display title, distinct from the protocol-required `name`. */
|
|
292
|
+
title?: string;
|
|
293
|
+
/** Optional visual hints advertised in `resources/list`. */
|
|
294
|
+
icons?: Array<{
|
|
295
|
+
src: string;
|
|
296
|
+
mimeType?: string;
|
|
297
|
+
sizes?: string[];
|
|
298
|
+
theme?: "light" | "dark";
|
|
299
|
+
}>;
|
|
300
|
+
/** Optional client-facing resource annotations. */
|
|
301
|
+
annotations?: {
|
|
302
|
+
audience?: Array<"user" | "assistant">;
|
|
303
|
+
priority?: number;
|
|
304
|
+
lastModified?: string;
|
|
305
|
+
};
|
|
306
|
+
/** Optional protocol/extension metadata advertised in `resources/list`. */
|
|
307
|
+
_meta?: Record<string, unknown>;
|
|
308
|
+
/** MIME type, when known before the resource is read. */
|
|
309
|
+
mimeType?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Byte size of the resource when it is known.
|
|
312
|
+
*
|
|
313
|
+
* This is an exact byte-size attestation: when supplied, every read must
|
|
314
|
+
* return exactly this many UTF-8 bytes for `text`, or decoded bytes for
|
|
315
|
+
* `blob`. It is surfaced in `resources/list` so clients can make loading
|
|
316
|
+
* decisions before reading. Must be a non-negative safe integer.
|
|
317
|
+
*/
|
|
318
|
+
size?: number;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Common fields of every resource response.
|
|
322
|
+
*/
|
|
323
|
+
interface ResourceContentBase {
|
|
324
|
+
/** URI of the resource. It must exactly match the URI that was requested. */
|
|
325
|
+
uri: string;
|
|
326
|
+
/** Non-empty MIME type of the content. */
|
|
327
|
+
mimeType: string;
|
|
328
|
+
/** Optional MCP metadata passed through to the protocol response. */
|
|
329
|
+
_meta?: Record<string, unknown>;
|
|
330
|
+
}
|
|
331
|
+
/** A UTF-8/text resource response. */
|
|
332
|
+
export interface TextResourceContent extends ResourceContentBase {
|
|
333
|
+
/** Text payload, including HTML for MCP Apps. */
|
|
334
|
+
text: string;
|
|
335
|
+
/** Text and blob payloads are mutually exclusive. */
|
|
336
|
+
blob?: never;
|
|
337
|
+
}
|
|
338
|
+
/** A binary resource response encoded as canonical standard base64. */
|
|
339
|
+
export interface BlobResourceContent extends ResourceContentBase {
|
|
340
|
+
/** Standard, padded base64 payload. */
|
|
341
|
+
blob: string;
|
|
342
|
+
/** Text and blob payloads are mutually exclusive. */
|
|
343
|
+
text?: never;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Content returned by a resource handler.
|
|
347
|
+
*
|
|
348
|
+
* Exactly one payload form is allowed: `text` for text/HTML, or `blob` for
|
|
349
|
+
* binary content encoded as canonical standard base64. The framework validates
|
|
350
|
+
* the same XOR contract at runtime before writing the response, which keeps
|
|
351
|
+
* JavaScript consumers and unchecked handler results on the protocol-safe path.
|
|
352
|
+
*/
|
|
353
|
+
export type ResourceContent = TextResourceContent | BlobResourceContent;
|
|
354
|
+
/**
|
|
355
|
+
* Resource handler callback
|
|
356
|
+
*
|
|
357
|
+
* @param uri - The requested resource URI as URL object
|
|
358
|
+
* @returns A text or base64-blob ResourceContent whose URI matches `uri`
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const handler: ResourceHandler = async (uri) => ({
|
|
363
|
+
* uri: uri.toString(),
|
|
364
|
+
* mimeType: MCP_APP_MIME_TYPE,
|
|
365
|
+
* text: "<html>...</html>"
|
|
366
|
+
* });
|
|
367
|
+
*
|
|
368
|
+
* // For binary content, return `blob` instead of `text`:
|
|
369
|
+
* // { uri: uri.toString(), mimeType: "image/png", blob: "iVBORw0KGgo..." }
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
export type ResourceHandler = (uri: URL) => Promise<ResourceContent> | ResourceContent;
|
|
373
|
+
/** MCP Apps MIME type constant */
|
|
374
|
+
export declare const MCP_APP_MIME_TYPE: "text/html;profile=mcp-app";
|
|
375
|
+
/** URI scheme for MCP Apps resources */
|
|
376
|
+
export declare const MCP_APP_URI_SCHEME: "ui:";
|
|
377
|
+
/**
|
|
378
|
+
* Well-known extension identifier for the MCP Apps protocol.
|
|
379
|
+
*
|
|
380
|
+
* Clients advertise MCP Apps support by including this key in
|
|
381
|
+
* `clientCapabilities.extensions` (per the MCP SDK 1.29 extensions
|
|
382
|
+
* feature). Servers read it via {@link getMcpAppsCapability} to decide
|
|
383
|
+
* whether to register UI-rendering tools or fall back to text-only.
|
|
384
|
+
*
|
|
385
|
+
* @see {@link https://github.com/modelcontextprotocol/ext-apps | MCP Apps spec}
|
|
386
|
+
*/
|
|
387
|
+
export declare const MCP_APPS_EXTENSION_ID: "io.modelcontextprotocol/ui";
|
|
388
|
+
/**
|
|
389
|
+
* MCP Apps protocol spec version this package targets.
|
|
390
|
+
*
|
|
391
|
+
* Matches the dated spec at
|
|
392
|
+
* https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx
|
|
393
|
+
*
|
|
394
|
+
* Bump this constant in the same commit that adopts a newer dated spec.
|
|
395
|
+
*/
|
|
396
|
+
export declare const MCP_APPS_PROTOCOL_VERSION: "2026-01-26";
|
|
397
|
+
/**
|
|
398
|
+
* MCP Apps capability advertised by a client.
|
|
399
|
+
*
|
|
400
|
+
* Returned by {@link getMcpAppsCapability} after reading
|
|
401
|
+
* `clientCapabilities.extensions[MCP_APPS_EXTENSION_ID]`.
|
|
402
|
+
*
|
|
403
|
+
* The capability object is intentionally minimal — the spec keeps it
|
|
404
|
+
* extensible by adding fields rather than removing them, so consumers
|
|
405
|
+
* MUST tolerate unknown fields.
|
|
406
|
+
*/
|
|
407
|
+
export interface McpAppsClientCapability {
|
|
408
|
+
/**
|
|
409
|
+
* MIME types the client can render as MCP Apps.
|
|
410
|
+
*
|
|
411
|
+
* Typically includes `"text/html;profile=mcp-app"`. An empty or
|
|
412
|
+
* absent array means the client advertised support but listed no
|
|
413
|
+
* concrete mime types — defensively assume nothing.
|
|
414
|
+
*/
|
|
415
|
+
mimeTypes?: string[];
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Read the MCP Apps capability from a client's advertised capabilities.
|
|
419
|
+
*
|
|
420
|
+
* Best-effort, defensive reader. Returns `undefined` for any of:
|
|
421
|
+
* - `null` / `undefined` input
|
|
422
|
+
* - `clientCapabilities` without an `extensions` field
|
|
423
|
+
* - `extensions` without the {@link MCP_APPS_EXTENSION_ID} key
|
|
424
|
+
* - extension value that is not a plain object (string, number, null, ...)
|
|
425
|
+
*
|
|
426
|
+
* Malformed `mimeTypes` (wrong type, non-string entries) are silently
|
|
427
|
+
* filtered rather than thrown — agents reading this function need a
|
|
428
|
+
* predictable contract that never crashes downstream consumers on
|
|
429
|
+
* untrusted client data.
|
|
430
|
+
*
|
|
431
|
+
* **Validation scope:** this function only validates the *type* of
|
|
432
|
+
* `mimeTypes` entries (must be string). It does NOT validate that the
|
|
433
|
+
* strings look like valid mime types (e.g. empty strings or garbage
|
|
434
|
+
* content pass through). Consumers should compare against known
|
|
435
|
+
* constants like {@link MCP_APP_MIME_TYPE} via `.includes()` rather
|
|
436
|
+
* than treating the array as a generic allowlist.
|
|
437
|
+
*
|
|
438
|
+
* @param clientCapabilities - The `ClientCapabilities` object from the
|
|
439
|
+
* MCP SDK initialize handshake. May be `null` or `undefined` if the
|
|
440
|
+
* client never sent capabilities.
|
|
441
|
+
* @returns The MCP Apps capability if the client advertised support,
|
|
442
|
+
* otherwise `undefined`.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const cap = getMcpAppsCapability(client.getClientCapabilities());
|
|
447
|
+
* if (cap?.mimeTypes?.includes(MCP_APP_MIME_TYPE)) {
|
|
448
|
+
* // register UI-rendering tools
|
|
449
|
+
* } else {
|
|
450
|
+
* // register text-only fallback tools
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
export declare function getMcpAppsCapability(clientCapabilities: (Record<string, unknown> & {
|
|
455
|
+
extensions?: Record<string, unknown>;
|
|
456
|
+
}) | null | undefined): McpAppsClientCapability | undefined;
|
|
457
|
+
/**
|
|
458
|
+
* Behavioural hints for model clients (MCP SDK 1.27 ToolAnnotations).
|
|
459
|
+
* Passed through in tools/list so hosts can adapt their UI accordingly.
|
|
460
|
+
*/
|
|
461
|
+
export interface ToolAnnotations {
|
|
462
|
+
/** Short human-readable title, may differ from tool name */
|
|
463
|
+
title?: string;
|
|
464
|
+
/** If true, tool has no side-effects and is safe to call speculatively */
|
|
465
|
+
readOnlyHint?: boolean;
|
|
466
|
+
/** If true, executing may produce irreversible effects */
|
|
467
|
+
destructiveHint?: boolean;
|
|
468
|
+
/** If true, repeated calls with same args produce same result */
|
|
469
|
+
idempotentHint?: boolean;
|
|
470
|
+
/** If true, tool may interact with entities outside the MCP system */
|
|
471
|
+
openWorldHint?: boolean;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* MCP Tool definition (compatible with MCP protocol)
|
|
475
|
+
*/
|
|
476
|
+
export interface MCPTool {
|
|
477
|
+
/** Tool name */
|
|
478
|
+
name: string;
|
|
479
|
+
/** Human-readable description */
|
|
480
|
+
description: string;
|
|
481
|
+
/** JSON Schema for tool input */
|
|
482
|
+
inputSchema: Record<string, unknown>;
|
|
483
|
+
/**
|
|
484
|
+
* JSON Schema for the tool's structured output (MCP SDK 1.27).
|
|
485
|
+
* Passed through in tools/list so hosts can validate tool results.
|
|
486
|
+
*/
|
|
487
|
+
outputSchema?: Record<string, unknown>;
|
|
488
|
+
/** Behavioural hints passed to model clients */
|
|
489
|
+
annotations?: ToolAnnotations;
|
|
490
|
+
/**
|
|
491
|
+
* Tool metadata including UI configuration for MCP Apps
|
|
492
|
+
* @see McpUiToolMeta
|
|
493
|
+
*/
|
|
494
|
+
_meta?: MCPToolMeta;
|
|
495
|
+
/**
|
|
496
|
+
* Required OAuth scopes to call this tool.
|
|
497
|
+
* Enforced for HTTP calls. A scoped HTTP tool fails closed when the server has
|
|
498
|
+
* no auth provider or the authenticated caller lacks one of these scopes.
|
|
499
|
+
* STDIO is a trusted local transport and does not apply OAuth scope checks.
|
|
500
|
+
* If empty or undefined, no scope check is performed.
|
|
501
|
+
*/
|
|
502
|
+
requiredScopes?: string[];
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Tool handler function.
|
|
506
|
+
*
|
|
507
|
+
* Receives validated arguments and returns a result (or throws).
|
|
508
|
+
* The return value is serialised as JSON inside a `text` content block.
|
|
509
|
+
*
|
|
510
|
+
* **Security**: Never pass `args` values directly to shell commands or SQL.
|
|
511
|
+
* Always validate / sanitise inside the handler or via `inputSchema`.
|
|
512
|
+
*
|
|
513
|
+
* @param args - Validated tool arguments from the MCP client
|
|
514
|
+
* @returns Tool result (string, object, or Promise thereof)
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const handler: ToolHandler = async (args) => {
|
|
519
|
+
* const rows = await db.query(args.sql as string);
|
|
520
|
+
* return { rows, count: rows.length };
|
|
521
|
+
* };
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export interface ToolHandlerContext {
|
|
525
|
+
readonly toolName: string;
|
|
526
|
+
readonly request?: Request;
|
|
527
|
+
readonly sessionId?: string;
|
|
528
|
+
readonly authInfo?: import("./auth/types.js").AuthInfo;
|
|
529
|
+
readonly clientInfo?: Implementation;
|
|
530
|
+
readonly clientCapabilities?: ClientCapabilities;
|
|
531
|
+
/**
|
|
532
|
+
* Answers to a previous `InputRequiredResult`, keyed by the ids the server
|
|
533
|
+
* assigned (spec 2026-07-28 MRTR).
|
|
534
|
+
*
|
|
535
|
+
* Present only on a retry. Read from `params.inputResponses` — a sibling of
|
|
536
|
+
* `_meta`, not a member of it, unlike every other per-request field. Getting
|
|
537
|
+
* that wrong yields a silent `undefined` even when the client sent them.
|
|
538
|
+
*/
|
|
539
|
+
readonly inputResponses?: Record<string, unknown>;
|
|
540
|
+
/**
|
|
541
|
+
* True when the client echoed a `requestState` that passed integrity
|
|
542
|
+
* verification, so the handler may trust this is a legitimate retry of its own
|
|
543
|
+
* earlier request.
|
|
544
|
+
*
|
|
545
|
+
* The token carries no application state — it binds the principal, method,
|
|
546
|
+
* argument digest and expiry. Since the digest guarantees the arguments are
|
|
547
|
+
* byte-identical to the original call, a handler reconstructs its context from
|
|
548
|
+
* those arguments rather than from the token.
|
|
549
|
+
*/
|
|
550
|
+
readonly retryVerified?: boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Log level requested for this call (spec 2026-07-28), read from
|
|
553
|
+
* `params._meta["io.modelcontextprotocol/logLevel"]`.
|
|
554
|
+
*
|
|
555
|
+
* `undefined` means the client requested no logging. A handler **MUST NOT**
|
|
556
|
+
* emit `notifications/message` in that case — the level is not a filter you
|
|
557
|
+
* may default, it is the client's opt-in.
|
|
558
|
+
*/
|
|
559
|
+
readonly logLevel?: import("./middleware/types.js").McpLogLevel;
|
|
560
|
+
}
|
|
561
|
+
export type ToolHandler = (args: Record<string, unknown>, ctx?: ToolHandlerContext) => Promise<unknown> | unknown;
|
|
562
|
+
/**
|
|
563
|
+
* Structured tool result: separates the LLM text summary (content)
|
|
564
|
+
* from the machine-readable payload (structuredContent).
|
|
565
|
+
*
|
|
566
|
+
* When a ToolHandler returns this shape, the framework produces a
|
|
567
|
+
* CallToolResult with both `content` and `structuredContent` set,
|
|
568
|
+
* keeping heavy data out of the LLM context.
|
|
569
|
+
*/
|
|
570
|
+
export interface StructuredToolResult {
|
|
571
|
+
/** Human-readable summary shown in content[0].text */
|
|
572
|
+
content: string;
|
|
573
|
+
/** Structured data conforming to the tool's outputSchema */
|
|
574
|
+
structuredContent: Record<string, unknown>;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Maps a thrown error to either a business error result (isError: true)
|
|
578
|
+
* or signals that the error should be re-thrown as a JSON-RPC error.
|
|
579
|
+
*
|
|
580
|
+
* @returns A message string to produce `{ isError: true }`, or null to rethrow.
|
|
581
|
+
*/
|
|
582
|
+
export type ToolErrorMapper = (error: unknown, toolName: string) => string | null;
|
|
583
|
+
/**
|
|
584
|
+
* Sampling client interface — no-op as of 0.24.0. The SamplingBridge was
|
|
585
|
+
* removed with MCP 2026-07-28. This type is kept for source compatibility
|
|
586
|
+
* only and will be removed in 0.25.0.
|
|
587
|
+
*
|
|
588
|
+
* @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
|
|
589
|
+
*/
|
|
590
|
+
export interface SamplingClient {
|
|
591
|
+
/**
|
|
592
|
+
* Request LLM completion from the client
|
|
593
|
+
* @param params - Sampling parameters (messages, tools, etc.)
|
|
594
|
+
* @returns Completion result with content and stop reason
|
|
595
|
+
*/
|
|
596
|
+
createMessage(params: SamplingParams): Promise<SamplingResult>;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Parameters for sampling request — no-op as of 0.24.0.
|
|
600
|
+
*
|
|
601
|
+
* @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
|
|
602
|
+
*/
|
|
603
|
+
export interface SamplingParams {
|
|
604
|
+
messages: Array<{
|
|
605
|
+
role: "user" | "assistant";
|
|
606
|
+
content: string;
|
|
607
|
+
}>;
|
|
608
|
+
/** Tools available for the agent to use. Client handles execution. */
|
|
609
|
+
tools?: Array<{
|
|
610
|
+
name: string;
|
|
611
|
+
description: string;
|
|
612
|
+
inputSchema: Record<string, unknown>;
|
|
613
|
+
}>;
|
|
614
|
+
/** "auto" = LLM decides, "required" = must use tool, "none" = no tools */
|
|
615
|
+
toolChoice?: "auto" | "required" | "none";
|
|
616
|
+
maxTokens?: number;
|
|
617
|
+
/** Hint for client: max agentic loop iterations */
|
|
618
|
+
maxIterations?: number;
|
|
619
|
+
/** Tool name patterns to filter (e.g., ['git_*', 'vfs_*']) */
|
|
620
|
+
allowedToolPatterns?: string[];
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Result from sampling request — no-op as of 0.24.0.
|
|
624
|
+
*
|
|
625
|
+
* @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
|
|
626
|
+
*/
|
|
627
|
+
export interface SamplingResult {
|
|
628
|
+
content: Array<{
|
|
629
|
+
type: string;
|
|
630
|
+
text?: string;
|
|
631
|
+
name?: string;
|
|
632
|
+
input?: Record<string, unknown>;
|
|
633
|
+
}>;
|
|
634
|
+
stopReason: "end_turn" | "tool_use" | "max_tokens";
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Queue metrics for monitoring
|
|
638
|
+
*/
|
|
639
|
+
export interface QueueMetrics {
|
|
640
|
+
/** Number of requests currently executing */
|
|
641
|
+
inFlight: number;
|
|
642
|
+
/** Number of requests waiting in queue */
|
|
643
|
+
queued: number;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Promise resolver for pending requests
|
|
647
|
+
*/
|
|
648
|
+
export interface PromiseResolver<T = unknown> {
|
|
649
|
+
resolve: (value: T) => void;
|
|
650
|
+
reject: (error: Error) => void;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Request queue options
|
|
654
|
+
*/
|
|
655
|
+
export interface QueueOptions {
|
|
656
|
+
maxConcurrent: number;
|
|
657
|
+
strategy: "sleep" | "queue" | "reject";
|
|
658
|
+
sleepMs: number;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Context passed to HTTP rate limit key extractor
|
|
662
|
+
*/
|
|
663
|
+
export interface HttpRateLimitContext {
|
|
664
|
+
/** Client IP address (from x-forwarded-for/x-real-ip) */
|
|
665
|
+
ip: string;
|
|
666
|
+
/** HTTP method */
|
|
667
|
+
method: string;
|
|
668
|
+
/** HTTP path (e.g. /mcp) */
|
|
669
|
+
path: string;
|
|
670
|
+
/** HTTP headers */
|
|
671
|
+
headers: Headers;
|
|
672
|
+
/** MCP session ID, if present */
|
|
673
|
+
sessionId?: string;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* HTTP rate limit configuration
|
|
677
|
+
*/
|
|
678
|
+
export interface HttpRateLimitOptions {
|
|
679
|
+
/** Maximum requests per window */
|
|
680
|
+
maxRequests: number;
|
|
681
|
+
/** Time window in milliseconds */
|
|
682
|
+
windowMs: number;
|
|
683
|
+
/**
|
|
684
|
+
* Function to extract client identifier from HTTP context
|
|
685
|
+
* Default: uses IP address
|
|
686
|
+
*/
|
|
687
|
+
keyExtractor?: (context: HttpRateLimitContext) => string;
|
|
688
|
+
/**
|
|
689
|
+
* Behavior when rate limit is exceeded
|
|
690
|
+
* - 'reject': Return error immediately
|
|
691
|
+
* - 'wait': Wait for slot with backoff
|
|
692
|
+
*/
|
|
693
|
+
onLimitExceeded?: "reject" | "wait";
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Options for starting an HTTP server
|
|
697
|
+
*/
|
|
698
|
+
export type { FetchHandler } from "./runtime/types.js";
|
|
699
|
+
import type { FetchHandler } from "./runtime/types.js";
|
|
700
|
+
export interface HttpServerOptions {
|
|
701
|
+
/**
|
|
702
|
+
* Port to listen on. Ignored when {@link embedded} is `true`.
|
|
703
|
+
*/
|
|
704
|
+
port: number;
|
|
705
|
+
/** Hostname to bind to (default: "0.0.0.0") */
|
|
706
|
+
hostname?: string;
|
|
707
|
+
/** Enable CORS (default: true) */
|
|
708
|
+
cors?: boolean;
|
|
709
|
+
/**
|
|
710
|
+
* Allowed CORS origins (default: "*")
|
|
711
|
+
* Use an allowlist in production.
|
|
712
|
+
*/
|
|
713
|
+
corsOrigins?: "*" | string[];
|
|
714
|
+
/**
|
|
715
|
+
* Maximum request body size in bytes (default: 1_000_000).
|
|
716
|
+
* Set to null to disable the limit.
|
|
717
|
+
*/
|
|
718
|
+
maxBodyBytes?: number | null;
|
|
719
|
+
/**
|
|
720
|
+
* Require auth for HTTP mode. If true and auth is not configured, startHttp throws.
|
|
721
|
+
*/
|
|
722
|
+
requireAuth?: boolean;
|
|
723
|
+
/**
|
|
724
|
+
* IP-based rate limiting for HTTP endpoints.
|
|
725
|
+
*/
|
|
726
|
+
ipRateLimit?: HttpRateLimitOptions;
|
|
727
|
+
/**
|
|
728
|
+
* Custom HTTP routes registered alongside MCP protocol routes.
|
|
729
|
+
* Uses Web standard Request/Response (no framework dependency).
|
|
730
|
+
*/
|
|
731
|
+
customRoutes?: Array<{
|
|
732
|
+
method: "get" | "post";
|
|
733
|
+
path: string;
|
|
734
|
+
handler: (req: Request) => Response | Promise<Response>;
|
|
735
|
+
}>;
|
|
736
|
+
/**
|
|
737
|
+
* Callback when server is ready
|
|
738
|
+
* @param info - Server address info
|
|
739
|
+
*/
|
|
740
|
+
onListen?: (info: {
|
|
741
|
+
hostname: string;
|
|
742
|
+
port: number;
|
|
743
|
+
}) => void;
|
|
744
|
+
/**
|
|
745
|
+
* Embedded mode: skip binding a port and instead surface the Hono fetch
|
|
746
|
+
* handler via the {@link embeddedHandlerCallback} option. Used by
|
|
747
|
+
* {@link McpApp.getFetchHandler} so consumers (Fresh, Hono,
|
|
748
|
+
* Express, etc.) can mount the MCP HTTP stack inside their own server
|
|
749
|
+
* without giving up port ownership.
|
|
750
|
+
*
|
|
751
|
+
* When `true`, `port`, `hostname`, and `onListen` are ignored.
|
|
752
|
+
*/
|
|
753
|
+
embedded?: boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Receives the Hono fetch handler when running in embedded mode.
|
|
756
|
+
* Required when {@link embedded} is `true`. Called exactly once,
|
|
757
|
+
* synchronously, before `startHttp` returns.
|
|
758
|
+
*
|
|
759
|
+
* Most consumers should use {@link McpApp.getFetchHandler}
|
|
760
|
+
* instead of setting this directly.
|
|
761
|
+
*/
|
|
762
|
+
embeddedHandlerCallback?: (handler: FetchHandler) => void;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* HTTP server instance returned by startHttp
|
|
766
|
+
*/
|
|
767
|
+
export interface HttpServerInstance {
|
|
768
|
+
/** Shutdown the HTTP server */
|
|
769
|
+
shutdown(): Promise<void>;
|
|
770
|
+
/** Server address info */
|
|
771
|
+
addr: {
|
|
772
|
+
hostname: string;
|
|
773
|
+
port: number;
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
//# sourceMappingURL=types.d.ts.map
|