skybridge 0.0.0-dev.f8da531 → 0.0.0-dev.f8ef758
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/README.md +123 -124
- package/dist/cli/build-helpers.d.ts +7 -0
- package/dist/cli/build-helpers.js +82 -0
- package/dist/cli/build-helpers.js.map +1 -0
- package/dist/cli/build-helpers.test.d.ts +1 -0
- package/dist/cli/build-helpers.test.js +64 -0
- package/dist/cli/build-helpers.test.js.map +1 -0
- package/dist/cli/detect-port.d.ts +2 -2
- package/dist/cli/detect-port.js +9 -20
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/resolve-views-dir.d.ts +1 -0
- package/dist/cli/resolve-views-dir.js +17 -0
- package/dist/cli/resolve-views-dir.js.map +1 -0
- package/dist/cli/run-command.js.map +1 -1
- package/dist/cli/telemetry.js.map +1 -1
- package/dist/cli/tunnel-control-server.js.map +1 -1
- package/dist/cli/tunnel-control-server.test.js.map +1 -1
- package/dist/cli/tunnel-handler.js.map +1 -1
- package/dist/cli/tunnel-handler.test.js.map +1 -1
- package/dist/cli/tunnel.js +2 -2
- package/dist/cli/tunnel.js.map +1 -1
- package/dist/cli/tunnel.test.js.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/use-execute-steps.js.map +1 -1
- package/dist/cli/use-messages.js.map +1 -1
- package/dist/cli/use-nodemon.js +11 -2
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-open-browser.d.ts +1 -0
- package/dist/cli/use-open-browser.js +44 -0
- package/dist/cli/use-open-browser.js.map +1 -0
- package/dist/cli/use-tunnel.js.map +1 -1
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +41 -18
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts +9 -0
- package/dist/commands/create.js +30 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +23 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +7 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
- package/dist/server/asset-base-url-transform-plugin.js +16 -1
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/auth/discovery.d.ts +11 -0
- package/dist/server/auth/discovery.js +51 -0
- package/dist/server/auth/discovery.js.map +1 -0
- package/dist/server/auth/discovery.test.d.ts +1 -0
- package/dist/server/auth/discovery.test.js +93 -0
- package/dist/server/auth/discovery.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +18 -0
- package/dist/server/auth/index.js +2 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/providers/auth0.d.ts +13 -0
- package/dist/server/auth/providers/auth0.js +18 -0
- package/dist/server/auth/providers/auth0.js.map +1 -0
- package/dist/server/auth/providers/auth0.test.d.ts +1 -0
- package/dist/server/auth/providers/auth0.test.js +33 -0
- package/dist/server/auth/providers/auth0.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +14 -0
- package/dist/server/auth/providers/clerk.js +20 -0
- package/dist/server/auth/providers/clerk.js.map +1 -0
- package/dist/server/auth/providers/clerk.test.d.ts +1 -0
- package/dist/server/auth/providers/clerk.test.js +48 -0
- package/dist/server/auth/providers/clerk.test.js.map +1 -0
- package/dist/server/auth/providers/custom.d.ts +17 -0
- package/dist/server/auth/providers/custom.js +28 -0
- package/dist/server/auth/providers/custom.js.map +1 -0
- package/dist/server/auth/providers/custom.test.d.ts +1 -0
- package/dist/server/auth/providers/custom.test.js +91 -0
- package/dist/server/auth/providers/custom.test.js.map +1 -0
- package/dist/server/auth/providers/descope.d.ts +14 -0
- package/dist/server/auth/providers/descope.js +14 -0
- package/dist/server/auth/providers/descope.js.map +1 -0
- package/dist/server/auth/providers/descope.test.d.ts +1 -0
- package/dist/server/auth/providers/descope.test.js +35 -0
- package/dist/server/auth/providers/descope.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +12 -0
- package/dist/server/auth/providers/stytch.js +17 -0
- package/dist/server/auth/providers/stytch.js.map +1 -0
- package/dist/server/auth/providers/stytch.test.d.ts +1 -0
- package/dist/server/auth/providers/stytch.test.js +33 -0
- package/dist/server/auth/providers/stytch.test.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +11 -0
- package/dist/server/auth/providers/workos.js +16 -0
- package/dist/server/auth/providers/workos.js.map +1 -0
- package/dist/server/auth/providers/workos.test.d.ts +1 -0
- package/dist/server/auth/providers/workos.test.js +41 -0
- package/dist/server/auth/providers/workos.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +4 -0
- package/dist/server/auth/setup.js +51 -0
- package/dist/server/auth/setup.js.map +1 -0
- package/dist/server/auth/setup.test.d.ts +1 -0
- package/dist/server/auth/setup.test.js +185 -0
- package/dist/server/auth/setup.test.js.map +1 -0
- package/dist/server/auth/verify.d.ts +12 -0
- package/dist/server/auth/verify.js +38 -0
- package/dist/server/auth/verify.js.map +1 -0
- package/dist/server/auth/verify.test.d.ts +1 -0
- package/dist/server/auth/verify.test.js +100 -0
- package/dist/server/auth/verify.test.js.map +1 -0
- package/dist/server/auth.d.ts +20 -0
- package/dist/server/auth.js +28 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/build-manifest.test.d.ts +1 -0
- package/dist/server/build-manifest.test.js +27 -0
- package/dist/server/build-manifest.test.js.map +1 -0
- package/dist/server/content-helpers.d.ts +40 -0
- package/dist/server/content-helpers.js +33 -0
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/content-helpers.test.js.map +1 -1
- package/dist/server/express.d.ts +1 -5
- package/dist/server/express.js +13 -7
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +214 -71
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +28 -0
- package/dist/server/file-ref.js +27 -0
- package/dist/server/file-ref.js.map +1 -0
- package/dist/server/index.d.ts +11 -2
- package/dist/server/index.js +9 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/inferUtilityTypes.js.map +1 -1
- package/dist/server/metric.js.map +1 -1
- package/dist/server/middleware.d.ts +16 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/requestOrigin.d.ts +7 -0
- package/dist/server/requestOrigin.js +25 -0
- package/dist/server/requestOrigin.js.map +1 -0
- package/dist/server/server.d.ts +237 -7
- package/dist/server/server.js +278 -73
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +0 -2
- package/dist/server/templateHelper.js +3 -22
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.d.ts +4 -0
- package/dist/server/templates.generated.js +47 -0
- package/dist/server/templates.generated.js.map +1 -0
- package/dist/server/tunnel-proxy-router.js.map +1 -1
- package/dist/server/tunnel-proxy-router.test.js.map +1 -1
- package/dist/server/view-resource-resolution.test.d.ts +6 -0
- package/dist/server/view-resource-resolution.test.js +88 -0
- package/dist/server/view-resource-resolution.test.js.map +1 -0
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +45 -0
- package/dist/test/view.test.js.map +1 -1
- package/dist/version.js +1 -3
- package/dist/version.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +7 -2
- package/dist/web/bridges/apps-sdk/adaptor.js +27 -3
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js +1 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +8 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +7 -0
- package/dist/web/bridges/get-adaptor.js +7 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +7 -2
- package/dist/web/bridges/mcp-app/adaptor.js +21 -6
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +4 -2
- package/dist/web/bridges/mcp-app/bridge.js +23 -1
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js +144 -0
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +98 -3
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/use-host-context.d.ts +5 -0
- package/dist/web/bridges/use-host-context.js +5 -0
- package/dist/web/bridges/use-host-context.js.map +1 -1
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.d.ts +26 -0
- package/dist/web/create-store.js +26 -0
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +33 -0
- package/dist/web/data-llm.js +28 -0
- package/dist/web/data-llm.js.map +1 -1
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +2 -0
- package/dist/web/generate-helpers.js +2 -0
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +4 -2
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/helpers/state.js.map +1 -1
- package/dist/web/helpers/state.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +4 -0
- package/dist/web/hooks/index.js +4 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +6 -2
- package/dist/web/hooks/test/utils.js +13 -2
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.d.ts +45 -0
- package/dist/web/hooks/use-call-tool.js +28 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +27 -6
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +20 -0
- package/dist/web/hooks/use-display-mode.js +20 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +5 -0
- package/dist/web/hooks/use-download.js +8 -0
- package/dist/web/hooks/use-download.js.map +1 -0
- package/dist/web/hooks/use-download.test.d.ts +1 -0
- package/dist/web/hooks/use-download.test.js +95 -0
- package/dist/web/hooks/use-download.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +32 -0
- package/dist/web/hooks/use-files.js +32 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.d.ts +2 -0
- package/dist/web/hooks/use-layout.js +2 -0
- package/dist/web/hooks/use-layout.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +17 -0
- package/dist/web/hooks/use-open-external.js +16 -0
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +38 -0
- package/dist/web/hooks/use-register-view-tool.js +50 -0
- package/dist/web/hooks/use-register-view-tool.js.map +1 -0
- package/dist/web/hooks/use-request-close.d.ts +16 -0
- package/dist/web/hooks/use-request-close.js +21 -0
- package/dist/web/hooks/use-request-close.js.map +1 -0
- package/dist/web/hooks/use-request-close.test.d.ts +1 -0
- package/dist/web/hooks/use-request-close.test.js +52 -0
- package/dist/web/hooks/use-request-close.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +16 -1
- package/dist/web/hooks/use-request-modal.js +16 -1
- package/dist/web/hooks/use-request-modal.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +20 -0
- package/dist/web/hooks/use-request-size.js +24 -0
- package/dist/web/hooks/use-request-size.js.map +1 -0
- package/dist/web/hooks/use-request-size.test.d.ts +1 -0
- package/dist/web/hooks/use-request-size.test.js +65 -0
- package/dist/web/hooks/use-request-size.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +19 -1
- package/dist/web/hooks/use-send-follow-up-message.js +19 -2
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +53 -2
- package/dist/web/hooks/use-tool-info.js +30 -7
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +11 -29
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +5 -5
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +2 -0
- package/dist/web/hooks/use-user.js +2 -0
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.d.ts +21 -0
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +19 -0
- package/dist/web/mount-view.js +19 -0
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/data-llm.test.js.map +1 -1
- package/dist/web/plugin/plugin.d.ts +28 -0
- package/dist/web/plugin/plugin.js +35 -9
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/scan-views.js.map +1 -1
- package/dist/web/plugin/scan-views.test.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
- package/dist/web/plugin/validate-view.js.map +1 -1
- package/dist/web/plugin/validate-view.test.js.map +1 -1
- package/dist/web/proxy.js.map +1 -1
- package/dist/web/types.d.ts +4 -0
- package/dist/web/types.js.map +1 -1
- package/package.json +28 -18
- package/dist/server/templates/development.hbs +0 -12
- package/dist/server/templates/production.hbs +0 -6
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
import type { AudioContent, EmbeddedResource, ImageContent, ResourceLink, TextContent } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* MCP content annotations applied to any returned block.
|
|
4
|
+
*
|
|
5
|
+
* - `audience` — who is meant to see the content (`"user"`, `"assistant"`, or both).
|
|
6
|
+
* - `priority` — relative importance hint for the host.
|
|
7
|
+
* - `lastModified` — ISO timestamp for when the content was produced.
|
|
8
|
+
*/
|
|
2
9
|
type ContentAnnotations = {
|
|
3
10
|
audience?: ("user" | "assistant")[];
|
|
4
11
|
priority?: number;
|
|
5
12
|
lastModified?: string;
|
|
6
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Build an MCP text content block.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* return { content: [text("Found 3 results.")] };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
7
22
|
export declare function text(value: string, annotations?: ContentAnnotations): TextContent;
|
|
23
|
+
/**
|
|
24
|
+
* Build an MCP image content block.
|
|
25
|
+
*
|
|
26
|
+
* `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
|
|
27
|
+
* **already base64-encoded**. Passing a raw byte-string will produce invalid
|
|
28
|
+
* content.
|
|
29
|
+
*/
|
|
8
30
|
export declare function image(data: string | Uint8Array, mimeType: string, annotations?: ContentAnnotations): ImageContent;
|
|
31
|
+
/**
|
|
32
|
+
* Build an MCP audio content block.
|
|
33
|
+
*
|
|
34
|
+
* `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
|
|
35
|
+
* **already base64-encoded**.
|
|
36
|
+
*/
|
|
9
37
|
export declare function audio(data: string | Uint8Array, mimeType: string, annotations?: ContentAnnotations): AudioContent;
|
|
38
|
+
/**
|
|
39
|
+
* Build an MCP embedded resource — the full content travels inline. Use this
|
|
40
|
+
* when the client needs the bytes themselves rather than a link.
|
|
41
|
+
*
|
|
42
|
+
* Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).
|
|
43
|
+
*/
|
|
10
44
|
export declare function embeddedResource(resource: {
|
|
11
45
|
uri: string;
|
|
12
46
|
mimeType?: string;
|
|
@@ -16,6 +50,12 @@ export declare function embeddedResource(resource: {
|
|
|
16
50
|
mimeType?: string;
|
|
17
51
|
blob: string;
|
|
18
52
|
}, annotations?: ContentAnnotations): EmbeddedResource;
|
|
53
|
+
/**
|
|
54
|
+
* Build an MCP resource link — a `type: "resource_link"` block carrying a URI
|
|
55
|
+
* the client can fetch (or subscribe to) on demand. Use a link when the
|
|
56
|
+
* client should retrieve the bytes itself; use {@link embeddedResource} when
|
|
57
|
+
* the content must travel inline with the response.
|
|
58
|
+
*/
|
|
19
59
|
export declare function resourceLink(link: {
|
|
20
60
|
uri: string;
|
|
21
61
|
name: string;
|
|
@@ -10,9 +10,24 @@ function toBase64(data) {
|
|
|
10
10
|
}
|
|
11
11
|
return Buffer.from(data).toString("base64");
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Build an MCP text content block.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* return { content: [text("Found 3 results.")] };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
13
21
|
export function text(value, annotations) {
|
|
14
22
|
return { type: "text", text: value, ...(annotations && { annotations }) };
|
|
15
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Build an MCP image content block.
|
|
26
|
+
*
|
|
27
|
+
* `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
|
|
28
|
+
* **already base64-encoded**. Passing a raw byte-string will produce invalid
|
|
29
|
+
* content.
|
|
30
|
+
*/
|
|
16
31
|
export function image(data, mimeType, annotations) {
|
|
17
32
|
return {
|
|
18
33
|
type: "image",
|
|
@@ -21,6 +36,12 @@ export function image(data, mimeType, annotations) {
|
|
|
21
36
|
...(annotations && { annotations }),
|
|
22
37
|
};
|
|
23
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Build an MCP audio content block.
|
|
41
|
+
*
|
|
42
|
+
* `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
|
|
43
|
+
* **already base64-encoded**.
|
|
44
|
+
*/
|
|
24
45
|
export function audio(data, mimeType, annotations) {
|
|
25
46
|
return {
|
|
26
47
|
type: "audio",
|
|
@@ -29,6 +50,12 @@ export function audio(data, mimeType, annotations) {
|
|
|
29
50
|
...(annotations && { annotations }),
|
|
30
51
|
};
|
|
31
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Build an MCP embedded resource — the full content travels inline. Use this
|
|
55
|
+
* when the client needs the bytes themselves rather than a link.
|
|
56
|
+
*
|
|
57
|
+
* Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).
|
|
58
|
+
*/
|
|
32
59
|
export function embeddedResource(resource, annotations) {
|
|
33
60
|
return {
|
|
34
61
|
type: "resource",
|
|
@@ -36,6 +63,12 @@ export function embeddedResource(resource, annotations) {
|
|
|
36
63
|
...(annotations && { annotations }),
|
|
37
64
|
};
|
|
38
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Build an MCP resource link — a `type: "resource_link"` block carrying a URI
|
|
68
|
+
* the client can fetch (or subscribe to) on demand. Use a link when the
|
|
69
|
+
* client should retrieve the bytes itself; use {@link embeddedResource} when
|
|
70
|
+
* the content must travel inline with the response.
|
|
71
|
+
*/
|
|
39
72
|
export function resourceLink(link, annotations) {
|
|
40
73
|
return {
|
|
41
74
|
type: "resource_link",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-helpers.js","sourceRoot":"","sources":["../../src/server/content-helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-helpers.js","sourceRoot":"","sources":["../../src/server/content-helpers.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,IAAyB;IACzC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAClB,KAAa,EACb,WAAgC;IAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAEoD,EACpD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,IAOC,EACD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,GAAG,IAAI;QACP,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AudioContent,\n EmbeddedResource,\n ImageContent,\n ResourceLink,\n TextContent,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * MCP content annotations applied to any returned block.\n *\n * - `audience` — who is meant to see the content (`\"user\"`, `\"assistant\"`, or both).\n * - `priority` — relative importance hint for the host.\n * - `lastModified` — ISO timestamp for when the content was produced.\n */\ntype ContentAnnotations = {\n audience?: (\"user\" | \"assistant\")[];\n priority?: number;\n lastModified?: string;\n};\n\n/**\n * Returns a base64-encoded string.\n * - `Uint8Array` input is encoded via `Buffer.toString(\"base64\")`.\n * - `string` input is assumed to be **already base64-encoded** and is returned\n * as-is. Passing raw/unencoded string bytes will produce invalid MCP content.\n */\nfunction toBase64(data: string | Uint8Array): string {\n if (typeof data === \"string\") {\n return data;\n }\n return Buffer.from(data).toString(\"base64\");\n}\n\n/**\n * Build an MCP text content block.\n *\n * @example\n * ```ts\n * return { content: [text(\"Found 3 results.\")] };\n * ```\n */\nexport function text(\n value: string,\n annotations?: ContentAnnotations,\n): TextContent {\n return { type: \"text\", text: value, ...(annotations && { annotations }) };\n}\n\n/**\n * Build an MCP image content block.\n *\n * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is\n * **already base64-encoded**. Passing a raw byte-string will produce invalid\n * content.\n */\nexport function image(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): ImageContent {\n return {\n type: \"image\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP audio content block.\n *\n * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is\n * **already base64-encoded**.\n */\nexport function audio(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): AudioContent {\n return {\n type: \"audio\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP embedded resource — the full content travels inline. Use this\n * when the client needs the bytes themselves rather than a link.\n *\n * Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).\n */\nexport function embeddedResource(\n resource:\n | { uri: string; mimeType?: string; text: string }\n | { uri: string; mimeType?: string; blob: string },\n annotations?: ContentAnnotations,\n): EmbeddedResource {\n return {\n type: \"resource\",\n resource,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP resource link — a `type: \"resource_link\"` block carrying a URI\n * the client can fetch (or subscribe to) on demand. Use a link when the\n * client should retrieve the bytes itself; use {@link embeddedResource} when\n * the content must travel inline with the response.\n */\nexport function resourceLink(\n link: {\n uri: string;\n name: string;\n title?: string;\n description?: string;\n mimeType?: string;\n size?: number;\n },\n annotations?: ContentAnnotations,\n): ResourceLink {\n return {\n type: \"resource_link\",\n ...link,\n ...(annotations && { annotations }),\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-helpers.test.js","sourceRoot":"","sources":["../../src/server/content-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAE9B,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAC1C,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,GAA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it } from \"vitest\";\nimport {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\n\ndescribe(\"text\", () => {\n it(\"returns a TextContent without annotations when none given\", () => {\n expect(text(\"hello\")).toEqual({ type: \"text\", text: \"hello\" });\n });\n\n it(\"includes annotations when provided\", () => {\n expect(text(\"hi\", { priority: 1 })).toEqual({\n type: \"text\",\n text: \"hi\",\n annotations: { priority: 1 },\n });\n });\n});\n\ndescribe(\"image\", () => {\n it(\"base64-encodes Uint8Array data\", () => {\n const bytes = new Uint8Array([104, 105]);\n expect(image(bytes, \"image/png\")).toEqual({\n type: \"image\",\n data: \"aGk=\",\n mimeType: \"image/png\",\n });\n });\n\n it(\"passes string data through unchanged (caller is responsible for base64)\", () => {\n expect(image(\"YWxyZWFkeS1iNjQ=\", \"image/png\")).toEqual({\n type: \"image\",\n data: \"YWxyZWFkeS1iNjQ=\",\n mimeType: \"image/png\",\n });\n });\n});\n\ndescribe(\"audio\", () => {\n it(\"base64-encodes Uint8Array data\", () => {\n const bytes = new Uint8Array([104, 105]);\n expect(audio(bytes, \"audio/mpeg\")).toMatchObject({\n type: \"audio\",\n data: \"aGk=\",\n mimeType: \"audio/mpeg\",\n });\n });\n});\n\ndescribe(\"embeddedResource\", () => {\n it(\"wraps a text resource with a type tag\", () => {\n expect(\n embeddedResource({\n uri: \"file:///a.txt\",\n mimeType: \"text/plain\",\n text: \"x\",\n }),\n ).toEqual({\n type: \"resource\",\n resource: { uri: \"file:///a.txt\", mimeType: \"text/plain\", text: \"x\" },\n });\n });\n\n it(\"wraps a blob resource with a type tag\", () => {\n expect(embeddedResource({ uri: \"file:///a.bin\", blob: \"YmFy\" })).toEqual({\n type: \"resource\",\n resource: { uri: \"file:///a.bin\", blob: \"YmFy\" },\n });\n });\n});\n\ndescribe(\"resourceLink\", () => {\n it(\"spreads link fields alongside the type tag\", () => {\n expect(resourceLink({ uri: \"file:///a\", name: \"a\", title: \"A\" })).toEqual({\n type: \"resource_link\",\n uri: \"file:///a\",\n name: \"a\",\n title: \"A\",\n });\n });\n});\n"]}
|
package/dist/server/express.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type http from "node:http";
|
|
2
2
|
import express from "express";
|
|
3
3
|
import type { McpServer } from "./server.js";
|
|
4
|
-
export declare function createApp({ mcpServer, httpServer,
|
|
4
|
+
export declare function createApp({ mcpServer, httpServer, errorMiddleware, }: {
|
|
5
5
|
mcpServer: McpServer;
|
|
6
6
|
httpServer: http.Server;
|
|
7
|
-
customMiddleware?: {
|
|
8
|
-
path?: string;
|
|
9
|
-
handlers: express.RequestHandler[];
|
|
10
|
-
}[];
|
|
11
7
|
errorMiddleware?: {
|
|
12
8
|
path?: string;
|
|
13
9
|
handlers: express.ErrorRequestHandler[];
|
package/dist/server/express.js
CHANGED
|
@@ -32,12 +32,11 @@ function defaultErrorHandler(err, _req, res, _next) {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export async function createApp({ mcpServer, httpServer,
|
|
36
|
-
const app = express
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
if (env !== "production") {
|
|
35
|
+
export async function createApp({ mcpServer, httpServer, errorMiddleware = [], }) {
|
|
36
|
+
const app = mcpServer.express;
|
|
37
|
+
// Read `process.env.NODE_ENV` inline: wrangler/esbuild only substitute the literal expression,
|
|
38
|
+
// so a local const would defeat dead-code elimination of the dev-only imports below.
|
|
39
|
+
if (process.env.NODE_ENV !== "production") {
|
|
41
40
|
const { devtoolsStaticServer } = await import("@skybridge/devtools");
|
|
42
41
|
app.use(await devtoolsStaticServer());
|
|
43
42
|
const { viewsDevServer } = await import("./viewsDevServer.js");
|
|
@@ -51,7 +50,7 @@ export async function createApp({ mcpServer, httpServer, customMiddleware = [],
|
|
|
51
50
|
console.warn(`Ignoring invalid __TUNNEL_CONTROL_PORT=${process.env.__TUNNEL_CONTROL_PORT}`);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
|
|
53
|
+
else {
|
|
55
54
|
const assetsPath = path.join(process.cwd(), "dist", "assets");
|
|
56
55
|
app.use("/assets", cors());
|
|
57
56
|
app.use("/assets", express.static(assetsPath));
|
|
@@ -77,6 +76,13 @@ const mcpMiddleware = (server) => {
|
|
|
77
76
|
try {
|
|
78
77
|
const transport = new StreamableHTTPServerTransport({
|
|
79
78
|
sessionIdGenerator: undefined,
|
|
79
|
+
// Respond with a single JSON body instead of SSE. Skybridge's stateless
|
|
80
|
+
// transport never streams server-initiated messages, so SSE adds no
|
|
81
|
+
// capability — and on workerd specifically, `cloudflare:node`'s http
|
|
82
|
+
// bridge silently drops chunked writes that happen after the request
|
|
83
|
+
// handler awaits, which manifests as a 200 with empty body for any
|
|
84
|
+
// async tools/call.
|
|
85
|
+
enableJsonResponse: true,
|
|
80
86
|
});
|
|
81
87
|
res.on("close", () => {
|
|
82
88
|
transport.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,SAAS,gBAAgB,CAAC,GAAuB;IAC/C,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,gBAAgB,CACvB,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AAM,aAAa,GAAG,CAAC,MAAiB,EAA0B,EAAE;IAClE,OAAO,KAAK,EACV,GAAoB,EACpB,GAAqB,EACrB,IAA0B,EAC1B,EAAE;QACF,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC1B,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CACpB,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,CAAC,KAAK;oBACZ,OAAO,EAAE,qBAAqB;iBAC/B;gBACD,EAAE,EAAE,IAAI;aACT,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;gBAClD,kBAAkB,EAAE,SAAS;gBAC7B,wEAAwE;gBACxE,oEAAoE;gBACpE,qEAAqE;gBACrE,qEAAqE;gBACrE,mEAAmE;gBACnE,oBAAoB;gBACpB,kBAAkB,EAAE,IAAI;aACzB,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACnB,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC;YAClD,wEAAwE;YACxE,4DAA4D;YAC5D,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC;YAC1B,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type http from \"node:http\";\nimport path from \"node:path\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport cors from \"cors\";\nimport express from \"express\";\nimport type { McpServer } from \"./server.js\";\n\nfunction parseControlPort(raw: string | undefined): number | null {\n if (raw === undefined) {\n return null;\n }\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n <= 0 || n >= 65536) {\n return null;\n }\n return n;\n}\n\nfunction applyMiddlewares(\n app: express.Express,\n middlewares: Array<{\n path?: string;\n handlers: express.ErrorRequestHandler[];\n }>,\n): void {\n for (const middleware of middlewares) {\n if (middleware.path) {\n app.use(middleware.path, ...middleware.handlers);\n } else {\n app.use(...middleware.handlers);\n }\n }\n}\n\nfunction defaultErrorHandler(\n err: unknown,\n _req: express.Request,\n res: express.Response,\n _next: express.NextFunction,\n) {\n console.error(\"Error handling MCP request:\", err);\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Internal server error\" },\n id: null,\n });\n }\n}\n\nexport async function createApp({\n mcpServer,\n httpServer,\n errorMiddleware = [],\n}: {\n mcpServer: McpServer;\n httpServer: http.Server;\n errorMiddleware?: {\n path?: string;\n handlers: express.ErrorRequestHandler[];\n }[];\n}): Promise<express.Express> {\n const app = mcpServer.express;\n\n // Read `process.env.NODE_ENV` inline: wrangler/esbuild only substitute the literal expression,\n // so a local const would defeat dead-code elimination of the dev-only imports below.\n if (process.env.NODE_ENV !== \"production\") {\n const { devtoolsStaticServer } = await import(\"@skybridge/devtools\");\n app.use(await devtoolsStaticServer());\n const { viewsDevServer } = await import(\"./viewsDevServer.js\");\n app.use(await viewsDevServer(httpServer));\n\n const controlPort = parseControlPort(process.env.__TUNNEL_CONTROL_PORT);\n if (controlPort !== null) {\n const { createTunnelProxyRouter } = await import(\n \"./tunnel-proxy-router.js\"\n );\n app.use(createTunnelProxyRouter(controlPort));\n } else if (process.env.__TUNNEL_CONTROL_PORT !== undefined) {\n console.warn(\n `Ignoring invalid __TUNNEL_CONTROL_PORT=${process.env.__TUNNEL_CONTROL_PORT}`,\n );\n }\n } else {\n const assetsPath = path.join(process.cwd(), \"dist\", \"assets\");\n\n app.use(\"/assets\", cors());\n app.use(\"/assets\", express.static(assetsPath));\n }\n\n app.use(\"/mcp\", mcpMiddleware(mcpServer));\n\n applyMiddlewares(app, errorMiddleware);\n\n app.use(\"/mcp\", defaultErrorHandler);\n\n return app;\n}\n\nconst mcpMiddleware = (server: McpServer): express.RequestHandler => {\n return async (\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n ) => {\n if (req.method !== \"POST\") {\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: \"2.0\",\n error: {\n code: -32000,\n message: \"Method not allowed.\",\n },\n id: null,\n }),\n );\n return;\n }\n\n try {\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n // Respond with a single JSON body instead of SSE. Skybridge's stateless\n // transport never streams server-initiated messages, so SSE adds no\n // capability — and on workerd specifically, `cloudflare:node`'s http\n // bridge silently drops chunked writes that happen after the request\n // handler awaits, which manifests as a 200 with empty body for any\n // async tools/call.\n enableJsonResponse: true,\n });\n\n res.on(\"close\", () => {\n transport.close();\n });\n\n await server.connectStatelessTransport(transport);\n // Express strips the mount path from req.url (e.g. \"/mcp\" becomes \"/\").\n // Restore it so the SDK builds the correct requestInfo.url.\n req.url = req.originalUrl;\n await transport.handleRequest(req, res, req.body);\n } catch (error) {\n next(error);\n }\n };\n};\n"]}
|
|
@@ -7,7 +7,6 @@ vi.mock("@skybridge/devtools", () => ({
|
|
|
7
7
|
vi.mock("./viewsDevServer.js", () => ({
|
|
8
8
|
viewsDevServer: (_httpServer) => ((_req, _res, next) => next()),
|
|
9
9
|
}));
|
|
10
|
-
const fakeServer = {};
|
|
11
10
|
async function listen(app) {
|
|
12
11
|
const server = http.createServer(app);
|
|
13
12
|
await new Promise((resolve) => server.listen(0, resolve));
|
|
@@ -26,6 +25,125 @@ async function postMcp(port) {
|
|
|
26
25
|
async function postApi(port) {
|
|
27
26
|
return fetch(`http://localhost:${port}/api/test`, { method: "POST" });
|
|
28
27
|
}
|
|
28
|
+
describe("McpServer.express", () => {
|
|
29
|
+
it("exposes a ready Express app immediately after construction", () => {
|
|
30
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
31
|
+
expect(server.express).toBeDefined();
|
|
32
|
+
expect(typeof server.express.use).toBe("function");
|
|
33
|
+
expect(typeof server.express.get).toBe("function");
|
|
34
|
+
});
|
|
35
|
+
it("server.express.get registers a route reachable alongside /mcp", async () => {
|
|
36
|
+
const { createApp } = await import("./express.js");
|
|
37
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
38
|
+
server.express.get("/health", (_req, res) => {
|
|
39
|
+
res.json({ status: "ok" });
|
|
40
|
+
});
|
|
41
|
+
const httpServer = http.createServer();
|
|
42
|
+
await createApp({ mcpServer: server, httpServer });
|
|
43
|
+
const { port, server: listening } = await listen(server.express);
|
|
44
|
+
openServer = listening;
|
|
45
|
+
const health = await fetch(`http://localhost:${port}/health`);
|
|
46
|
+
expect(health.status).toBe(200);
|
|
47
|
+
expect(await health.json()).toEqual({ status: "ok" });
|
|
48
|
+
// /mcp still works (POST returns 200/4xx, not 404)
|
|
49
|
+
const mcp = await postMcp(port);
|
|
50
|
+
expect(mcp.status).not.toBe(404);
|
|
51
|
+
});
|
|
52
|
+
it("server.use and server.express.use produce the same registration order", async () => {
|
|
53
|
+
const { createApp } = await import("./express.js");
|
|
54
|
+
const callsA = [];
|
|
55
|
+
const callsB = [];
|
|
56
|
+
const buildServer = () => new McpServer({ name: "t", version: "0.0.0" });
|
|
57
|
+
const sA = buildServer();
|
|
58
|
+
sA.use((_req, _res, next) => {
|
|
59
|
+
callsA.push("first");
|
|
60
|
+
next();
|
|
61
|
+
});
|
|
62
|
+
sA.express.use((_req, _res, next) => {
|
|
63
|
+
callsA.push("second");
|
|
64
|
+
next();
|
|
65
|
+
});
|
|
66
|
+
const sB = buildServer();
|
|
67
|
+
sB.express.use((_req, _res, next) => {
|
|
68
|
+
callsB.push("first");
|
|
69
|
+
next();
|
|
70
|
+
});
|
|
71
|
+
sB.use((_req, _res, next) => {
|
|
72
|
+
callsB.push("second");
|
|
73
|
+
next();
|
|
74
|
+
});
|
|
75
|
+
for (const s of [sA, sB]) {
|
|
76
|
+
s.express.get("/probe", (_req, res) => res.json({ ok: true }));
|
|
77
|
+
const httpServer = http.createServer();
|
|
78
|
+
await createApp({ mcpServer: s, httpServer });
|
|
79
|
+
const { port, server: listening } = await listen(s.express);
|
|
80
|
+
openServer = listening;
|
|
81
|
+
await fetch(`http://localhost:${port}/probe`);
|
|
82
|
+
listening.close();
|
|
83
|
+
}
|
|
84
|
+
expect(callsA).toEqual(["first", "second"]);
|
|
85
|
+
expect(callsB).toEqual(["first", "second"]);
|
|
86
|
+
});
|
|
87
|
+
it("useOnError still wraps thrown /mcp errors after the route is mounted", async () => {
|
|
88
|
+
const { createApp } = await import("./express.js");
|
|
89
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
90
|
+
// Register the error handler BEFORE createApp — useOnError should still
|
|
91
|
+
// apply it after /mcp, so /mcp errors hit it.
|
|
92
|
+
const seen = [];
|
|
93
|
+
server.useOnError((_err, _req, res, _next) => {
|
|
94
|
+
seen.push("useOnError");
|
|
95
|
+
res.status(503).json({ from: "useOnError" });
|
|
96
|
+
});
|
|
97
|
+
// Force the /mcp handler to throw so the error pipeline runs.
|
|
98
|
+
vi.spyOn(server, "connectStatelessTransport").mockRejectedValue(new Error("boom"));
|
|
99
|
+
const httpServer = http.createServer();
|
|
100
|
+
await createApp({
|
|
101
|
+
mcpServer: server,
|
|
102
|
+
httpServer,
|
|
103
|
+
// Mirror what run() does: forward the McpServer's useOnError handlers
|
|
104
|
+
// to createApp so they get applied after /mcp.
|
|
105
|
+
// biome-ignore lint/complexity/useLiteralKeys: test mirrors run() internals to verify useOnError ordering
|
|
106
|
+
errorMiddleware: server["customErrorMiddleware"],
|
|
107
|
+
});
|
|
108
|
+
const { port, server: listening } = await listen(server.express);
|
|
109
|
+
openServer = listening;
|
|
110
|
+
const res = await postMcp(port);
|
|
111
|
+
expect(seen).toEqual(["useOnError"]);
|
|
112
|
+
expect(res.status).toBe(503);
|
|
113
|
+
expect(await res.json()).toEqual({ from: "useOnError" });
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe("McpServer JSON body parser options", () => {
|
|
117
|
+
const largeBody = JSON.stringify({ data: "x".repeat(200 * 1024) });
|
|
118
|
+
async function postEcho(port, body) {
|
|
119
|
+
return fetch(`http://localhost:${port}/echo`, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers: { "Content-Type": "application/json" },
|
|
122
|
+
body,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
it("forwards json options to express.json", async () => {
|
|
126
|
+
const server = new McpServer({ name: "t", version: "0.0.0" }, {}, { json: { limit: "10mb" } });
|
|
127
|
+
server.express.post("/echo", (req, res) => {
|
|
128
|
+
res.json({ received: req.body.data.length });
|
|
129
|
+
});
|
|
130
|
+
const { port, server: listening } = await listen(server.express);
|
|
131
|
+
openServer = listening;
|
|
132
|
+
const res = await postEcho(port, largeBody);
|
|
133
|
+
expect(res.status).toBe(200);
|
|
134
|
+
expect(await res.json()).toEqual({ received: 200 * 1024 });
|
|
135
|
+
});
|
|
136
|
+
it("keeps the default 100kb limit when no options are passed", async () => {
|
|
137
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
138
|
+
server.express.post("/echo", (_req, res) => {
|
|
139
|
+
res.json({ ok: true });
|
|
140
|
+
});
|
|
141
|
+
const { port, server: listening } = await listen(server.express);
|
|
142
|
+
openServer = listening;
|
|
143
|
+
const res = await postEcho(port, largeBody);
|
|
144
|
+
expect(res.status).toBe(413);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
29
147
|
describe("createApp", () => {
|
|
30
148
|
it("runs global custom middleware before the /mcp handler", async () => {
|
|
31
149
|
const { createApp } = await import("./express.js");
|
|
@@ -34,14 +152,12 @@ describe("createApp", () => {
|
|
|
34
152
|
calls.push("custom");
|
|
35
153
|
next();
|
|
36
154
|
};
|
|
155
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
156
|
+
server.use(mw);
|
|
37
157
|
const httpServer = http.createServer();
|
|
38
|
-
const app = await createApp({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
customMiddleware: [{ handlers: [mw] }],
|
|
42
|
-
});
|
|
43
|
-
const { port, server } = await listen(app);
|
|
44
|
-
openServer = server;
|
|
158
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
159
|
+
const { port, server: httpListening } = await listen(app);
|
|
160
|
+
openServer = httpListening;
|
|
45
161
|
await postMcp(port);
|
|
46
162
|
expect(calls).toEqual(["custom"]);
|
|
47
163
|
});
|
|
@@ -52,14 +168,12 @@ describe("createApp", () => {
|
|
|
52
168
|
calls.push("auth");
|
|
53
169
|
next();
|
|
54
170
|
};
|
|
171
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
172
|
+
server.use("/mcp", mw);
|
|
55
173
|
const httpServer = http.createServer();
|
|
56
|
-
const app = await createApp({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
customMiddleware: [{ path: "/mcp", handlers: [mw] }],
|
|
60
|
-
});
|
|
61
|
-
const { port, server } = await listen(app);
|
|
62
|
-
openServer = server;
|
|
174
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
175
|
+
const { port, server: httpListening } = await listen(app);
|
|
176
|
+
openServer = httpListening;
|
|
63
177
|
await postMcp(port);
|
|
64
178
|
expect(calls).toEqual(["auth"]);
|
|
65
179
|
});
|
|
@@ -70,14 +184,12 @@ describe("createApp", () => {
|
|
|
70
184
|
calls.push("reject");
|
|
71
185
|
res.status(401).json({ error: "Unauthorized" });
|
|
72
186
|
};
|
|
187
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
188
|
+
server.use("/mcp", reject);
|
|
73
189
|
const httpServer = http.createServer();
|
|
74
|
-
const app = await createApp({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
customMiddleware: [{ path: "/mcp", handlers: [reject] }],
|
|
78
|
-
});
|
|
79
|
-
const { port, server } = await listen(app);
|
|
80
|
-
openServer = server;
|
|
190
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
191
|
+
const { port, server: httpListening } = await listen(app);
|
|
192
|
+
openServer = httpListening;
|
|
81
193
|
const res = await postMcp(port);
|
|
82
194
|
expect(calls).toEqual(["reject"]);
|
|
83
195
|
expect(res.status).toBe(401);
|
|
@@ -94,14 +206,13 @@ describe("createApp", () => {
|
|
|
94
206
|
calls.push("B");
|
|
95
207
|
next();
|
|
96
208
|
};
|
|
209
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
210
|
+
server.use(mwA);
|
|
211
|
+
server.use(mwB);
|
|
97
212
|
const httpServer = http.createServer();
|
|
98
|
-
const app = await createApp({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
customMiddleware: [{ handlers: [mwA] }, { handlers: [mwB] }],
|
|
102
|
-
});
|
|
103
|
-
const { port, server } = await listen(app);
|
|
104
|
-
openServer = server;
|
|
213
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
214
|
+
const { port, server: httpListening } = await listen(app);
|
|
215
|
+
openServer = httpListening;
|
|
105
216
|
await postMcp(port);
|
|
106
217
|
expect(calls).toEqual(["A", "B"]);
|
|
107
218
|
});
|
|
@@ -112,14 +223,12 @@ describe("createApp", () => {
|
|
|
112
223
|
calls.push("api");
|
|
113
224
|
next();
|
|
114
225
|
};
|
|
226
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
227
|
+
server.use("/api", apiMw);
|
|
115
228
|
const httpServer = http.createServer();
|
|
116
|
-
const app = await createApp({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
customMiddleware: [{ path: "/api", handlers: [apiMw] }],
|
|
120
|
-
});
|
|
121
|
-
const { port, server } = await listen(app);
|
|
122
|
-
openServer = server;
|
|
229
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
230
|
+
const { port, server: httpListening } = await listen(app);
|
|
231
|
+
openServer = httpListening;
|
|
123
232
|
// Hit /mcp — the /api middleware should NOT fire
|
|
124
233
|
await postMcp(port);
|
|
125
234
|
expect(calls).toEqual([]);
|
|
@@ -131,14 +240,12 @@ describe("createApp", () => {
|
|
|
131
240
|
router.get("/health", (_req, res) => {
|
|
132
241
|
res.json({ status: "ok" });
|
|
133
242
|
});
|
|
243
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
244
|
+
server.use(router);
|
|
134
245
|
const httpServer = http.createServer();
|
|
135
|
-
const app = await createApp({
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
customMiddleware: [{ handlers: [router] }],
|
|
139
|
-
});
|
|
140
|
-
const { port, server } = await listen(app);
|
|
141
|
-
openServer = server;
|
|
246
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
247
|
+
const { port, server: httpListening } = await listen(app);
|
|
248
|
+
openServer = httpListening;
|
|
142
249
|
const res = await fetch(`http://localhost:${port}/health`);
|
|
143
250
|
expect(res.status).toBe(200);
|
|
144
251
|
expect(await res.json()).toEqual({ status: "ok" });
|
|
@@ -150,16 +257,12 @@ describe("createApp", () => {
|
|
|
150
257
|
router.get("/data", (_req, res) => {
|
|
151
258
|
res.json({ value: 42 });
|
|
152
259
|
});
|
|
260
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
261
|
+
server.use("/api", router);
|
|
153
262
|
const httpServer = http.createServer();
|
|
154
|
-
const app = await createApp({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
customMiddleware: [
|
|
158
|
-
{ path: "/api", handlers: [router] },
|
|
159
|
-
],
|
|
160
|
-
});
|
|
161
|
-
const { port, server } = await listen(app);
|
|
162
|
-
openServer = server;
|
|
263
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
264
|
+
const { port, server: httpListening } = await listen(app);
|
|
265
|
+
openServer = httpListening;
|
|
163
266
|
const res = await fetch(`http://localhost:${port}/api/data`);
|
|
164
267
|
expect(res.status).toBe(200);
|
|
165
268
|
expect(await res.json()).toEqual({ value: 42 });
|
|
@@ -169,14 +272,12 @@ describe("createApp", () => {
|
|
|
169
272
|
const throwing = () => {
|
|
170
273
|
throw new Error("boom");
|
|
171
274
|
};
|
|
275
|
+
const server = new McpServer({ name: "t", version: "0.0.0" });
|
|
276
|
+
server.use("/explode", throwing);
|
|
172
277
|
const httpServer = http.createServer();
|
|
173
|
-
const app = await createApp({
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
customMiddleware: [{ path: "/explode", handlers: [throwing] }],
|
|
177
|
-
});
|
|
178
|
-
const { port, server } = await listen(app);
|
|
179
|
-
openServer = server;
|
|
278
|
+
const app = await createApp({ mcpServer: server, httpServer });
|
|
279
|
+
const { port, server: httpListening } = await listen(app);
|
|
280
|
+
openServer = httpListening;
|
|
180
281
|
const res = await fetch(`http://localhost:${port}/explode`);
|
|
181
282
|
expect(res.status).toBe(500);
|
|
182
283
|
// Server process did not crash — it still accepts connections
|
|
@@ -186,10 +287,15 @@ describe("createApp", () => {
|
|
|
186
287
|
it("returns 500 JSON-RPC error when the MCP handler throws and no error middleware is registered", async () => {
|
|
187
288
|
const { createApp } = await import("./express.js");
|
|
188
289
|
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
290
|
+
const mcpServer = new McpServer({ name: "t", version: "0.0.0" });
|
|
291
|
+
// Force the express-level error path: make connectStatelessTransport
|
|
292
|
+
// reject so the request handler hits its try/catch and calls next(error),
|
|
293
|
+
// which lands in the default /mcp error handler.
|
|
294
|
+
vi.spyOn(mcpServer, "connectStatelessTransport").mockRejectedValue(new Error("boom"));
|
|
189
295
|
const httpServer = http.createServer();
|
|
190
|
-
const app = await createApp({ mcpServer
|
|
191
|
-
const { port, server } = await listen(app);
|
|
192
|
-
openServer =
|
|
296
|
+
const app = await createApp({ mcpServer, httpServer });
|
|
297
|
+
const { port, server: httpListening } = await listen(app);
|
|
298
|
+
openServer = httpListening;
|
|
193
299
|
const res = await postMcp(port);
|
|
194
300
|
expect(res.status).toBe(500);
|
|
195
301
|
expect(await res.json()).toEqual({
|
|
@@ -207,14 +313,16 @@ describe("createApp", () => {
|
|
|
207
313
|
calls.push("error-handler");
|
|
208
314
|
res.status(503).json({ custom: true });
|
|
209
315
|
};
|
|
316
|
+
const mcpServer = new McpServer({ name: "t", version: "0.0.0" });
|
|
317
|
+
vi.spyOn(mcpServer, "connectStatelessTransport").mockRejectedValue(new Error("boom"));
|
|
210
318
|
const httpServer = http.createServer();
|
|
211
319
|
const app = await createApp({
|
|
212
|
-
mcpServer
|
|
320
|
+
mcpServer,
|
|
213
321
|
httpServer,
|
|
214
322
|
errorMiddleware: [{ handlers: [errorHandler] }],
|
|
215
323
|
});
|
|
216
|
-
const { port, server } = await listen(app);
|
|
217
|
-
openServer =
|
|
324
|
+
const { port, server: httpListening } = await listen(app);
|
|
325
|
+
openServer = httpListening;
|
|
218
326
|
const res = await postMcp(port);
|
|
219
327
|
expect(calls).toEqual(["error-handler"]);
|
|
220
328
|
expect(res.status).toBe(503);
|
|
@@ -230,15 +338,17 @@ describe("createApp", () => {
|
|
|
230
338
|
const throwingApiRoute = (_req, _res, next) => {
|
|
231
339
|
next(new Error("api error"));
|
|
232
340
|
};
|
|
341
|
+
const mcpServer = new McpServer({ name: "t", version: "0.0.0" });
|
|
342
|
+
vi.spyOn(mcpServer, "connectStatelessTransport").mockRejectedValue(new Error("boom"));
|
|
343
|
+
mcpServer.use("/api/test", throwingApiRoute);
|
|
233
344
|
const httpServer = http.createServer();
|
|
234
345
|
const app = await createApp({
|
|
235
|
-
mcpServer
|
|
346
|
+
mcpServer,
|
|
236
347
|
httpServer,
|
|
237
|
-
customMiddleware: [{ path: "/api/test", handlers: [throwingApiRoute] }],
|
|
238
348
|
errorMiddleware: [{ path: "/mcp", handlers: [mcpErrorHandler] }],
|
|
239
349
|
});
|
|
240
|
-
const { port, server } = await listen(app);
|
|
241
|
-
openServer =
|
|
350
|
+
const { port, server: httpListening } = await listen(app);
|
|
351
|
+
openServer = httpListening;
|
|
242
352
|
const mcpRes = await postMcp(port);
|
|
243
353
|
expect(calls).toEqual(["mcp-error-handler"]);
|
|
244
354
|
expect(mcpRes.status).toBe(503);
|
|
@@ -286,6 +396,36 @@ describe("createApp", () => {
|
|
|
286
396
|
consoleSpy.mockRestore();
|
|
287
397
|
});
|
|
288
398
|
});
|
|
399
|
+
describe("createApp Vercel mode", () => {
|
|
400
|
+
it("server.run() returns the Express app without binding a port when VERCEL=1", async () => {
|
|
401
|
+
const prevVercel = process.env.VERCEL;
|
|
402
|
+
const prevEnv = process.env.NODE_ENV;
|
|
403
|
+
process.env.VERCEL = "1";
|
|
404
|
+
process.env.NODE_ENV = "production";
|
|
405
|
+
try {
|
|
406
|
+
vi.resetModules();
|
|
407
|
+
const { McpServer: Reloaded } = await import("./server.js");
|
|
408
|
+
const server = new Reloaded({ name: "t", version: "0.0.0" });
|
|
409
|
+
const result = await server.run();
|
|
410
|
+
expect(typeof result).toBe("function");
|
|
411
|
+
expect(result).toBe(server.express);
|
|
412
|
+
const { port, server: listening } = await listen(server.express);
|
|
413
|
+
openServer = listening;
|
|
414
|
+
const res = await postMcp(port);
|
|
415
|
+
expect(res.status).not.toBe(404);
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
if (prevVercel === undefined) {
|
|
419
|
+
delete process.env.VERCEL;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
process.env.VERCEL = prevVercel;
|
|
423
|
+
}
|
|
424
|
+
process.env.NODE_ENV = prevEnv;
|
|
425
|
+
vi.resetModules();
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
});
|
|
289
429
|
describe("createApp tunnel routes", () => {
|
|
290
430
|
it("proxies POST /__skybridge/tunnel to the cli control server in dev mode", async () => {
|
|
291
431
|
// Stand up a fake control listener that returns a known JSON body.
|
|
@@ -304,8 +444,9 @@ describe("createApp tunnel routes", () => {
|
|
|
304
444
|
process.env.__TUNNEL_CONTROL_PORT = String(controlPort);
|
|
305
445
|
try {
|
|
306
446
|
const { createApp } = await import("./express.js");
|
|
447
|
+
const mcpServer = new McpServer({ name: "t", version: "0.0.0" });
|
|
307
448
|
const httpServer = http.createServer();
|
|
308
|
-
const app = await createApp({ mcpServer
|
|
449
|
+
const app = await createApp({ mcpServer, httpServer });
|
|
309
450
|
const { port, server } = await listen(app);
|
|
310
451
|
openServer = server;
|
|
311
452
|
const res = await fetch(`http://localhost:${port}/__skybridge/tunnel`, {
|
|
@@ -330,8 +471,10 @@ describe("createApp tunnel routes", () => {
|
|
|
330
471
|
try {
|
|
331
472
|
vi.resetModules();
|
|
332
473
|
const { createApp } = await import("./express.js");
|
|
474
|
+
const { McpServer: ReloadedMcpServer } = await import("./server.js");
|
|
475
|
+
const mcpServer = new ReloadedMcpServer({ name: "t", version: "0.0.0" });
|
|
333
476
|
const httpServer = http.createServer();
|
|
334
|
-
const app = await createApp({ mcpServer
|
|
477
|
+
const app = await createApp({ mcpServer, httpServer });
|
|
335
478
|
const { port, server } = await listen(app);
|
|
336
479
|
openServer = server;
|
|
337
480
|
const res = await fetch(`http://localhost:${port}/__skybridge/tunnel`, {
|