@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,728 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* McpApp — Hono-style framework for MCP servers
|
|
3
|
+
*
|
|
4
|
+
* High-performance MCP server with built-in concurrency control
|
|
5
|
+
* and backpressure.
|
|
6
|
+
*
|
|
7
|
+
* Wraps the official MCP server packages with middleware, auth, and
|
|
8
|
+
* observability features.
|
|
9
|
+
*
|
|
10
|
+
* @module lib/server/mcp-app
|
|
11
|
+
*/
|
|
12
|
+
import { RateLimiter } from "./concurrency/rate-limiter.js";
|
|
13
|
+
import { SchemaValidator } from "./validation/schema-validator.js";
|
|
14
|
+
import type { Middleware } from "./middleware/types.js";
|
|
15
|
+
import type { FetchHandler, HttpServerOptions, McpAppOptions, McpAppsClientCapability, MCPResource, MCPTool, QueueMetrics, ResourceContent, ResourceHandler, ToolHandler } from "./types.js";
|
|
16
|
+
import type { DiscoverViewersFS } from "./ui/viewer-utils.js";
|
|
17
|
+
/**
|
|
18
|
+
* McpApp provides a high-performance MCP server
|
|
19
|
+
*
|
|
20
|
+
* Features:
|
|
21
|
+
* - Wraps official @modelcontextprotocol/sdk
|
|
22
|
+
* - Concurrency limiting (default: 10 max concurrent)
|
|
23
|
+
* - Multiple backpressure strategies (sleep/queue/reject)
|
|
24
|
+
* - Metrics for monitoring
|
|
25
|
+
* - Graceful shutdown
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const server = new McpApp({
|
|
30
|
+
* name: "my-server",
|
|
31
|
+
* version: "1.0.0",
|
|
32
|
+
* maxConcurrent: 5,
|
|
33
|
+
* backpressureStrategy: 'queue'
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* server.registerTools(myTools, myHandlers);
|
|
37
|
+
* await server.start();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class McpApp {
|
|
41
|
+
/**
|
|
42
|
+
* Server name — the identifier reported to MCP clients in `InitializeResult.serverInfo.name`.
|
|
43
|
+
*
|
|
44
|
+
* Exposed as a public readonly field (0.16.1) so consumers can use it for
|
|
45
|
+
* log prefixes, tracing context, or any UI that wants to echo the server
|
|
46
|
+
* identity without having to thread `options.name` through their code.
|
|
47
|
+
* Immutable after construction, same value that appears in the MCP
|
|
48
|
+
* `initialize` response.
|
|
49
|
+
*/
|
|
50
|
+
readonly name: string;
|
|
51
|
+
private requestQueue;
|
|
52
|
+
private rateLimiter;
|
|
53
|
+
private schemaValidator;
|
|
54
|
+
private tools;
|
|
55
|
+
/**
|
|
56
|
+
* Tool name → parameters the tool asked clients to mirror into
|
|
57
|
+
* `Mcp-Param-{Name}` headers (spec 2026-07-28, `x-mcp-header`).
|
|
58
|
+
*
|
|
59
|
+
* Populated at registration so the per-request path is a map lookup rather
|
|
60
|
+
* than a schema walk. Tools without annotations are simply absent.
|
|
61
|
+
*/
|
|
62
|
+
private mirroredParams;
|
|
63
|
+
/**
|
|
64
|
+
* Task store for the Tasks extension, or `null` when the consumer did not
|
|
65
|
+
* declare it.
|
|
66
|
+
*
|
|
67
|
+
* Created only on declaration: a server not using Tasks should not pay for a
|
|
68
|
+
* sweep timer, and a `tasks/*` call against it must read as the unimplemented
|
|
69
|
+
* method it is (404 + -32601) rather than hitting an empty store.
|
|
70
|
+
*/
|
|
71
|
+
private taskStore;
|
|
72
|
+
/**
|
|
73
|
+
* Set synchronously at the top of `stop()`.
|
|
74
|
+
*
|
|
75
|
+
* Checked before spawning a task, because the pipeline is async: a handler that
|
|
76
|
+
* settles during shutdown would otherwise start work in a store already drained,
|
|
77
|
+
* producing a task that outlives its server. A synchronous flag is what makes
|
|
78
|
+
* the check reliable — anything awaited leaves the same window open.
|
|
79
|
+
*/
|
|
80
|
+
private stopping;
|
|
81
|
+
/**
|
|
82
|
+
* Live `subscriptions/listen` streams.
|
|
83
|
+
*
|
|
84
|
+
* Initialized unconditionally in startHttp(); null before the server starts
|
|
85
|
+
* or in stdio mode.
|
|
86
|
+
*/
|
|
87
|
+
private subscriptions;
|
|
88
|
+
/** Era-aware stdio serving handle, present only while start() is active. */
|
|
89
|
+
private stdioHandle;
|
|
90
|
+
/** Protocol instance pinned by the stdio era negotiator, when connected. */
|
|
91
|
+
private activeStdioServer;
|
|
92
|
+
/**
|
|
93
|
+
* Imported HMAC key for sealing `requestState`, or `null` when the deployment
|
|
94
|
+
* configured none.
|
|
95
|
+
*
|
|
96
|
+
* Resolved lazily on first use rather than in the constructor, because
|
|
97
|
+
* `importStateKey` is async and a constructor cannot await.
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* In-flight or resolved key import.
|
|
101
|
+
*
|
|
102
|
+
* A Promise, not a value plus a loaded flag: the flag was set before the await,
|
|
103
|
+
* so a second request arriving during the import saw "loaded" with the key
|
|
104
|
+
* still null, received an UNSIGNED requestState, and could then submit raw
|
|
105
|
+
* inputResponses past the verification guard. Memoising the Promise makes every
|
|
106
|
+
* caller await the same import.
|
|
107
|
+
*/
|
|
108
|
+
private mrtrKeyPromise;
|
|
109
|
+
/**
|
|
110
|
+
* Consumes a verified requestState nonce before the handler runs.
|
|
111
|
+
*
|
|
112
|
+
* A signed deployment always has a store: process-local by default, or the
|
|
113
|
+
* shared atomic implementation supplied by the consumer.
|
|
114
|
+
*/
|
|
115
|
+
private readonly mrtrReplayStore;
|
|
116
|
+
/**
|
|
117
|
+
* Validated `ttlMs`. The spec requires servers to provide a value `>= 0`, and
|
|
118
|
+
* an integer — clients are told to ignore a negative one, which would make a
|
|
119
|
+
* misconfiguration silently do nothing instead of failing.
|
|
120
|
+
*
|
|
121
|
+
* Resolved once at construction: a per-response check would pay for the same
|
|
122
|
+
* validation on every list call, and a bad value is a deployment error that
|
|
123
|
+
* should surface at startup (AX: fast fail early).
|
|
124
|
+
*/
|
|
125
|
+
private readonly cacheTtlMs;
|
|
126
|
+
private resources;
|
|
127
|
+
private options;
|
|
128
|
+
private started;
|
|
129
|
+
private resourceHandlersInstalled;
|
|
130
|
+
private customMiddlewares;
|
|
131
|
+
private middlewareRunner;
|
|
132
|
+
private authProvider;
|
|
133
|
+
private serverMetrics;
|
|
134
|
+
constructor(options: McpAppOptions);
|
|
135
|
+
/** Build one unconnected SDK server for one negotiated stdio era. */
|
|
136
|
+
private createProtocolServer;
|
|
137
|
+
/**
|
|
138
|
+
* Pre-install the resources handlers on the low-level
|
|
139
|
+
* SDK Server. This declares the `resources` capability BEFORE transport
|
|
140
|
+
* connection, allowing dynamic resource registration after start().
|
|
141
|
+
*
|
|
142
|
+
* The handlers read from `this.resources` Map which is populated lazily
|
|
143
|
+
* by registerResource() calls (e.g., after async MCP discovery).
|
|
144
|
+
*/
|
|
145
|
+
private installResourceHandlers;
|
|
146
|
+
/** Install resource handlers on one fresh protocol instance. */
|
|
147
|
+
private installResourceHandlersOn;
|
|
148
|
+
/**
|
|
149
|
+
* Setup MCP protocol request handlers
|
|
150
|
+
*/
|
|
151
|
+
private setupHandlers;
|
|
152
|
+
/**
|
|
153
|
+
* The stateless HTTP `server/discover` result (spec 2026-07-28, SEP-2575).
|
|
154
|
+
*
|
|
155
|
+
* The stdio adapter deliberately does not call this builder: the official v2
|
|
156
|
+
* serving entry owns discover, era selection, result stamping and its final
|
|
157
|
+
* wire shape. Keeping this method HTTP-specific prevents a custom payload
|
|
158
|
+
* from bypassing that authority again.
|
|
159
|
+
*/
|
|
160
|
+
private buildDiscoverResult;
|
|
161
|
+
/**
|
|
162
|
+
* Register tools with their handlers
|
|
163
|
+
*
|
|
164
|
+
* @param tools - Array of tool definitions (MCP format)
|
|
165
|
+
* @param handlers - Map of tool name to handler function
|
|
166
|
+
*/
|
|
167
|
+
registerTools(tools: MCPTool[], handlers: Map<string, ToolHandler>): void;
|
|
168
|
+
/**
|
|
169
|
+
* Register a single tool
|
|
170
|
+
*
|
|
171
|
+
* @param tool - Tool definition
|
|
172
|
+
* @param handler - Tool handler function
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* Validate and index a tool's `x-mcp-header` annotations (spec 2026-07-28).
|
|
176
|
+
*
|
|
177
|
+
* Every registration path must go through here. Wiring it into `registerTools`
|
|
178
|
+
* alone was a real bypass: a tool registered via `registerTool` or
|
|
179
|
+
* `registerToolLive` carried annotations that clients would mirror into
|
|
180
|
+
* `Mcp-Param-*` headers, while the server never required or checked them.
|
|
181
|
+
*
|
|
182
|
+
* Throws *before* the caller inserts the tool, so a rejected definition cannot
|
|
183
|
+
* leave a half-registered tool behind.
|
|
184
|
+
*/
|
|
185
|
+
private collectToolMirroredParams;
|
|
186
|
+
/**
|
|
187
|
+
* Validate and atomically commit one tool definition.
|
|
188
|
+
*
|
|
189
|
+
* Schema compilation and mirrored-header validation happen before any public
|
|
190
|
+
* registry state changes. Re-registering an invalid live definition therefore
|
|
191
|
+
* leaves the previous handler, scopes, schema and header policy intact.
|
|
192
|
+
*/
|
|
193
|
+
private commitToolRegistration;
|
|
194
|
+
registerTool(tool: MCPTool, handler: ToolHandler): void;
|
|
195
|
+
/**
|
|
196
|
+
* Register a tool after the server has started (live registration).
|
|
197
|
+
*
|
|
198
|
+
* Unlike registerTool(), this can be called while the server is running.
|
|
199
|
+
* The tool becomes immediately available for tools/list and tools/call.
|
|
200
|
+
*
|
|
201
|
+
* Use case: relay proxy where tools are registered dynamically
|
|
202
|
+
* when remote owners connect/disconnect their tunnels.
|
|
203
|
+
*
|
|
204
|
+
* @param tool - Tool definition
|
|
205
|
+
* @param handler - Tool handler function
|
|
206
|
+
*/
|
|
207
|
+
registerToolLive(tool: MCPTool, handler: ToolHandler): void;
|
|
208
|
+
/**
|
|
209
|
+
* Register a tool that is only visible to the MCP App (UI layer),
|
|
210
|
+
* not to the model via tools/list.
|
|
211
|
+
*
|
|
212
|
+
* Equivalent to registerTool() with _meta.ui.visibility: ["app"].
|
|
213
|
+
* The tool is still callable via tools/call if the caller knows its name.
|
|
214
|
+
*
|
|
215
|
+
* @param tool - Tool definition
|
|
216
|
+
* @param handler - Tool handler function
|
|
217
|
+
*/
|
|
218
|
+
registerAppOnlyTool(tool: MCPTool, handler: ToolHandler): void;
|
|
219
|
+
/**
|
|
220
|
+
* Unregister a tool (removes it from tools/list and tools/call).
|
|
221
|
+
*
|
|
222
|
+
* Can be called before or after start.
|
|
223
|
+
* In-flight calls to this tool will complete normally.
|
|
224
|
+
*
|
|
225
|
+
* @param toolName - Name of the tool to remove
|
|
226
|
+
* @returns true if the tool was found and removed
|
|
227
|
+
*/
|
|
228
|
+
unregisterTool(toolName: string): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Add a custom middleware to the pipeline.
|
|
231
|
+
* Must be called before start()/startHttp().
|
|
232
|
+
*
|
|
233
|
+
* Custom middlewares execute between rate-limit and validation:
|
|
234
|
+
* rate-limit → **custom middlewares** → validation → backpressure → handler
|
|
235
|
+
*
|
|
236
|
+
* @param middleware - Middleware function
|
|
237
|
+
* @returns this (for chaining)
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* server.use(async (ctx, next) => {
|
|
242
|
+
* console.log(`Calling ${ctx.toolName}`);
|
|
243
|
+
* const result = await next();
|
|
244
|
+
* console.log(`Done ${ctx.toolName}`);
|
|
245
|
+
* return result;
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
use(middleware: Middleware): this;
|
|
250
|
+
/**
|
|
251
|
+
* Build the middleware pipeline from config + custom middlewares.
|
|
252
|
+
* Called once at start()/startHttp() time.
|
|
253
|
+
*
|
|
254
|
+
* Pipeline order:
|
|
255
|
+
* rate-limit → auth → custom middlewares → scope-check → validation → backpressure → handler
|
|
256
|
+
*/
|
|
257
|
+
private buildPipeline;
|
|
258
|
+
/**
|
|
259
|
+
* Execute a tool call through the middleware pipeline.
|
|
260
|
+
* Unified entry point for both STDIO and HTTP transports.
|
|
261
|
+
*
|
|
262
|
+
* @param toolName - Name of the tool to call
|
|
263
|
+
* @param args - Tool arguments
|
|
264
|
+
* @param request - HTTP request (undefined for STDIO)
|
|
265
|
+
* @param sessionId - HTTP session ID (undefined for STDIO)
|
|
266
|
+
* @returns Tool execution result
|
|
267
|
+
*/
|
|
268
|
+
private executeToolCall;
|
|
269
|
+
/**
|
|
270
|
+
* Apply CSP meta tag injection to HTML resource content (if configured).
|
|
271
|
+
* Only transforms text HTML content; blob responses pass through unchanged.
|
|
272
|
+
*/
|
|
273
|
+
private applyResourceCsp;
|
|
274
|
+
private isTextResourceContent;
|
|
275
|
+
/** Standard padded base64 with zero pad bits, without whitespace or URL-safe substitutions. */
|
|
276
|
+
private isCanonicalBase64;
|
|
277
|
+
/**
|
|
278
|
+
* Validate an untrusted handler result at the API boundary.
|
|
279
|
+
*
|
|
280
|
+
* TypeScript callers get the discriminated `ResourceContent` union at compile
|
|
281
|
+
* time. This check closes the equivalent JavaScript, `any`, and unchecked
|
|
282
|
+
* TypeScript paths before a malformed result reaches an MCP client.
|
|
283
|
+
*/
|
|
284
|
+
private validateResourceContent;
|
|
285
|
+
/** Run, validate, and CSP-harden a handler for a protocol response. */
|
|
286
|
+
private readResourceForProtocol;
|
|
287
|
+
/** Convert public metadata into the exact wire listing shape. */
|
|
288
|
+
private toResourceListing;
|
|
289
|
+
/** Fail early rather than publishing a metadata value clients must ignore. */
|
|
290
|
+
private validateResourceMetadata;
|
|
291
|
+
/**
|
|
292
|
+
* Resources are keyed by their wire URI, so accepting a spelling which URL
|
|
293
|
+
* canonicalisation changes would make list/read/handler identity ambiguous.
|
|
294
|
+
* Refuse it at registration instead of silently normalising a caller-owned
|
|
295
|
+
* identifier. Non-`ui:` schemes are valid MCP resources and remain allowed.
|
|
296
|
+
*/
|
|
297
|
+
private validateResourceUri;
|
|
298
|
+
/** A consumer logger is observability, never a resource-commit dependency. */
|
|
299
|
+
private resourceLog;
|
|
300
|
+
/**
|
|
301
|
+
* Publish the one post-commit list-changed projection for a mutation.
|
|
302
|
+
* It is best-effort by design: registry state is authoritative and callers
|
|
303
|
+
* must not receive a false failure after it changes.
|
|
304
|
+
*/
|
|
305
|
+
private notifyResourceListChanged;
|
|
306
|
+
/**
|
|
307
|
+
* Register a single resource
|
|
308
|
+
*
|
|
309
|
+
* @param resource - Resource definition with uri, name, description
|
|
310
|
+
* @param handler - Callback that returns ResourceContent when resource is read
|
|
311
|
+
* @throws Error if resource with same URI already registered
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* server.registerResource(
|
|
316
|
+
* { uri: "ui://my-server/viewer", name: "Viewer", description: "Data viewer" },
|
|
317
|
+
* async (uri) => ({
|
|
318
|
+
* uri: uri.toString(),
|
|
319
|
+
* mimeType: MCP_APP_MIME_TYPE,
|
|
320
|
+
* text: "<html>...</html>"
|
|
321
|
+
* })
|
|
322
|
+
* );
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
registerResource(resource: MCPResource, handler: ResourceHandler): void;
|
|
326
|
+
/**
|
|
327
|
+
* Remove a resource from this server.
|
|
328
|
+
*
|
|
329
|
+
* It is safe before or after either transport starts once resources are
|
|
330
|
+
* installed. Returns `false` when no such URI is present, so callers can make
|
|
331
|
+
* idempotent cleanup calls without catching an error.
|
|
332
|
+
*/
|
|
333
|
+
unregisterResource(uri: string): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Register multiple resources
|
|
336
|
+
*
|
|
337
|
+
* @param resources - Array of resource definitions
|
|
338
|
+
* @param handlers - Map of URI to handler function
|
|
339
|
+
* @throws Error if any resource is missing a handler (fail-fast)
|
|
340
|
+
*/
|
|
341
|
+
registerResources(resources: MCPResource[], handlers: Map<string, ResourceHandler>): void;
|
|
342
|
+
/**
|
|
343
|
+
* Register MCP Apps viewers with automatic dist path resolution.
|
|
344
|
+
*
|
|
345
|
+
* Replaces the manual pattern of: enumerate viewers → resolve paths → register resources.
|
|
346
|
+
* Each viewer gets a `ui://{prefix}/{viewerName}` resource URI.
|
|
347
|
+
*
|
|
348
|
+
* Viewers whose dist is not found are skipped with a warning (not an error),
|
|
349
|
+
* so that the server can start in dev without building UIs first.
|
|
350
|
+
*
|
|
351
|
+
* @returns Summary of registered and skipped viewers
|
|
352
|
+
*/
|
|
353
|
+
registerViewers(config: RegisterViewersConfig): RegisterViewersSummary;
|
|
354
|
+
/**
|
|
355
|
+
* Start the MCP server with stdio transport
|
|
356
|
+
*/
|
|
357
|
+
start(): Promise<void>;
|
|
358
|
+
/**
|
|
359
|
+
* Restore the invariants a running server relies on.
|
|
360
|
+
*
|
|
361
|
+
* Called by both transports' start paths. `stop()` disposes the task store and
|
|
362
|
+
* leaves it disposed — rebuilding it mid-teardown is what let an in-flight call
|
|
363
|
+
* spawn into a store nobody would drain — so coming back up is where a live one
|
|
364
|
+
* is created.
|
|
365
|
+
*/
|
|
366
|
+
private prepareForStart;
|
|
367
|
+
stop(): Promise<void>;
|
|
368
|
+
private httpServer;
|
|
369
|
+
/**
|
|
370
|
+
* Start the MCP server with HTTP transport (Streamable HTTP compatible)
|
|
371
|
+
*
|
|
372
|
+
* This creates an HTTP server that handles MCP JSON-RPC requests.
|
|
373
|
+
* Supports tools/list, tools/call, resources/list, resources/read.
|
|
374
|
+
*
|
|
375
|
+
* @param options - HTTP server options
|
|
376
|
+
* @returns Server instance with shutdown method
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const server = new McpApp({ name: "my-server", version: "1.0.0" });
|
|
381
|
+
* server.registerTools(tools, handlers);
|
|
382
|
+
* server.registerResource(resource, handler);
|
|
383
|
+
*
|
|
384
|
+
* const http = await server.startHttp({ port: 3000 });
|
|
385
|
+
* // Server running on http://localhost:3000
|
|
386
|
+
*
|
|
387
|
+
* // Later: await http.shutdown();
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
startHttp(options: HttpServerOptions): Promise<{
|
|
391
|
+
shutdown: () => Promise<void>;
|
|
392
|
+
addr: {
|
|
393
|
+
hostname: string;
|
|
394
|
+
port: number;
|
|
395
|
+
};
|
|
396
|
+
}>;
|
|
397
|
+
/**
|
|
398
|
+
* Build the HTTP middleware stack and return its fetch handler without
|
|
399
|
+
* binding a port. Use this when you want to mount the MCP HTTP layer
|
|
400
|
+
* inside another HTTP framework on Deno (Fresh, Hono, `Deno.serve`) or
|
|
401
|
+
* Node (Express, Hono-on-Node) instead of giving up port ownership to
|
|
402
|
+
* {@link startHttp}.
|
|
403
|
+
*
|
|
404
|
+
* **Runtime targets:** `@casys/mcp-server` is Deno-first — the canonical
|
|
405
|
+
* deployment path is Deno 2.x on Deno Deploy or self-hosted Deno, with
|
|
406
|
+
* a Node 20+ distribution via `scripts/build-node.sh` as a secondary
|
|
407
|
+
* target. Cloudflare Workers, workerd, and browser runtimes are not
|
|
408
|
+
* supported — if you target those, use
|
|
409
|
+
* [`@modelcontextprotocol/server`](https://www.npmjs.com/package/@modelcontextprotocol/server)
|
|
410
|
+
* directly instead.
|
|
411
|
+
*
|
|
412
|
+
* The returned handler accepts a Web Standard {@link Request} and returns
|
|
413
|
+
* a Web Standard {@link Response}. It exposes the same routes as
|
|
414
|
+
* {@link startHttp}: `POST /mcp`, `GET /health`, `GET /metrics`, and
|
|
415
|
+
* `GET /.well-known/oauth-protected-resource`. `GET /mcp` returns 405.
|
|
416
|
+
*
|
|
417
|
+
* Auth, multi-tenant middleware, scope checks, and rate limiting are all
|
|
418
|
+
* applied identically. OTel hooks are started, so the server is fully
|
|
419
|
+
* live after this returns — just without its own listening socket.
|
|
420
|
+
*
|
|
421
|
+
* Multi-tenant SaaS pattern: cache one `McpApp` per tenant
|
|
422
|
+
* and call `getFetchHandler()` once per server, then dispatch each
|
|
423
|
+
* inbound request to the right cached handler from your framework's
|
|
424
|
+
* routing layer.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* // In a Fresh route at routes/mcp/[...path].tsx
|
|
429
|
+
* const server = new McpApp({ name: "my-mcp", version: "1.0.0" });
|
|
430
|
+
* server.registerTools(tools, handlers);
|
|
431
|
+
* const handler = await server.getFetchHandler({
|
|
432
|
+
* requireAuth: true,
|
|
433
|
+
* auth: { provider: myAuthProvider },
|
|
434
|
+
* });
|
|
435
|
+
* // Later, in your route handler:
|
|
436
|
+
* return await handler(ctx.req);
|
|
437
|
+
* ```
|
|
438
|
+
*
|
|
439
|
+
* @param options - Same as {@link startHttp}, minus `port`/`hostname`/`onListen`.
|
|
440
|
+
* @returns A Web Standard fetch handler.
|
|
441
|
+
*/
|
|
442
|
+
getFetchHandler(options?: Omit<HttpServerOptions, "port" | "hostname" | "onListen">): Promise<FetchHandler>;
|
|
443
|
+
/**
|
|
444
|
+
* Read the MCP Apps capability advertised by the connected client.
|
|
445
|
+
*
|
|
446
|
+
* Returns the capability object (possibly empty `{}`) when the client
|
|
447
|
+
* advertised support for MCP Apps via its `extensions` capability,
|
|
448
|
+
* or `undefined` when:
|
|
449
|
+
* - the client did not send capabilities yet (called before initialize)
|
|
450
|
+
* - the client did not advertise the MCP Apps extension at all
|
|
451
|
+
* - the client sent a malformed extension value
|
|
452
|
+
*
|
|
453
|
+
* Use this from a tool handler to decide whether to return a UI
|
|
454
|
+
* resource (`_meta.ui`) or a text-only fallback. Hosts that don't
|
|
455
|
+
* support MCP Apps will silently drop the `_meta.ui` field, but
|
|
456
|
+
* checking explicitly lets you serve a richer text response when
|
|
457
|
+
* the UI path isn't available.
|
|
458
|
+
*
|
|
459
|
+
* @returns MCP Apps capability or `undefined` if not supported.
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* const cap = app.getClientMcpAppsCapability();
|
|
464
|
+
* if (cap?.mimeTypes?.includes(MCP_APP_MIME_TYPE)) {
|
|
465
|
+
* return {
|
|
466
|
+
* content: [{ type: "text", text: summary }],
|
|
467
|
+
* _meta: { ui: { resourceUri: "ui://my-app/dashboard" } },
|
|
468
|
+
* };
|
|
469
|
+
* }
|
|
470
|
+
* return { content: [{ type: "text", text: detailedTextFallback }] };
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* @see {@link getMcpAppsCapability} for the standalone reader
|
|
474
|
+
* @see {@link MCP_APPS_EXTENSION_ID} for the extension key
|
|
475
|
+
*/
|
|
476
|
+
getClientMcpAppsCapability(): McpAppsClientCapability | undefined;
|
|
477
|
+
/**
|
|
478
|
+
* Get queue metrics for monitoring
|
|
479
|
+
*/
|
|
480
|
+
getMetrics(): QueueMetrics;
|
|
481
|
+
/**
|
|
482
|
+
* Get full server metrics (counters, histograms, gauges)
|
|
483
|
+
*/
|
|
484
|
+
getServerMetrics(): import("./observability/metrics.js").ServerMetricsSnapshot;
|
|
485
|
+
/**
|
|
486
|
+
* Get Prometheus text format metrics
|
|
487
|
+
*/
|
|
488
|
+
getPrometheusMetrics(): string;
|
|
489
|
+
/**
|
|
490
|
+
* Get rate limiter metrics (if rate limiting is enabled)
|
|
491
|
+
*/
|
|
492
|
+
getRateLimitMetrics(): {
|
|
493
|
+
keys: number;
|
|
494
|
+
totalRequests: number;
|
|
495
|
+
} | null;
|
|
496
|
+
/**
|
|
497
|
+
* Get rate limiter instance (for advanced use cases)
|
|
498
|
+
*/
|
|
499
|
+
getRateLimiter(): RateLimiter | null;
|
|
500
|
+
/**
|
|
501
|
+
* Get schema validator instance (for advanced use cases)
|
|
502
|
+
*/
|
|
503
|
+
getSchemaValidator(): SchemaValidator | null;
|
|
504
|
+
/**
|
|
505
|
+
* Check if server is started
|
|
506
|
+
*/
|
|
507
|
+
isStarted(): boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Get number of registered tools
|
|
510
|
+
*/
|
|
511
|
+
getToolCount(): number;
|
|
512
|
+
/**
|
|
513
|
+
* Get tool names
|
|
514
|
+
*/
|
|
515
|
+
getToolNames(): string[];
|
|
516
|
+
/**
|
|
517
|
+
* Get number of registered resources
|
|
518
|
+
*/
|
|
519
|
+
getResourceCount(): number;
|
|
520
|
+
/**
|
|
521
|
+
* Get registered resource URIs
|
|
522
|
+
*/
|
|
523
|
+
getResourceUris(): string[];
|
|
524
|
+
/**
|
|
525
|
+
* Check if a resource is registered
|
|
526
|
+
*/
|
|
527
|
+
hasResource(uri: string): boolean;
|
|
528
|
+
/**
|
|
529
|
+
* Get resource info by URI (for testing/debugging)
|
|
530
|
+
*/
|
|
531
|
+
getResourceInfo(uri: string): MCPResource | undefined;
|
|
532
|
+
/**
|
|
533
|
+
* Read resource content by URI.
|
|
534
|
+
* Invokes the registered handler directly (no MCP protocol round-trip).
|
|
535
|
+
* Returns null if the resource is not registered.
|
|
536
|
+
*/
|
|
537
|
+
readResourceContent(uri: string): Promise<ResourceContent | null>;
|
|
538
|
+
/**
|
|
539
|
+
* Send a JSON-RPC notification to the connected transport.
|
|
540
|
+
*
|
|
541
|
+
* Routing depends on the transport:
|
|
542
|
+
* - **HTTP**: fanned out to `subscriptions/listen` streams, only to
|
|
543
|
+
* subscribers that opted into that notification type.
|
|
544
|
+
* - **stdio**: written to stdout via the SDK transport.
|
|
545
|
+
*
|
|
546
|
+
* @param method - Notification method (e.g. "notifications/tools/list_changed")
|
|
547
|
+
* @param params - Notification parameters
|
|
548
|
+
*/
|
|
549
|
+
sendNotification(method: string, params?: Record<string, unknown>): void;
|
|
550
|
+
/**
|
|
551
|
+
* Register a callback for the "initialized" notification.
|
|
552
|
+
* Called after client sends "initialized" (post-handshake).
|
|
553
|
+
*/
|
|
554
|
+
onInitialized(callback: () => void): void;
|
|
555
|
+
private initializedCallback;
|
|
556
|
+
/**
|
|
557
|
+
* Check if a handler result is a pre-formatted MCP result.
|
|
558
|
+
* Pre-formatted results have a `content` array and are passed through
|
|
559
|
+
* without re-wrapping. This supports proxy/gateway patterns.
|
|
560
|
+
*/
|
|
561
|
+
private isPreformattedResult;
|
|
562
|
+
/**
|
|
563
|
+
* Apply the spec-2026-07-28 result envelope when — and only when — the peer
|
|
564
|
+
* negotiated that revision.
|
|
565
|
+
*
|
|
566
|
+
* This helper applies on the custom stateless HTTP transport, which only
|
|
567
|
+
* accepts 2026-07-28. Stdio results are neutral here: the official v2 codec
|
|
568
|
+
* stamps modern responses and leaves a negotiated legacy connection clean.
|
|
569
|
+
*
|
|
570
|
+
* Omitting the envelope for a genuinely legacy peer is safe in the other
|
|
571
|
+
* direction too: the spec instructs clients to read a missing `resultType` as
|
|
572
|
+
* `"complete"`.
|
|
573
|
+
*
|
|
574
|
+
* Every HTTP result path funnels through here. Adding a new one without it is
|
|
575
|
+
* the failure mode to watch for — hence the conformance test that walks the
|
|
576
|
+
* method table rather than asserting one endpoint at a time.
|
|
577
|
+
*
|
|
578
|
+
* @param negotiatedVersion Version from the request's `_meta`, or `undefined`
|
|
579
|
+
* where no per-request negotiation happens.
|
|
580
|
+
*/
|
|
581
|
+
private stampResult;
|
|
582
|
+
/**
|
|
583
|
+
* Validate one MRTR retry delivered through the v2 protocol server.
|
|
584
|
+
*
|
|
585
|
+
* The SDK owns era-specific lifting and legacy fulfilment; Casys owns the
|
|
586
|
+
* integrity bindings and nonce consumption of its sealed requestState.
|
|
587
|
+
* Protocol errors deliberately escape the tool-error wrapper so clients see
|
|
588
|
+
* a JSON-RPC error instead of a successful tools/call result with isError.
|
|
589
|
+
*/
|
|
590
|
+
private prepareProtocolMrtrRetry;
|
|
591
|
+
/**
|
|
592
|
+
* Resolve the MRTR signing key once, warning if a deployment has none.
|
|
593
|
+
*
|
|
594
|
+
* A missing key is not an error: the spec permits unprotected `requestState`
|
|
595
|
+
* when tampering can cause nothing worse than the request failing. It is a
|
|
596
|
+
* loud warning because that condition is easy to believe and hard to verify.
|
|
597
|
+
*/
|
|
598
|
+
/**
|
|
599
|
+
* Key lookup that reports failure instead of throwing.
|
|
600
|
+
*
|
|
601
|
+
* The `tools/call` call sites sit outside the tool try/catch, so a throw would
|
|
602
|
+
* reach the POST-level catch and surface as -32700 "Parse error" — the same trap
|
|
603
|
+
* the earlier throwing principal guard fell into. Returns a ready response
|
|
604
|
+
* instead.
|
|
605
|
+
*/
|
|
606
|
+
private getMrtrKeySafe;
|
|
607
|
+
private getMrtrKey;
|
|
608
|
+
/**
|
|
609
|
+
* Turn a handler's `InputRequiredSignal` into the wire result.
|
|
610
|
+
*
|
|
611
|
+
* Validates what the spec puts on the server rather than the client:
|
|
612
|
+
* - at least one of `inputRequests` / `requestState` must be present;
|
|
613
|
+
* - no input request may name a capability the client did not declare.
|
|
614
|
+
*
|
|
615
|
+
* A violation is the server author's bug, so it surfaces as `-32603` rather
|
|
616
|
+
* than being emitted as an invalid MRTR result for the client to puzzle over.
|
|
617
|
+
*/
|
|
618
|
+
private buildInputRequiredResult;
|
|
619
|
+
/**
|
|
620
|
+
* Reject a Tasks request from a client that did not declare the extension.
|
|
621
|
+
*
|
|
622
|
+
* Returns a ready 400 response to return, or `null` when the client is
|
|
623
|
+
* entitled to proceed. Two distinct spec rules converge here: a server
|
|
624
|
+
* **MUST NOT** hand a task to a non-declaring client, and **MUST** answer the
|
|
625
|
+
* missing-capability error when one calls `tasks/*`.
|
|
626
|
+
*
|
|
627
|
+
* `-32021` (`MissingRequiredClientCapability`) is the code, and
|
|
628
|
+
* `data.requiredCapabilities` is required to list what was missing — a client
|
|
629
|
+
* that gets this back needs to know which capability to add, not just that
|
|
630
|
+
* something was absent.
|
|
631
|
+
*/
|
|
632
|
+
private requireTasksCapability;
|
|
633
|
+
/**
|
|
634
|
+
* Task status transitions, for pushing to subscribers.
|
|
635
|
+
*
|
|
636
|
+
* The spec's notification method is `notifications/tasks` — not a
|
|
637
|
+
* `tasks/`-prefixed name, which would collide with the request methods.
|
|
638
|
+
*
|
|
639
|
+
* Delivery goes out over `subscriptions/listen` once that route is wired
|
|
640
|
+
* (Track G); the registry exists but the transport does not yet open streams.
|
|
641
|
+
* Until then this is intentionally a no-op beyond the log: polling via
|
|
642
|
+
* `tasks/get` is the spec's default and works without it.
|
|
643
|
+
*/
|
|
644
|
+
private onTaskChanged;
|
|
645
|
+
/**
|
|
646
|
+
* Add the required `CacheableResult` fields (spec 2026-07-28, SEP-2549).
|
|
647
|
+
*
|
|
648
|
+
* Applies to `tools/list`, `prompts/list`, `resources/list`, `resources/read`
|
|
649
|
+
* and `resources/templates/list`, where the final spec makes both fields
|
|
650
|
+
* required rather than optional. Same version gate as {@link stampResult}:
|
|
651
|
+
* neither field exists in an earlier revision.
|
|
652
|
+
*
|
|
653
|
+
* Both are hints — a client that ignores them stays correct, it just polls
|
|
654
|
+
* more often.
|
|
655
|
+
*/
|
|
656
|
+
private withCacheHints;
|
|
657
|
+
/**
|
|
658
|
+
* Capabilities advertised on `server/discover` and `initialize`.
|
|
659
|
+
*
|
|
660
|
+
* Single source of truth: these two responses used to build the same object
|
|
661
|
+
* independently, which is how they drift.
|
|
662
|
+
*
|
|
663
|
+
* `extensions` (spec 2026-07-28) is the declaration point for opt-in
|
|
664
|
+
* extensions such as `io.modelcontextprotocol/tasks`. It is emitted only when
|
|
665
|
+
* the consumer actually declares one — an empty `extensions: {}` would read as
|
|
666
|
+
* "this server supports no extensions", which is a stronger claim than we can
|
|
667
|
+
* make while MCP Apps support is de-facto (via `ui://` resources) rather than
|
|
668
|
+
* declared. Wire it up here once the Apps extension identifier is pinned.
|
|
669
|
+
*/
|
|
670
|
+
private buildServerCapabilities;
|
|
671
|
+
/**
|
|
672
|
+
* Build the tools/list response, filtering out app-only tools
|
|
673
|
+
* and passing through outputSchema/annotations when defined.
|
|
674
|
+
*/
|
|
675
|
+
private buildToolListing;
|
|
676
|
+
/**
|
|
677
|
+
* Check if a handler result is a StructuredToolResult
|
|
678
|
+
* (has content as string + structuredContent as object).
|
|
679
|
+
*/
|
|
680
|
+
private isStructuredToolResult;
|
|
681
|
+
/**
|
|
682
|
+
* Build a CallToolResult from the handler's return value.
|
|
683
|
+
* Priority: preformatted > structuredToolResult > plain value.
|
|
684
|
+
*/
|
|
685
|
+
private buildToolCallResult;
|
|
686
|
+
/**
|
|
687
|
+
* Handle a tool execution error using the configured toolErrorMapper.
|
|
688
|
+
* Returns an isError result if the mapper handles it, otherwise rethrows.
|
|
689
|
+
*/
|
|
690
|
+
private handleToolError;
|
|
691
|
+
/**
|
|
692
|
+
* Log message using custom logger or stderr
|
|
693
|
+
*/
|
|
694
|
+
private log;
|
|
695
|
+
}
|
|
696
|
+
/** Configuration for registerViewers() */
|
|
697
|
+
export interface RegisterViewersConfig {
|
|
698
|
+
/** URI prefix — viewers get `ui://{prefix}/{viewerName}` */
|
|
699
|
+
prefix: string;
|
|
700
|
+
/** import.meta.url of the consumer's server.ts (for resolving dist paths) */
|
|
701
|
+
moduleUrl: string;
|
|
702
|
+
/** Check if a path or URL exists. Receives a filesystem path for local
|
|
703
|
+
* modules (file://) or an HTTPS URL for remote modules (JSR, CDN). */
|
|
704
|
+
exists: (path: string) => boolean;
|
|
705
|
+
/** Read a file and return its content as string */
|
|
706
|
+
readFile: (path: string) => string | Promise<string>;
|
|
707
|
+
/** Explicit list of viewer names. If omitted, use `discover`. */
|
|
708
|
+
viewers?: string[];
|
|
709
|
+
/** Auto-discover viewers by scanning a directory */
|
|
710
|
+
discover?: {
|
|
711
|
+
uiDir: string;
|
|
712
|
+
} & DiscoverViewersFS;
|
|
713
|
+
/** Custom function to generate human-readable names. Default: kebab-to-Title. */
|
|
714
|
+
humanName?: (viewerName: string) => string;
|
|
715
|
+
/** MCP Apps CSP — declares external domains the viewer needs (tiles, APIs, CDNs).
|
|
716
|
+
* Uses McpUiCsp from @casys/mcp-compose (resourceDomains, connectDomains). */
|
|
717
|
+
csp?: {
|
|
718
|
+
resourceDomains?: string[];
|
|
719
|
+
connectDomains?: string[];
|
|
720
|
+
frameDomains?: string[];
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
/** Summary returned by registerViewers() */
|
|
724
|
+
export interface RegisterViewersSummary {
|
|
725
|
+
registered: string[];
|
|
726
|
+
skipped: string[];
|
|
727
|
+
}
|
|
728
|
+
//# sourceMappingURL=mcp-app.d.ts.map
|