skybridge 0.0.0-dev.815d058 → 0.0.0-dev.8164d23
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 +3 -0
- package/dist/cli/build-helpers.d.ts +6 -2
- package/dist/cli/build-helpers.js +39 -14
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +73 -5
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
- package/dist/cli/resolve-skybridge-config.js.map +1 -0
- package/dist/cli/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +71 -60
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +2 -61
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +34 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +2 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- package/dist/server/app.d.ts +177 -0
- package/dist/server/app.js +261 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/auth/discovery.d.ts +29 -7
- package/dist/server/auth/discovery.js +16 -11
- package/dist/server/auth/discovery.js.map +1 -1
- package/dist/server/auth/index.d.ts +17 -5
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +33 -6
- package/dist/server/auth/providers/auth0.js +25 -12
- package/dist/server/auth/providers/auth0.js.map +1 -1
- package/dist/server/auth/providers/auth0.test.js +30 -13
- package/dist/server/auth/providers/auth0.test.js.map +1 -1
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +140 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +39 -2
- package/dist/server/auth/providers/clerk.js +5 -6
- package/dist/server/auth/providers/clerk.js.map +1 -1
- package/dist/server/auth/providers/clerk.test.js +7 -25
- package/dist/server/auth/providers/clerk.test.js.map +1 -1
- package/dist/server/auth/providers/custom.d.ts +26 -3
- package/dist/server/auth/providers/custom.js +42 -14
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +79 -12
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +40 -11
- package/dist/server/auth/providers/descope.js +38 -9
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +42 -15
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- package/dist/server/auth/providers/shared.d.ts +2 -0
- package/dist/server/auth/providers/shared.js +6 -0
- package/dist/server/auth/providers/shared.js.map +1 -0
- package/dist/server/auth/providers/shared.test.d.ts +1 -0
- package/dist/server/auth/providers/shared.test.js +10 -0
- package/dist/server/auth/providers/shared.test.js.map +1 -0
- package/dist/server/auth/providers/stytch.d.ts +15 -2
- package/dist/server/auth/providers/stytch.js +5 -6
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +24 -2
- package/dist/server/auth/providers/workos.js +5 -6
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +3 -1
- package/dist/server/auth/setup.js +66 -26
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +342 -15
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.d.ts +37 -3
- package/dist/server/auth/verify.js +27 -3
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +49 -0
- package/dist/server/auth/verify.test.js.map +1 -1
- package/dist/server/auth-extra.test-d.js +70 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +42 -5
- package/dist/server/auth.js +3 -4
- package/dist/server/auth.js.map +1 -1
- package/dist/server/build-manifest.test.js +6 -5
- package/dist/server/build-manifest.test.js.map +1 -1
- package/dist/server/content-helpers.d.ts +1 -1
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.d.ts +5 -3
- package/dist/server/express.js +8 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +130 -102
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +15 -8
- package/dist/server/index.js +8 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +37 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/middleware.d.ts +35 -10
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +9 -9
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +164 -98
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +23 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +155 -137
- package/dist/server/server.js +281 -351
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +79 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +72 -0
- package/dist/server/tool-extra.test.js.map +1 -0
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.js +101 -17
- package/dist/server/view-resource-resolution.test.js.map +1 -1
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/standard-schema.d.ts +3 -0
- package/dist/standard-schema.js +2 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +18 -13
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +88 -120
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +327 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +225 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -4
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +4 -4
- package/dist/web/bridges/get-adaptor.js +6 -11
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
- package/dist/web/bridges/mcp-app/bridge.js +51 -7
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +27 -9
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +9 -6
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +1 -1
- package/dist/web/data-llm.test.js +19 -6
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +13 -12
- package/dist/web/generate-helpers.js +10 -9
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +3 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -1
- package/dist/web/hooks/index.js +2 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +2 -1
- package/dist/web/hooks/test/utils.js +1 -1
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +39 -25
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +57 -21
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +1 -3
- package/dist/web/hooks/use-download.js +1 -2
- package/dist/web/hooks/use-download.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +16 -8
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +11 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +22 -0
- package/dist/web/hooks/use-host.js +30 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +14 -4
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
- package/dist/web/hooks/use-register-view-tool.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +11 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +29 -9
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +1 -20
- package/dist/web/hooks/use-tool-info.js +0 -1
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +0 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +37 -32
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +84 -36
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +38 -3
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/use-viewport.test.js +109 -0
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-view.d.ts +3 -2
- package/dist/web/mount-view.js +3 -2
- package/dist/web/mount-view.js.map +1 -1
- package/dist/web/plugin/plugin-build.test.d.ts +1 -0
- package/dist/web/plugin/plugin-build.test.js +54 -0
- package/dist/web/plugin/plugin-build.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +6 -0
- package/dist/web/plugin/plugin.js +18 -7
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/plugin.test.d.ts +1 -0
- package/dist/web/plugin/plugin.test.js +61 -0
- package/dist/web/plugin/plugin.test.js.map +1 -0
- package/package.json +28 -23
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
- package/dist/server/auth/providers/stytch.test.js +0 -33
- package/dist/server/auth/providers/stytch.test.js.map +0 -1
- package/dist/server/auth/providers/workos.test.js +0 -41
- package/dist/server/auth/providers/workos.test.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
- package/dist/web/bridges/mcp-app/adaptor.js +0 -283
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js +0 -96
- package/dist/web/hooks/use-layout.test.js.map +0 -1
- /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
- /package/dist/{server/auth/providers/workos.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/hooks/use-layout.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { expectTypeOf, test } from "vitest";
|
|
2
|
-
const
|
|
2
|
+
const app = null;
|
|
3
3
|
test("request category narrows extra and next() result", () => {
|
|
4
|
-
|
|
4
|
+
app.mcpMiddleware("request", async (_request, extra, next) => {
|
|
5
5
|
expectTypeOf(extra).toEqualTypeOf();
|
|
6
|
-
extra.signal;
|
|
6
|
+
extra.mcpReq.signal;
|
|
7
7
|
const result = await next();
|
|
8
8
|
expectTypeOf(result).toEqualTypeOf();
|
|
9
9
|
return result;
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
test("notification category narrows extra and next() result", () => {
|
|
13
|
-
|
|
13
|
+
app.mcpMiddleware("notification", async (_request, extra, next) => {
|
|
14
14
|
expectTypeOf(extra).toEqualTypeOf();
|
|
15
15
|
// @ts-expect-error extra is undefined, cannot access .signal
|
|
16
16
|
extra.signal;
|
|
@@ -19,7 +19,7 @@ test("notification category narrows extra and next() result", () => {
|
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
test("exact method tools/call narrows params, extra, and next() result", () => {
|
|
22
|
-
|
|
22
|
+
app.mcpMiddleware("tools/call", async (request, extra, next) => {
|
|
23
23
|
expectTypeOf(request.params.name).toBeString();
|
|
24
24
|
expectTypeOf(extra).toEqualTypeOf();
|
|
25
25
|
const result = await next();
|
|
@@ -28,14 +28,14 @@ test("exact method tools/call narrows params, extra, and next() result", () => {
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
test("exact method tools/list narrows next() to ListToolsResult", () => {
|
|
31
|
-
|
|
31
|
+
app.mcpMiddleware("tools/list", async (_request, _extra, next) => {
|
|
32
32
|
const result = await next();
|
|
33
33
|
expectTypeOf(result).toEqualTypeOf();
|
|
34
34
|
return result;
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
test("exact notification method narrows extra and next() result", () => {
|
|
38
|
-
|
|
38
|
+
app.mcpMiddleware("notifications/initialized", async (_request, extra, next) => {
|
|
39
39
|
expectTypeOf(extra).toEqualTypeOf();
|
|
40
40
|
// @ts-expect-error extra is undefined
|
|
41
41
|
extra.signal;
|
|
@@ -56,7 +56,7 @@ test("McpResultFor maps methods to correct result types", () => {
|
|
|
56
56
|
expectTypeOf().toEqualTypeOf();
|
|
57
57
|
});
|
|
58
58
|
test("wildcard tools/* narrows next() to union of tools result types", () => {
|
|
59
|
-
|
|
59
|
+
app.mcpMiddleware("tools/*", async (_request, _extra, next) => {
|
|
60
60
|
const result = await next();
|
|
61
61
|
expectTypeOf(result).toEqualTypeOf();
|
|
62
62
|
return result;
|
|
@@ -66,7 +66,7 @@ test("McpResultFor resolves wildcards to union of matching result types", () =>
|
|
|
66
66
|
expectTypeOf().toEqualTypeOf();
|
|
67
67
|
});
|
|
68
68
|
test("catch-all middleware has no narrowing on extra or params", () => {
|
|
69
|
-
|
|
69
|
+
app.mcpMiddleware((_request, extra, next) => {
|
|
70
70
|
expectTypeOf(extra).toEqualTypeOf();
|
|
71
71
|
expectTypeOf(_request.params).toEqualTypeOf();
|
|
72
72
|
return next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.test-d.js","sourceRoot":"","sources":["../../src/server/middleware.test-d.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,MAAM,
|
|
1
|
+
{"version":3,"file":"middleware.test-d.js","sourceRoot":"","sources":["../../src/server/middleware.test-d.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n CallToolResult,\n ListToolsResult,\n ServerResult,\n} from \"@modelcontextprotocol/server\";\nimport { expectTypeOf, test } from \"vitest\";\nimport type { Skybridge } from \"./app.js\";\nimport type {\n McpExtra,\n McpResultFor,\n McpTypedMiddlewareFn,\n} from \"./middleware.js\";\n\nconst app = null as unknown as Skybridge;\n\ntest(\"request category narrows extra and next() result\", () => {\n app.mcpMiddleware(\"request\", async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<McpExtra>();\n extra.mcpReq.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ServerResult>();\n return result;\n });\n});\n\ntest(\"notification category narrows extra and next() result\", () => {\n app.mcpMiddleware(\"notification\", async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<undefined>();\n // @ts-expect-error extra is undefined, cannot access .signal\n extra.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<undefined>();\n });\n});\n\ntest(\"exact method tools/call narrows params, extra, and next() result\", () => {\n app.mcpMiddleware(\"tools/call\", async (request, extra, next) => {\n expectTypeOf(request.params.name).toBeString();\n expectTypeOf(extra).toEqualTypeOf<McpExtra>();\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<CallToolResult>();\n return result;\n });\n});\n\ntest(\"exact method tools/list narrows next() to ListToolsResult\", () => {\n app.mcpMiddleware(\"tools/list\", async (_request, _extra, next) => {\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ListToolsResult>();\n return result;\n });\n});\n\ntest(\"exact notification method narrows extra and next() result\", () => {\n app.mcpMiddleware(\n \"notifications/initialized\",\n async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<undefined>();\n // @ts-expect-error extra is undefined\n extra.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<undefined>();\n },\n );\n});\n\ntest(\"McpTypedMiddlewareFn narrows params, extra, and next() per method\", () => {\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"tools/call\">>[0][\"params\"][\"name\"]\n >().toBeString();\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"tools/call\">>[1]\n >().toEqualTypeOf<McpExtra>();\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"notifications/initialized\">>[1]\n >().toEqualTypeOf<undefined>();\n expectTypeOf<\n ReturnType<Parameters<McpTypedMiddlewareFn<\"tools/list\">>[2]>\n >().toEqualTypeOf<Promise<ListToolsResult>>();\n expectTypeOf<\n ReturnType<Parameters<McpTypedMiddlewareFn<\"notifications/initialized\">>[2]>\n >().toEqualTypeOf<Promise<undefined>>();\n});\n\ntest(\"McpResultFor maps methods to correct result types\", () => {\n expectTypeOf<McpResultFor<\"tools/list\">>().toEqualTypeOf<ListToolsResult>();\n expectTypeOf<McpResultFor<\"tools/call\">>().toEqualTypeOf<CallToolResult>();\n expectTypeOf<\n McpResultFor<\"notifications/initialized\">\n >().toEqualTypeOf<undefined>();\n});\n\ntest(\"wildcard tools/* narrows next() to union of tools result types\", () => {\n app.mcpMiddleware(\"tools/*\", async (_request, _extra, next) => {\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ListToolsResult | CallToolResult>();\n return result;\n });\n});\n\ntest(\"McpResultFor resolves wildcards to union of matching result types\", () => {\n expectTypeOf<McpResultFor<\"tools/*\">>().toEqualTypeOf<\n ListToolsResult | CallToolResult\n >();\n});\n\ntest(\"catch-all middleware has no narrowing on extra or params\", () => {\n app.mcpMiddleware((_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<McpExtra | undefined>();\n expectTypeOf(_request.params).toEqualTypeOf<Record<string, unknown>>();\n return next();\n });\n});\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/
|
|
2
|
-
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
1
|
+
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
3
2
|
import { describe, expect, it, vi } from "vitest";
|
|
4
3
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Skybridge } from "./app.js";
|
|
5
|
+
import { buildMiddlewareChain, getHandlerMaps, getToolError, matchesFilter, } from "./middleware.js";
|
|
7
6
|
// ---------------------------------------------------------------------------
|
|
8
7
|
// matchesFilter
|
|
9
8
|
// ---------------------------------------------------------------------------
|
|
@@ -201,36 +200,39 @@ describe("buildMiddlewareChain", () => {
|
|
|
201
200
|
});
|
|
202
201
|
});
|
|
203
202
|
// ---------------------------------------------------------------------------
|
|
204
|
-
//
|
|
203
|
+
// Skybridge.mcpMiddleware() integration tests
|
|
205
204
|
// ---------------------------------------------------------------------------
|
|
206
|
-
describe("
|
|
205
|
+
describe("Skybridge.mcpMiddleware()", () => {
|
|
207
206
|
function createClient() {
|
|
208
207
|
return new Client({ name: "test-client", version: "1.0.0" });
|
|
209
208
|
}
|
|
210
209
|
it("returns this for chaining", () => {
|
|
211
|
-
const
|
|
212
|
-
const result =
|
|
213
|
-
expect(result).toBe(
|
|
210
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => server);
|
|
211
|
+
const result = app.mcpMiddleware(async (_req, _extra, next) => next());
|
|
212
|
+
expect(result).toBe(app);
|
|
214
213
|
});
|
|
215
214
|
it("intercepts tools/call and exposes request params", async () => {
|
|
216
215
|
let capturedMethod = "";
|
|
217
216
|
let capturedParams = {};
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
218
|
+
server.registerTool({
|
|
219
|
+
name: "greet",
|
|
220
|
+
description: "greet",
|
|
221
|
+
inputSchema: { name: z.string() },
|
|
222
|
+
}, (args) => ({
|
|
223
|
+
content: [{ type: "text", text: `hi ${args.name}` }],
|
|
224
|
+
}));
|
|
225
|
+
return server;
|
|
226
|
+
});
|
|
227
|
+
app.mcpMiddleware("tools/call", async (request, _extra, next) => {
|
|
227
228
|
capturedMethod = request.method;
|
|
228
229
|
capturedParams = request.params;
|
|
229
230
|
return next();
|
|
230
231
|
});
|
|
231
232
|
const client = createClient();
|
|
232
233
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
233
|
-
|
|
234
|
+
const instance = app.createServerInstance();
|
|
235
|
+
await instance.connect(serverTransport);
|
|
234
236
|
await client.connect(clientTransport);
|
|
235
237
|
const result = await client.callTool({
|
|
236
238
|
name: "greet",
|
|
@@ -243,48 +245,54 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
243
245
|
});
|
|
244
246
|
expect(result.content).toEqual([{ type: "text", text: "hi World" }]);
|
|
245
247
|
await client.close();
|
|
246
|
-
await
|
|
248
|
+
await instance.close();
|
|
247
249
|
});
|
|
248
250
|
it("array filter works", async () => {
|
|
249
251
|
const matchedMethods = [];
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
253
|
+
server.registerTool({ name: "t1", description: "t1" }, () => ({
|
|
254
|
+
content: [{ type: "text", text: "ok" }],
|
|
255
|
+
}));
|
|
256
|
+
return server;
|
|
257
|
+
});
|
|
258
|
+
app.mcpMiddleware(["tools/call", "tools/list"], async (request, _extra, next) => {
|
|
255
259
|
matchedMethods.push(request.method);
|
|
256
260
|
return next();
|
|
257
261
|
});
|
|
258
262
|
const client = createClient();
|
|
259
263
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
260
|
-
|
|
264
|
+
const instance = app.createServerInstance();
|
|
265
|
+
await instance.connect(serverTransport);
|
|
261
266
|
await client.connect(clientTransport);
|
|
262
267
|
await client.listTools();
|
|
263
268
|
await client.callTool({ name: "t1" });
|
|
264
269
|
expect(matchedMethods).toEqual(["tools/list", "tools/call"]);
|
|
265
270
|
await client.close();
|
|
266
|
-
await
|
|
271
|
+
await instance.close();
|
|
267
272
|
});
|
|
268
273
|
it("throws if registered after connect()", async () => {
|
|
269
|
-
const
|
|
274
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => server);
|
|
270
275
|
const [_clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
276
|
+
const instance = app.createServerInstance();
|
|
277
|
+
await instance.connect(serverTransport);
|
|
278
|
+
expect(() => app.mcpMiddleware(async (_req, _extra, next) => next())).toThrow("Cannot register MCP middleware after run() or connect()");
|
|
279
|
+
await instance.close();
|
|
274
280
|
});
|
|
275
281
|
it("throws when filter provided without handler", () => {
|
|
276
|
-
const
|
|
282
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => server);
|
|
277
283
|
expect(() =>
|
|
278
284
|
// @ts-expect-error intentionally passing filter without handler
|
|
279
|
-
|
|
285
|
+
app.mcpMiddleware("tools/call")).toThrow("mcpMiddleware requires a handler function");
|
|
280
286
|
});
|
|
281
287
|
it("catch-all middleware + filtered middleware stack correctly", async () => {
|
|
282
288
|
const calls = [];
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
289
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
290
|
+
server.registerTool({ name: "t1", description: "t1" }, () => ({
|
|
291
|
+
content: [{ type: "text", text: "ok" }],
|
|
292
|
+
}));
|
|
293
|
+
return server;
|
|
294
|
+
});
|
|
295
|
+
app
|
|
288
296
|
.mcpMiddleware(async (request, _extra, next) => {
|
|
289
297
|
calls.push(`global:${request.method}`);
|
|
290
298
|
return next();
|
|
@@ -295,7 +303,8 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
295
303
|
});
|
|
296
304
|
const client = createClient();
|
|
297
305
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
298
|
-
|
|
306
|
+
const instance = app.createServerInstance();
|
|
307
|
+
await instance.connect(serverTransport);
|
|
299
308
|
await client.connect(clientTransport);
|
|
300
309
|
await client.listTools();
|
|
301
310
|
await client.callTool({ name: "t1" });
|
|
@@ -309,41 +318,47 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
309
318
|
const toolsCallIdx = calls.indexOf("global:tools/call");
|
|
310
319
|
expect(calls[toolsCallIdx + 1]).toBe("tools-only");
|
|
311
320
|
await client.close();
|
|
312
|
-
await
|
|
321
|
+
await instance.close();
|
|
313
322
|
});
|
|
314
323
|
it("notification middleware receives extra as undefined", async () => {
|
|
315
324
|
let capturedExtra = "sentinel";
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
325
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
326
|
+
server.registerTool({ name: "t1", description: "t1" }, () => ({
|
|
327
|
+
content: [{ type: "text", text: "ok" }],
|
|
328
|
+
}));
|
|
329
|
+
return server;
|
|
330
|
+
});
|
|
331
|
+
app.mcpMiddleware("notification", async (_request, extra, next) => {
|
|
321
332
|
capturedExtra = extra;
|
|
322
333
|
return next();
|
|
323
334
|
});
|
|
324
335
|
const client = createClient();
|
|
325
336
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
326
|
-
|
|
337
|
+
const instance = app.createServerInstance();
|
|
338
|
+
await instance.connect(serverTransport);
|
|
327
339
|
await client.connect(clientTransport);
|
|
328
340
|
// The client sends notifications/initialized automatically on connect.
|
|
329
341
|
await client.listTools();
|
|
330
342
|
expect(capturedExtra).toBeUndefined();
|
|
331
343
|
await client.close();
|
|
332
|
-
await
|
|
344
|
+
await instance.close();
|
|
333
345
|
});
|
|
334
346
|
it("wildcard filter intercepts matching methods only", async () => {
|
|
335
347
|
const matchedMethods = [];
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
348
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
349
|
+
server.registerTool({ name: "t1", description: "t1" }, () => ({
|
|
350
|
+
content: [{ type: "text", text: "ok" }],
|
|
351
|
+
}));
|
|
352
|
+
return server;
|
|
353
|
+
});
|
|
354
|
+
app.mcpMiddleware("tools/*", async (request, _extra, next) => {
|
|
341
355
|
matchedMethods.push(request.method);
|
|
342
356
|
return next();
|
|
343
357
|
});
|
|
344
358
|
const client = createClient();
|
|
345
359
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
346
|
-
|
|
360
|
+
const instance = app.createServerInstance();
|
|
361
|
+
await instance.connect(serverTransport);
|
|
347
362
|
await client.connect(clientTransport);
|
|
348
363
|
await client.listTools();
|
|
349
364
|
await client.callTool({ name: "t1" });
|
|
@@ -353,18 +368,20 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
353
368
|
expect(matchedMethods).not.toContain("initialize");
|
|
354
369
|
expect(matchedMethods).not.toContain("notifications/initialized");
|
|
355
370
|
await client.close();
|
|
356
|
-
await
|
|
357
|
-
});
|
|
358
|
-
it("middleware can modify tool result via
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
371
|
+
await instance.close();
|
|
372
|
+
});
|
|
373
|
+
it("middleware can modify tool result via Skybridge integration", async () => {
|
|
374
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
375
|
+
server.registerTool({
|
|
376
|
+
name: "greet",
|
|
377
|
+
description: "greet",
|
|
378
|
+
inputSchema: { name: z.string() },
|
|
379
|
+
}, (args) => ({
|
|
380
|
+
content: [{ type: "text", text: `hi ${args.name}` }],
|
|
381
|
+
}));
|
|
382
|
+
return server;
|
|
383
|
+
});
|
|
384
|
+
app.mcpMiddleware("tools/call", async (_req, _extra, next) => {
|
|
368
385
|
const result = (await next());
|
|
369
386
|
return {
|
|
370
387
|
...result,
|
|
@@ -376,7 +393,8 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
376
393
|
});
|
|
377
394
|
const client = createClient();
|
|
378
395
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
379
|
-
|
|
396
|
+
const instance = app.createServerInstance();
|
|
397
|
+
await instance.connect(serverTransport);
|
|
380
398
|
await client.connect(clientTransport);
|
|
381
399
|
const result = await client.callTool({
|
|
382
400
|
name: "greet",
|
|
@@ -387,50 +405,95 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
387
405
|
{ type: "text", text: " (modified)" },
|
|
388
406
|
]);
|
|
389
407
|
await client.close();
|
|
390
|
-
await
|
|
408
|
+
await instance.close();
|
|
391
409
|
});
|
|
392
|
-
it("middleware can short-circuit via
|
|
410
|
+
it("middleware can short-circuit via Skybridge integration", async () => {
|
|
393
411
|
const handlerCalled = vi.fn();
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
412
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
413
|
+
server.registerTool({ name: "t1", description: "t1" }, () => {
|
|
414
|
+
handlerCalled();
|
|
415
|
+
return {
|
|
416
|
+
content: [{ type: "text", text: "original" }],
|
|
417
|
+
};
|
|
418
|
+
});
|
|
419
|
+
return server;
|
|
400
420
|
});
|
|
401
|
-
|
|
421
|
+
app.mcpMiddleware("tools/call", async () => ({
|
|
402
422
|
content: [{ type: "text", text: "short-circuited" }],
|
|
403
423
|
}));
|
|
404
424
|
const client = createClient();
|
|
405
425
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
406
|
-
|
|
426
|
+
const instance = app.createServerInstance();
|
|
427
|
+
await instance.connect(serverTransport);
|
|
407
428
|
await client.connect(clientTransport);
|
|
408
429
|
const result = await client.callTool({ name: "t1" });
|
|
409
430
|
expect(result.content).toEqual([{ type: "text", text: "short-circuited" }]);
|
|
410
431
|
expect(handlerCalled).not.toHaveBeenCalled();
|
|
411
432
|
await client.close();
|
|
412
|
-
await
|
|
433
|
+
await instance.close();
|
|
434
|
+
});
|
|
435
|
+
it("exposes a thrown tool error to middleware via getToolError", async () => {
|
|
436
|
+
const schemaError = new Error("boom with schema");
|
|
437
|
+
const schemalessError = new Error("boom without schema");
|
|
438
|
+
let captured;
|
|
439
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
440
|
+
server.registerTool({
|
|
441
|
+
name: "withSchema",
|
|
442
|
+
description: "withSchema",
|
|
443
|
+
inputSchema: { name: z.string() },
|
|
444
|
+
}, () => {
|
|
445
|
+
throw schemaError;
|
|
446
|
+
});
|
|
447
|
+
server.registerTool({ name: "withoutSchema", description: "withoutSchema" }, () => {
|
|
448
|
+
throw schemalessError;
|
|
449
|
+
});
|
|
450
|
+
return server;
|
|
451
|
+
});
|
|
452
|
+
app.mcpMiddleware("tools/call", async (_request, extra, next) => {
|
|
453
|
+
const result = await next();
|
|
454
|
+
captured = getToolError(extra);
|
|
455
|
+
return result;
|
|
456
|
+
});
|
|
457
|
+
const client = createClient();
|
|
458
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
459
|
+
const instance = app.createServerInstance();
|
|
460
|
+
await instance.connect(serverTransport);
|
|
461
|
+
await client.connect(clientTransport);
|
|
462
|
+
const withSchema = await client.callTool({
|
|
463
|
+
name: "withSchema",
|
|
464
|
+
arguments: { name: "World" },
|
|
465
|
+
});
|
|
466
|
+
expect(withSchema.isError).toBe(true);
|
|
467
|
+
expect(captured).toBe(schemaError);
|
|
468
|
+
const withoutSchema = await client.callTool({ name: "withoutSchema" });
|
|
469
|
+
expect(withoutSchema.isError).toBe(true);
|
|
470
|
+
expect(captured).toBe(schemalessError);
|
|
471
|
+
await client.close();
|
|
472
|
+
await instance.close();
|
|
413
473
|
});
|
|
414
|
-
it("middleware can mutate tool call params via
|
|
474
|
+
it("middleware can mutate tool call params via Skybridge integration", async () => {
|
|
415
475
|
let receivedName = "";
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
476
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
477
|
+
server.registerTool({
|
|
478
|
+
name: "greet",
|
|
479
|
+
description: "greet",
|
|
480
|
+
inputSchema: { name: z.string() },
|
|
481
|
+
}, (args) => {
|
|
482
|
+
receivedName = args.name;
|
|
483
|
+
return {
|
|
484
|
+
content: [{ type: "text", text: `hi ${args.name}` }],
|
|
485
|
+
};
|
|
486
|
+
});
|
|
487
|
+
return server;
|
|
426
488
|
});
|
|
427
|
-
|
|
489
|
+
app.mcpMiddleware("tools/call", async (request, _extra, next) => {
|
|
428
490
|
request.params.arguments = { name: "Overridden" };
|
|
429
491
|
return next();
|
|
430
492
|
});
|
|
431
493
|
const client = createClient();
|
|
432
494
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
433
|
-
|
|
495
|
+
const instance = app.createServerInstance();
|
|
496
|
+
await instance.connect(serverTransport);
|
|
434
497
|
await client.connect(clientTransport);
|
|
435
498
|
await client.callTool({
|
|
436
499
|
name: "greet",
|
|
@@ -438,21 +501,24 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
438
501
|
});
|
|
439
502
|
expect(receivedName).toBe("Overridden");
|
|
440
503
|
await client.close();
|
|
441
|
-
await
|
|
504
|
+
await instance.close();
|
|
442
505
|
});
|
|
443
506
|
it("category 'request' filter matches requests but not notifications", async () => {
|
|
444
507
|
const matchedMethods = [];
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
508
|
+
const app = new Skybridge({ name: "test", version: "1.0.0" }, (server) => {
|
|
509
|
+
server.registerTool({ name: "t1", description: "t1" }, () => ({
|
|
510
|
+
content: [{ type: "text", text: "ok" }],
|
|
511
|
+
}));
|
|
512
|
+
return server;
|
|
513
|
+
});
|
|
514
|
+
app.mcpMiddleware("request", async (request, _extra, next) => {
|
|
450
515
|
matchedMethods.push(request.method);
|
|
451
516
|
return next();
|
|
452
517
|
});
|
|
453
518
|
const client = createClient();
|
|
454
519
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
455
|
-
|
|
520
|
+
const instance = app.createServerInstance();
|
|
521
|
+
await instance.connect(serverTransport);
|
|
456
522
|
await client.connect(clientTransport);
|
|
457
523
|
await client.listTools();
|
|
458
524
|
await client.callTool({ name: "t1" });
|
|
@@ -460,7 +526,7 @@ describe("McpServer.mcpMiddleware()", () => {
|
|
|
460
526
|
expect(matchedMethods).toContain("tools/call");
|
|
461
527
|
expect(matchedMethods).not.toContain("notifications/initialized");
|
|
462
528
|
await client.close();
|
|
463
|
-
await
|
|
529
|
+
await instance.close();
|
|
464
530
|
});
|
|
465
531
|
});
|
|
466
532
|
// ---------------------------------------------------------------------------
|