skybridge 0.0.0-dev.fe3d450 → 0.0.0-dev.fe48ef8
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 +17 -8
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.js +1 -1
- package/dist/cli/header.js.map +1 -1
- package/dist/cli/types.d.ts +5 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/use-messages.d.ts +3 -0
- package/dist/cli/use-messages.js +11 -0
- package/dist/cli/use-messages.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +2 -6
- package/dist/cli/use-nodemon.js +20 -17
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-tunnel.d.ts +14 -0
- package/dist/cli/use-tunnel.js +97 -0
- package/dist/cli/use-tunnel.js.map +1 -0
- package/dist/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +3 -1
- package/dist/commands/dev.js +25 -7
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +36 -15
- package/dist/commands/start.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.d.ts +5 -6
- package/dist/server/asset-base-url-transform-plugin.js +8 -9
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
- package/dist/server/asset-base-url-transform-plugin.test.js +12 -13
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
- package/dist/server/express.d.ts +15 -0
- package/dist/server/express.js +77 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +252 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/metric.d.ts +14 -0
- package/dist/server/metric.js +62 -0
- package/dist/server/metric.js.map +1 -0
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +490 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +52 -1
- package/dist/server/server.js +179 -13
- package/dist/server/server.js.map +1 -1
- package/dist/server/templates/development.hbs +0 -53
- package/dist/server/widgetsDevServer.d.ts +2 -1
- package/dist/server/widgetsDevServer.js +5 -5
- package/dist/server/widgetsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +5 -1
- package/dist/test/utils.js +3 -2
- package/dist/test/utils.js.map +1 -1
- package/dist/test/widget.test.js +98 -19
- package/dist/test/widget.test.js.map +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +7 -5
- package/dist/web/bridges/apps-sdk/adaptor.js +39 -16
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +24 -13
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +16 -4
- package/dist/web/bridges/mcp-app/adaptor.js +121 -38
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +13 -30
- package/dist/web/bridges/mcp-app/bridge.js +43 -196
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +2 -2
- 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 +1 -41
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +15 -4
- package/dist/web/components/modal-provider.js +2 -4
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.js +15 -1
- package/dist/web/create-store.js.map +1 -1
- package/dist/web/create-store.test.js +9 -4
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.test.js +11 -8
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +1 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.js +4 -0
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +3 -3
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +2 -1
- package/dist/web/hooks/use-files.js +1 -0
- package/dist/web/hooks/use-files.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +27 -3
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-layout.test.js +3 -3
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.d.ts +3 -1
- package/dist/web/hooks/use-open-external.js +1 -1
- package/dist/web/hooks/use-open-external.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +26 -11
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +5 -11
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +1 -1
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.js +18 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +29 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-widget-state.test.js +123 -7
- package/dist/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/web/plugin/plugin.js +17 -9
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/transform-data-llm.js +1 -1
- package/dist/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/web/plugin/validate-widget.d.ts +5 -0
- package/dist/web/plugin/validate-widget.js +27 -0
- package/dist/web/plugin/validate-widget.js.map +1 -0
- package/dist/web/plugin/validate-widget.test.d.ts +1 -0
- package/dist/web/plugin/validate-widget.test.js +42 -0
- package/dist/web/plugin/validate-widget.test.js.map +1 -0
- package/dist/web/proxy.js +0 -1
- package/dist/web/proxy.js.map +1 -1
- package/package.json +30 -25
- package/tsconfig.base.json +31 -0
package/dist/commands/start.js
CHANGED
|
@@ -1,33 +1,54 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { existsSync } from "node:fs";
|
|
3
2
|
import { resolve } from "node:path";
|
|
4
|
-
import { Command } from "@oclif/core";
|
|
5
|
-
import {
|
|
6
|
-
import { Header } from "../cli/header.js";
|
|
3
|
+
import { Command, Flags } from "@oclif/core";
|
|
4
|
+
import { resolvePort } from "../cli/detect-port.js";
|
|
7
5
|
import { runCommand } from "../cli/run-command.js";
|
|
8
6
|
export default class Start extends Command {
|
|
9
7
|
static description = "Start production server";
|
|
10
8
|
static examples = ["skybridge start"];
|
|
11
|
-
static flags = {
|
|
9
|
+
static flags = {
|
|
10
|
+
port: Flags.integer({
|
|
11
|
+
char: "p",
|
|
12
|
+
description: "Port to run the server on",
|
|
13
|
+
min: 1,
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
12
16
|
async run() {
|
|
17
|
+
const { flags } = await this.parse(Start);
|
|
18
|
+
const { port, fallback, envWarning } = await resolvePort(flags.port);
|
|
19
|
+
if (envWarning) {
|
|
20
|
+
this.warn(envWarning);
|
|
21
|
+
}
|
|
13
22
|
console.clear();
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
const candidates = [
|
|
24
|
+
resolve(process.cwd(), "dist/server/src/index.js"),
|
|
25
|
+
resolve(process.cwd(), "dist/index.js"),
|
|
26
|
+
];
|
|
27
|
+
const indexPath = candidates.find(existsSync);
|
|
28
|
+
if (!indexPath) {
|
|
29
|
+
console.error("❌ Error: No build output found");
|
|
17
30
|
console.error("");
|
|
18
31
|
console.error("Please build your project first:");
|
|
19
32
|
console.error(" skybridge build");
|
|
20
33
|
console.error("");
|
|
21
34
|
process.exit(1);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.log(`\x1b[36m\x1b[1m⛰ Skybridge\x1b[0m \x1b[36mv${this.config.version}\x1b[0m`);
|
|
38
|
+
if (fallback) {
|
|
39
|
+
console.log(`\x1b[33m3000 in use, running on\x1b[0m \x1b[32mhttp://localhost:${port}/mcp\x1b[0m`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(`Running on \x1b[32mhttp://localhost:${port}/mcp\x1b[0m`);
|
|
22
43
|
}
|
|
23
|
-
runCommand(
|
|
24
|
-
stdio: ["ignore", "
|
|
25
|
-
env: {
|
|
44
|
+
await runCommand(`node ${indexPath}`, {
|
|
45
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
46
|
+
env: {
|
|
47
|
+
...process.env,
|
|
48
|
+
NODE_ENV: "production",
|
|
49
|
+
__PORT: String(port),
|
|
50
|
+
},
|
|
26
51
|
});
|
|
27
|
-
const App = () => {
|
|
28
|
-
return (_jsxs(Box, { flexDirection: "column", padding: 1, marginLeft: 1, children: [_jsx(Header, { version: this.config.version }), _jsxs(Box, { children: [_jsx(Text, { children: "Server running at: " }), _jsx(Text, { color: "green", bold: true, children: "http://localhost:3000/mcp" })] })] }));
|
|
29
|
-
};
|
|
30
|
-
render(_jsx(App, {}), { exitOnCtrlC: true, patchConsole: false });
|
|
31
52
|
}
|
|
32
53
|
}
|
|
33
54
|
//# sourceMappingURL=start.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,MAAM,CAAU,WAAW,GAAG,yBAAyB,CAAC;IACxD,MAAM,CAAU,QAAQ,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC/C,MAAM,CAAU,KAAK,GAAG;QACtB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC;YAClB,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,2BAA2B;YACxC,GAAG,EAAE,CAAC;SACP,CAAC;KACH,CAAC;IAEK,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrE,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxB,CA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
|
-
* Transforms asset import paths to
|
|
3
|
+
* Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
|
|
4
|
+
* so they work both locally and behind tunnels.
|
|
4
5
|
*/
|
|
5
|
-
export declare function assetBaseUrlTransform(code: string
|
|
6
|
+
export declare function assetBaseUrlTransform(code: string): string;
|
|
6
7
|
/**
|
|
7
|
-
* Vite plugin that transforms asset import paths to
|
|
8
|
+
* Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
|
|
8
9
|
*/
|
|
9
|
-
export declare function assetBaseUrlTransformPlugin(
|
|
10
|
-
devServerOrigin: string;
|
|
11
|
-
}): Plugin;
|
|
10
|
+
export declare function assetBaseUrlTransformPlugin(): Plugin;
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Transforms asset import paths to
|
|
2
|
+
* Transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`,
|
|
3
|
+
* so they work both locally and behind tunnels.
|
|
3
4
|
*/
|
|
4
|
-
export function assetBaseUrlTransform(code
|
|
5
|
+
export function assetBaseUrlTransform(code) {
|
|
5
6
|
const assetStringPattern = /(?<!https?:\/\/)(["'`])(\/[^"'`]+\.(svg|png|jpeg|jpg|gif|webp|mp3|mp4|woff|woff2|ttf|eot))\1/g;
|
|
6
|
-
code = code.replace(assetStringPattern, (_match,
|
|
7
|
-
return
|
|
7
|
+
code = code.replace(assetStringPattern, (_match, _quote, assetPath) => {
|
|
8
|
+
return `(window.skybridge?.serverUrl ?? "") + "${assetPath}"`;
|
|
8
9
|
});
|
|
9
10
|
return code;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
|
-
* Vite plugin that transforms asset import paths to
|
|
13
|
+
* Vite plugin that transforms asset import paths to resolve at runtime via `window.skybridge.serverUrl`.
|
|
13
14
|
*/
|
|
14
|
-
export function assetBaseUrlTransformPlugin(
|
|
15
|
-
const { devServerOrigin } = options;
|
|
15
|
+
export function assetBaseUrlTransformPlugin() {
|
|
16
16
|
return {
|
|
17
17
|
name: "asset-base-url-transform",
|
|
18
|
-
enforce: "pre",
|
|
19
18
|
transform(code) {
|
|
20
19
|
if (!code) {
|
|
21
20
|
return null;
|
|
22
21
|
}
|
|
23
|
-
const transformedCode = assetBaseUrlTransform(code
|
|
22
|
+
const transformedCode = assetBaseUrlTransform(code);
|
|
24
23
|
if (transformedCode === code) {
|
|
25
24
|
return null;
|
|
26
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-base-url-transform-plugin.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"asset-base-url-transform-plugin.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,kBAAkB,GACtB,+FAA+F,CAAC;IAElG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE;QACpE,OAAO,0CAA0C,SAAS,GAAG,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,SAAS,CAAC,IAAI;YACZ,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAEpD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE,IAAI;aACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { assetBaseUrlTransform } from "./asset-base-url-transform-plugin.js";
|
|
3
3
|
describe("assetBaseUrlTransform", () => {
|
|
4
|
-
|
|
5
|
-
it("should transform asset paths in single, double, and backtick quotes", () => {
|
|
4
|
+
it("should transform asset paths to use window.skybridge.serverUrl", () => {
|
|
6
5
|
const cases = [
|
|
7
6
|
{
|
|
8
7
|
desc: "single-quoted",
|
|
9
8
|
code: `const image = '/assets/logo.png';`,
|
|
10
|
-
expected: `const image =
|
|
9
|
+
expected: `const image = (window.skybridge?.serverUrl ?? "") + "/assets/logo.png";`,
|
|
11
10
|
},
|
|
12
11
|
{
|
|
13
12
|
desc: "double-quoted",
|
|
14
13
|
code: `const image = "/assets/logo.png";`,
|
|
15
|
-
expected: `const image = "
|
|
14
|
+
expected: `const image = (window.skybridge?.serverUrl ?? "") + "/assets/logo.png";`,
|
|
16
15
|
},
|
|
17
16
|
{
|
|
18
17
|
desc: "backtick-quoted",
|
|
19
18
|
code: "const image = `/assets/logo.png`;",
|
|
20
|
-
expected: `const image =
|
|
19
|
+
expected: `const image = (window.skybridge?.serverUrl ?? "") + "/assets/logo.png";`,
|
|
21
20
|
},
|
|
22
21
|
];
|
|
23
22
|
for (const { code, expected } of cases) {
|
|
24
|
-
const result = assetBaseUrlTransform(code
|
|
23
|
+
const result = assetBaseUrlTransform(code);
|
|
25
24
|
expect(result).toBe(expected);
|
|
26
25
|
}
|
|
27
26
|
});
|
|
@@ -31,10 +30,10 @@ describe("assetBaseUrlTransform", () => {
|
|
|
31
30
|
const icon = '/assets/icon.svg';
|
|
32
31
|
const font = '/assets/font.woff2';
|
|
33
32
|
`;
|
|
34
|
-
const result = assetBaseUrlTransform(code
|
|
35
|
-
expect(result).toContain(
|
|
36
|
-
expect(result).toContain(
|
|
37
|
-
expect(result).toContain(
|
|
33
|
+
const result = assetBaseUrlTransform(code);
|
|
34
|
+
expect(result).toContain(`(window.skybridge?.serverUrl ?? "") + "/assets/logo.png"`);
|
|
35
|
+
expect(result).toContain(`(window.skybridge?.serverUrl ?? "") + "/assets/icon.svg"`);
|
|
36
|
+
expect(result).toContain(`(window.skybridge?.serverUrl ?? "") + "/assets/font.woff2"`);
|
|
38
37
|
});
|
|
39
38
|
it("should not transform already absolute URLs", () => {
|
|
40
39
|
const code = `
|
|
@@ -42,14 +41,14 @@ describe("assetBaseUrlTransform", () => {
|
|
|
42
41
|
const http = 'http://example.com/image.png';
|
|
43
42
|
const https = 'https://example.com/image.png';
|
|
44
43
|
`;
|
|
45
|
-
const result = assetBaseUrlTransform(code
|
|
46
|
-
expect(result).toContain(
|
|
44
|
+
const result = assetBaseUrlTransform(code);
|
|
45
|
+
expect(result).toContain(`(window.skybridge?.serverUrl ?? "") + "/assets/logo.png"`);
|
|
47
46
|
expect(result).toContain("http://example.com/image.png");
|
|
48
47
|
expect(result).toContain("https://example.com/image.png");
|
|
49
48
|
});
|
|
50
49
|
it("should not transform code without asset paths", () => {
|
|
51
50
|
const code = `const text = "Hello World";`;
|
|
52
|
-
const result = assetBaseUrlTransform(code
|
|
51
|
+
const result = assetBaseUrlTransform(code);
|
|
53
52
|
expect(result).toBe(code);
|
|
54
53
|
});
|
|
55
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-base-url-transform-plugin.test.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,
|
|
1
|
+
{"version":3,"file":"asset-base-url-transform-plugin.test.js","sourceRoot":"","sources":["../../src/server/asset-base-url-transform-plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,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CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CACtB,0DAA0D,CAC3D,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,IAAI,GAAG,6BAA6B,CAAC;QAC3C,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type http from "node:http";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import type { McpServer } from "./server.js";
|
|
4
|
+
export declare function createApp({ mcpServer, httpServer, customMiddleware, errorMiddleware, }: {
|
|
5
|
+
mcpServer: McpServer;
|
|
6
|
+
httpServer: http.Server;
|
|
7
|
+
customMiddleware?: {
|
|
8
|
+
path?: string;
|
|
9
|
+
handlers: express.RequestHandler[];
|
|
10
|
+
}[];
|
|
11
|
+
errorMiddleware?: {
|
|
12
|
+
path?: string;
|
|
13
|
+
handlers: express.ErrorRequestHandler[];
|
|
14
|
+
}[];
|
|
15
|
+
}): Promise<express.Express>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express from "express";
|
|
5
|
+
function applyMiddlewares(app, middlewares) {
|
|
6
|
+
for (const middleware of middlewares) {
|
|
7
|
+
if (middleware.path) {
|
|
8
|
+
app.use(middleware.path, ...middleware.handlers);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
app.use(...middleware.handlers);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function defaultErrorHandler(err, _req, res, _next) {
|
|
16
|
+
console.error("Error handling MCP request:", err);
|
|
17
|
+
if (!res.headersSent) {
|
|
18
|
+
res.status(500).json({
|
|
19
|
+
jsonrpc: "2.0",
|
|
20
|
+
error: { code: -32603, message: "Internal server error" },
|
|
21
|
+
id: null,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function createApp({ mcpServer, httpServer, customMiddleware = [], errorMiddleware = [], }) {
|
|
26
|
+
const app = express();
|
|
27
|
+
app.use(express.json());
|
|
28
|
+
const env = process.env.NODE_ENV || "development";
|
|
29
|
+
applyMiddlewares(app, customMiddleware);
|
|
30
|
+
if (env !== "production") {
|
|
31
|
+
const { devtoolsStaticServer } = await import("@skybridge/devtools");
|
|
32
|
+
app.use(await devtoolsStaticServer());
|
|
33
|
+
const { widgetsDevServer } = await import("./widgetsDevServer.js");
|
|
34
|
+
app.use(await widgetsDevServer(httpServer));
|
|
35
|
+
}
|
|
36
|
+
if (env === "production") {
|
|
37
|
+
const assetsPath = path.join(process.cwd(), "dist", "assets");
|
|
38
|
+
app.use("/assets", cors());
|
|
39
|
+
app.use("/assets", express.static(assetsPath));
|
|
40
|
+
}
|
|
41
|
+
app.use("/mcp", mcpMiddleware(mcpServer));
|
|
42
|
+
applyMiddlewares(app, errorMiddleware);
|
|
43
|
+
app.use("/mcp", defaultErrorHandler);
|
|
44
|
+
return app;
|
|
45
|
+
}
|
|
46
|
+
const mcpMiddleware = (server) => {
|
|
47
|
+
return async (req, res, next) => {
|
|
48
|
+
if (req.method !== "POST") {
|
|
49
|
+
res.writeHead(405).end(JSON.stringify({
|
|
50
|
+
jsonrpc: "2.0",
|
|
51
|
+
error: {
|
|
52
|
+
code: -32000,
|
|
53
|
+
message: "Method not allowed.",
|
|
54
|
+
},
|
|
55
|
+
id: null,
|
|
56
|
+
}));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const transport = new StreamableHTTPServerTransport({
|
|
61
|
+
sessionIdGenerator: undefined,
|
|
62
|
+
});
|
|
63
|
+
res.on("close", () => {
|
|
64
|
+
transport.close();
|
|
65
|
+
});
|
|
66
|
+
await server.connect(transport);
|
|
67
|
+
// Express strips the mount path from req.url (e.g. "/mcp" becomes "/").
|
|
68
|
+
// Restore it so the SDK builds the correct requestInfo.url.
|
|
69
|
+
req.url = req.originalUrl;
|
|
70
|
+
await transport.handleRequest(req, res, req.body);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
next(error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +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,CACvB,GAAoB,EACpB,WAGE;IAEF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;YACpB,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAC1B,GAAY,EACZ,IAAqB,EACrB,GAAqB,EACrB,KAA2B;IAE3B,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE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CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
vi.mock("@skybridge/devtools", () => ({
|
|
4
|
+
devtoolsStaticServer: () => ((_req, _res, next) => next()),
|
|
5
|
+
}));
|
|
6
|
+
vi.mock("./widgetsDevServer.js", () => ({
|
|
7
|
+
widgetsDevServer: (_httpServer) => ((_req, _res, next) => next()),
|
|
8
|
+
}));
|
|
9
|
+
const fakeServer = {};
|
|
10
|
+
async function listen(app) {
|
|
11
|
+
const server = http.createServer(app);
|
|
12
|
+
await new Promise((resolve) => server.listen(0, resolve));
|
|
13
|
+
const port = server.address().port;
|
|
14
|
+
return { port, server };
|
|
15
|
+
}
|
|
16
|
+
let openServer;
|
|
17
|
+
afterEach(() => openServer?.close());
|
|
18
|
+
async function postMcp(port) {
|
|
19
|
+
return fetch(`http://localhost:${port}/mcp`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json" },
|
|
22
|
+
body: JSON.stringify({ jsonrpc: "2.0", method: "initialize", id: 1 }),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function postApi(port) {
|
|
26
|
+
return fetch(`http://localhost:${port}/api/test`, { method: "POST" });
|
|
27
|
+
}
|
|
28
|
+
describe("createApp", () => {
|
|
29
|
+
it("runs global custom middleware before the /mcp handler", async () => {
|
|
30
|
+
const { createApp } = await import("./express.js");
|
|
31
|
+
const calls = [];
|
|
32
|
+
const mw = (_req, _res, next) => {
|
|
33
|
+
calls.push("custom");
|
|
34
|
+
next();
|
|
35
|
+
};
|
|
36
|
+
const httpServer = http.createServer();
|
|
37
|
+
const app = await createApp({
|
|
38
|
+
mcpServer: fakeServer,
|
|
39
|
+
httpServer,
|
|
40
|
+
customMiddleware: [{ handlers: [mw] }],
|
|
41
|
+
});
|
|
42
|
+
const { port, server } = await listen(app);
|
|
43
|
+
openServer = server;
|
|
44
|
+
await postMcp(port);
|
|
45
|
+
expect(calls).toEqual(["custom"]);
|
|
46
|
+
});
|
|
47
|
+
it("runs path-scoped middleware on /mcp", async () => {
|
|
48
|
+
const { createApp } = await import("./express.js");
|
|
49
|
+
const calls = [];
|
|
50
|
+
const mw = (_req, _res, next) => {
|
|
51
|
+
calls.push("auth");
|
|
52
|
+
next();
|
|
53
|
+
};
|
|
54
|
+
const httpServer = http.createServer();
|
|
55
|
+
const app = await createApp({
|
|
56
|
+
mcpServer: fakeServer,
|
|
57
|
+
httpServer,
|
|
58
|
+
customMiddleware: [{ path: "/mcp", handlers: [mw] }],
|
|
59
|
+
});
|
|
60
|
+
const { port, server } = await listen(app);
|
|
61
|
+
openServer = server;
|
|
62
|
+
await postMcp(port);
|
|
63
|
+
expect(calls).toEqual(["auth"]);
|
|
64
|
+
});
|
|
65
|
+
it("allows middleware to short-circuit with 401", async () => {
|
|
66
|
+
const { createApp } = await import("./express.js");
|
|
67
|
+
const calls = [];
|
|
68
|
+
const reject = (_req, res) => {
|
|
69
|
+
calls.push("reject");
|
|
70
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
71
|
+
};
|
|
72
|
+
const httpServer = http.createServer();
|
|
73
|
+
const app = await createApp({
|
|
74
|
+
mcpServer: fakeServer,
|
|
75
|
+
httpServer,
|
|
76
|
+
customMiddleware: [{ path: "/mcp", handlers: [reject] }],
|
|
77
|
+
});
|
|
78
|
+
const { port, server } = await listen(app);
|
|
79
|
+
openServer = server;
|
|
80
|
+
const res = await postMcp(port);
|
|
81
|
+
expect(calls).toEqual(["reject"]);
|
|
82
|
+
expect(res.status).toBe(401);
|
|
83
|
+
expect(await res.json()).toEqual({ error: "Unauthorized" });
|
|
84
|
+
});
|
|
85
|
+
it("runs multiple global middleware in registration order", async () => {
|
|
86
|
+
const { createApp } = await import("./express.js");
|
|
87
|
+
const calls = [];
|
|
88
|
+
const mwA = (_req, _res, next) => {
|
|
89
|
+
calls.push("A");
|
|
90
|
+
next();
|
|
91
|
+
};
|
|
92
|
+
const mwB = (_req, _res, next) => {
|
|
93
|
+
calls.push("B");
|
|
94
|
+
next();
|
|
95
|
+
};
|
|
96
|
+
const httpServer = http.createServer();
|
|
97
|
+
const app = await createApp({
|
|
98
|
+
mcpServer: fakeServer,
|
|
99
|
+
httpServer,
|
|
100
|
+
customMiddleware: [{ handlers: [mwA] }, { handlers: [mwB] }],
|
|
101
|
+
});
|
|
102
|
+
const { port, server } = await listen(app);
|
|
103
|
+
openServer = server;
|
|
104
|
+
await postMcp(port);
|
|
105
|
+
expect(calls).toEqual(["A", "B"]);
|
|
106
|
+
});
|
|
107
|
+
it("path-scoped middleware does not run on non-matching paths", async () => {
|
|
108
|
+
const { createApp } = await import("./express.js");
|
|
109
|
+
const calls = [];
|
|
110
|
+
const apiMw = (_req, _res, next) => {
|
|
111
|
+
calls.push("api");
|
|
112
|
+
next();
|
|
113
|
+
};
|
|
114
|
+
const httpServer = http.createServer();
|
|
115
|
+
const app = await createApp({
|
|
116
|
+
mcpServer: fakeServer,
|
|
117
|
+
httpServer,
|
|
118
|
+
customMiddleware: [{ path: "/api", handlers: [apiMw] }],
|
|
119
|
+
});
|
|
120
|
+
const { port, server } = await listen(app);
|
|
121
|
+
openServer = server;
|
|
122
|
+
// Hit /mcp — the /api middleware should NOT fire
|
|
123
|
+
await postMcp(port);
|
|
124
|
+
expect(calls).toEqual([]);
|
|
125
|
+
});
|
|
126
|
+
it("supports Express Router via custom middleware", async () => {
|
|
127
|
+
const { createApp } = await import("./express.js");
|
|
128
|
+
const { Router } = await import("express");
|
|
129
|
+
const router = Router();
|
|
130
|
+
router.get("/health", (_req, res) => {
|
|
131
|
+
res.json({ status: "ok" });
|
|
132
|
+
});
|
|
133
|
+
const httpServer = http.createServer();
|
|
134
|
+
const app = await createApp({
|
|
135
|
+
mcpServer: fakeServer,
|
|
136
|
+
httpServer,
|
|
137
|
+
customMiddleware: [{ handlers: [router] }],
|
|
138
|
+
});
|
|
139
|
+
const { port, server } = await listen(app);
|
|
140
|
+
openServer = server;
|
|
141
|
+
const res = await fetch(`http://localhost:${port}/health`);
|
|
142
|
+
expect(res.status).toBe(200);
|
|
143
|
+
expect(await res.json()).toEqual({ status: "ok" });
|
|
144
|
+
});
|
|
145
|
+
it("supports path-prefixed Router", async () => {
|
|
146
|
+
const { createApp } = await import("./express.js");
|
|
147
|
+
const { Router } = await import("express");
|
|
148
|
+
const router = Router();
|
|
149
|
+
router.get("/data", (_req, res) => {
|
|
150
|
+
res.json({ value: 42 });
|
|
151
|
+
});
|
|
152
|
+
const httpServer = http.createServer();
|
|
153
|
+
const app = await createApp({
|
|
154
|
+
mcpServer: fakeServer,
|
|
155
|
+
httpServer,
|
|
156
|
+
customMiddleware: [
|
|
157
|
+
{ path: "/api", handlers: [router] },
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
const { port, server } = await listen(app);
|
|
161
|
+
openServer = server;
|
|
162
|
+
const res = await fetch(`http://localhost:${port}/api/data`);
|
|
163
|
+
expect(res.status).toBe(200);
|
|
164
|
+
expect(await res.json()).toEqual({ value: 42 });
|
|
165
|
+
});
|
|
166
|
+
it("server survives middleware errors without crashing", async () => {
|
|
167
|
+
const { createApp } = await import("./express.js");
|
|
168
|
+
const throwing = () => {
|
|
169
|
+
throw new Error("boom");
|
|
170
|
+
};
|
|
171
|
+
const httpServer = http.createServer();
|
|
172
|
+
const app = await createApp({
|
|
173
|
+
mcpServer: fakeServer,
|
|
174
|
+
httpServer,
|
|
175
|
+
customMiddleware: [{ path: "/explode", handlers: [throwing] }],
|
|
176
|
+
});
|
|
177
|
+
const { port, server } = await listen(app);
|
|
178
|
+
openServer = server;
|
|
179
|
+
const res = await fetch(`http://localhost:${port}/explode`);
|
|
180
|
+
expect(res.status).toBe(500);
|
|
181
|
+
// Server process did not crash — it still accepts connections
|
|
182
|
+
const followUp = await fetch(`http://localhost:${port}/explode`);
|
|
183
|
+
expect(followUp.status).toBe(500);
|
|
184
|
+
});
|
|
185
|
+
it("returns 500 JSON-RPC error when the MCP handler throws and no error middleware is registered", async () => {
|
|
186
|
+
const { createApp } = await import("./express.js");
|
|
187
|
+
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
188
|
+
const httpServer = http.createServer();
|
|
189
|
+
const app = await createApp({ mcpServer: fakeServer, httpServer });
|
|
190
|
+
const { port, server } = await listen(app);
|
|
191
|
+
openServer = server;
|
|
192
|
+
const res = await postMcp(port);
|
|
193
|
+
expect(res.status).toBe(500);
|
|
194
|
+
expect(await res.json()).toEqual({
|
|
195
|
+
jsonrpc: "2.0",
|
|
196
|
+
error: { code: -32603, message: "Internal server error" },
|
|
197
|
+
id: null,
|
|
198
|
+
});
|
|
199
|
+
expect(consoleSpy).toHaveBeenCalledWith("Error handling MCP request:", expect.any(Error));
|
|
200
|
+
consoleSpy.mockRestore();
|
|
201
|
+
});
|
|
202
|
+
it("invokes a custom error handler when the MCP handler throws", async () => {
|
|
203
|
+
const { createApp } = await import("./express.js");
|
|
204
|
+
const calls = [];
|
|
205
|
+
const errorHandler = (_err, _req, res, _next) => {
|
|
206
|
+
calls.push("error-handler");
|
|
207
|
+
res.status(503).json({ custom: true });
|
|
208
|
+
};
|
|
209
|
+
const httpServer = http.createServer();
|
|
210
|
+
const app = await createApp({
|
|
211
|
+
mcpServer: fakeServer,
|
|
212
|
+
httpServer,
|
|
213
|
+
errorMiddleware: [{ handlers: [errorHandler] }],
|
|
214
|
+
});
|
|
215
|
+
const { port, server } = await listen(app);
|
|
216
|
+
openServer = server;
|
|
217
|
+
const res = await postMcp(port);
|
|
218
|
+
expect(calls).toEqual(["error-handler"]);
|
|
219
|
+
expect(res.status).toBe(503);
|
|
220
|
+
expect(await res.json()).toEqual({ custom: true });
|
|
221
|
+
});
|
|
222
|
+
it("invokes a path-scoped error handler only for matching routes", async () => {
|
|
223
|
+
const { createApp } = await import("./express.js");
|
|
224
|
+
const calls = [];
|
|
225
|
+
const mcpErrorHandler = (_err, _req, res, _next) => {
|
|
226
|
+
calls.push("mcp-error-handler");
|
|
227
|
+
res.status(503).json({ from: "mcp-error-handler" });
|
|
228
|
+
};
|
|
229
|
+
const throwingApiRoute = (_req, _res, next) => {
|
|
230
|
+
next(new Error("api error"));
|
|
231
|
+
};
|
|
232
|
+
const httpServer = http.createServer();
|
|
233
|
+
const app = await createApp({
|
|
234
|
+
mcpServer: fakeServer,
|
|
235
|
+
httpServer,
|
|
236
|
+
customMiddleware: [{ path: "/api/test", handlers: [throwingApiRoute] }],
|
|
237
|
+
errorMiddleware: [{ path: "/mcp", handlers: [mcpErrorHandler] }],
|
|
238
|
+
});
|
|
239
|
+
const { port, server } = await listen(app);
|
|
240
|
+
openServer = server;
|
|
241
|
+
const mcpRes = await postMcp(port);
|
|
242
|
+
expect(calls).toEqual(["mcp-error-handler"]);
|
|
243
|
+
expect(mcpRes.status).toBe(503);
|
|
244
|
+
expect(await mcpRes.json()).toEqual({ from: "mcp-error-handler" });
|
|
245
|
+
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
246
|
+
const apiRes = await postApi(port);
|
|
247
|
+
expect(calls).toEqual(["mcp-error-handler"]);
|
|
248
|
+
expect(apiRes.status).toBe(500);
|
|
249
|
+
consoleSpy.mockRestore();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=express.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.test.js","sourceRoot":"","sources":["../../src/server/express.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAG7D,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAA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M,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAEnE,MAAM,UAAU,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
2
|
+
export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
|
|
2
3
|
export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
|
|
3
4
|
export { McpServer } from "./server.js";
|
|
4
5
|
export { widgetsDevServer } from "./widgetsDevServer.js";
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { McpMiddlewareEntry } from "./middleware.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns an internal MCP middleware entry that emits a DogStatsD counter over UDP
|
|
4
|
+
* for every tool call. Enabled by default; respects the existing telemetry
|
|
5
|
+
* opt-out (SKYBRIDGE_TELEMETRY_DISABLED, DO_NOT_TRACK, or `skybridge telemetry disable`).
|
|
6
|
+
*
|
|
7
|
+
* Returns `null` when the version string contains "-dev" (e.g. development
|
|
8
|
+
* builds) or when the version cannot be parsed into major.minor, so that
|
|
9
|
+
* malformed data does not pollute production metrics.
|
|
10
|
+
*
|
|
11
|
+
* Metric (DogStatsD counter format with tags):
|
|
12
|
+
* Requests:1|c|#version:<major>.<minor> — every tools/call
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMiddlewareEntry(): McpMiddlewareEntry | null;
|