skybridge 0.0.0-dev.af69a09 → 0.0.0-dev.afab68e
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/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/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +12 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.d.ts +3 -1
- package/dist/commands/start.js +32 -8
- package/dist/commands/start.js.map +1 -1
- package/dist/server/const.d.ts +1 -0
- package/dist/server/const.js +2 -0
- package/dist/server/const.js.map +1 -0
- package/dist/server/express.d.ts +5 -1
- package/dist/server/express.js +14 -5
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +74 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/server.d.ts +1 -5
- package/dist/server/server.js +27 -24
- package/dist/server/server.js.map +1 -1
- package/dist/server/widgetsDevServer.js +8 -2
- package/dist/server/widgetsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +3 -223
- package/dist/test/widget.test.js +4 -4
- package/dist/test/widget.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.js +11 -10
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -5
- package/dist/web/bridges/apps-sdk/types.d.ts +2 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.js +6 -4
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +5 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +5 -1
- package/dist/web/hooks/use-files.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/plugin/plugin.js +8 -0
- package/dist/web/plugin/plugin.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/package.json +13 -10
- package/tsconfig.base.json +28 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function resolvePort(flagPort?: number): Promise<{
|
|
2
|
+
port: number;
|
|
3
|
+
fallback: boolean;
|
|
4
|
+
envWarning?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
port: number;
|
|
7
|
+
fallback: boolean;
|
|
8
|
+
envWarning: string;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the given port if available, otherwise lets the OS
|
|
12
|
+
* pick a free port via `listen(0)`.
|
|
13
|
+
*
|
|
14
|
+
* @param host - Bind address for the check. Pass `"localhost"` for
|
|
15
|
+
* services that bind to 127.0.0.1 (e.g. Vite HMR). Omit for
|
|
16
|
+
* services that bind to all interfaces (e.g. the HTTP server).
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectAvailablePort(startPort: number, host?: string): Promise<number>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
const DEFAULT_PORT = 3000;
|
|
3
|
+
export async function resolvePort(flagPort) {
|
|
4
|
+
if (flagPort && flagPort > 1) {
|
|
5
|
+
return { port: flagPort, fallback: false };
|
|
6
|
+
}
|
|
7
|
+
const rawEnv = process.env.PORT;
|
|
8
|
+
if (rawEnv) {
|
|
9
|
+
const parsed = Number(rawEnv);
|
|
10
|
+
if (Number.isInteger(parsed) && parsed > 0) {
|
|
11
|
+
return { port: parsed, fallback: false };
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
port: await detectAvailablePort(DEFAULT_PORT),
|
|
15
|
+
fallback: false,
|
|
16
|
+
envWarning: `Invalid PORT="${rawEnv}", ignoring and using default`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const port = await detectAvailablePort(DEFAULT_PORT);
|
|
20
|
+
return { port, fallback: port !== DEFAULT_PORT };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the given port if available, otherwise lets the OS
|
|
24
|
+
* pick a free port via `listen(0)`.
|
|
25
|
+
*
|
|
26
|
+
* @param host - Bind address for the check. Pass `"localhost"` for
|
|
27
|
+
* services that bind to 127.0.0.1 (e.g. Vite HMR). Omit for
|
|
28
|
+
* services that bind to all interfaces (e.g. the HTTP server).
|
|
29
|
+
*/
|
|
30
|
+
export async function detectAvailablePort(startPort, host) {
|
|
31
|
+
const available = await isPortAvailable(startPort, host);
|
|
32
|
+
if (available) {
|
|
33
|
+
return startPort;
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const server = net.createServer();
|
|
37
|
+
server.once("error", reject);
|
|
38
|
+
server.once("listening", () => {
|
|
39
|
+
const addr = server.address();
|
|
40
|
+
if (addr && typeof addr === "object") {
|
|
41
|
+
const { port } = addr;
|
|
42
|
+
server.close(() => resolve(port));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
server.close(() => reject(new Error("Failed to detect available port")));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
server.listen(0, host);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function isPortAvailable(port, host) {
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
const server = net.createServer();
|
|
54
|
+
server.once("error", () => resolve(false));
|
|
55
|
+
server.once("listening", () => {
|
|
56
|
+
server.close(() => resolve(true));
|
|
57
|
+
});
|
|
58
|
+
server.listen(port, host);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61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B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/commands/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAoB,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEhF,MAAM,CAAC,MAAM,YAAY,GAAkB;IACzC;QACE,KAAK,EAAE,kBAAkB;QACzB,OAAO,EAAE,kCAAkC;KAC5C;IACD;QACE,KAAK,EAAE,kBAAkB;QACzB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAoB,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEhF,MAAM,CAAC,MAAM,YAAY,GAAkB;IACzC;QACE,KAAK,EAAE,kBAAk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AK;SACpB,CAAC,CAAC;IACL,CAAC"}
|
package/dist/commands/dev.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export default class Dev extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
7
|
"use-forwarded-host": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
8
|
};
|
|
8
9
|
run(): Promise<void>;
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Command, Flags } from "@oclif/core";
|
|
3
3
|
import { Box, render, Text } from "ink";
|
|
4
|
+
import { resolvePort } from "../cli/detect-port.js";
|
|
4
5
|
import { Header } from "../cli/header.js";
|
|
5
6
|
import { useNodemon } from "../cli/use-nodemon.js";
|
|
6
7
|
import { useTypeScriptCheck } from "../cli/use-typescript-check.js";
|
|
@@ -8,14 +9,24 @@ export default class Dev extends Command {
|
|
|
8
9
|
static description = "Start development server";
|
|
9
10
|
static examples = ["skybridge"];
|
|
10
11
|
static flags = {
|
|
12
|
+
port: Flags.integer({
|
|
13
|
+
char: "p",
|
|
14
|
+
description: "Port to run the server on",
|
|
15
|
+
min: 1,
|
|
16
|
+
}),
|
|
11
17
|
"use-forwarded-host": Flags.boolean({
|
|
12
18
|
description: "Uses the forwarded host header to construct widget URLs instead of localhost, useful when accessing the dev server through a tunnel (e.g., ngrok)",
|
|
13
19
|
}),
|
|
14
20
|
};
|
|
15
21
|
async run() {
|
|
16
22
|
const { flags } = await this.parse(Dev);
|
|
23
|
+
const { port, fallback, envWarning } = await resolvePort(flags.port);
|
|
24
|
+
if (envWarning) {
|
|
25
|
+
this.warn(envWarning);
|
|
26
|
+
}
|
|
17
27
|
const env = {
|
|
18
28
|
...process.env,
|
|
29
|
+
__PORT: String(port),
|
|
19
30
|
...(flags["use-forwarded-host"]
|
|
20
31
|
? { SKYBRIDGE_USE_FORWARDED_HOST: "true" }
|
|
21
32
|
: {}),
|
|
@@ -23,7 +34,7 @@ export default class Dev extends Command {
|
|
|
23
34
|
const App = () => {
|
|
24
35
|
const tsErrors = useTypeScriptCheck();
|
|
25
36
|
const messages = useNodemon(env);
|
|
26
|
-
return (_jsxs(Box, { flexDirection: "column", padding: 1, marginLeft: 1, children: [_jsx(Header, { version: this.config.version }),
|
|
37
|
+
return (_jsxs(Box, { flexDirection: "column", padding: 1, marginLeft: 1, children: [_jsx(Header, { version: this.config.version }), fallback && (_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { color: "yellow", children: ["Port 3000 is in use, falling back to port ", port] }) })), _jsxs(Box, { marginBottom: 1, children: [_jsxs(Text, { color: "green", children: ["\u2192", " "] }), _jsxs(Text, { color: "white", bold: true, children: ["Open DevTools to test your app locally:", " "] }), _jsx(Text, { color: "green", children: `http://localhost:${port}/` })] }), _jsxs(Box, { marginBottom: 1, children: [_jsxs(Text, { color: "#20a832", children: ["\u2192", " "] }), _jsxs(Text, { children: ["MCP server running at:", " "] }), _jsx(Text, { color: "white", bold: true, children: `http://localhost:${port}/mcp` })] }), _jsx(Box, { children: _jsxs(Text, { children: [_jsxs(Text, { color: "#20a832", children: ["\u2192", " "] }), _jsxs(Text, { color: "grey", children: ["Test on ChatGPT, Claude, or any MCP client:", " "] }), _jsx(Text, { color: "white", bold: true, children: "https://docs.skybridge.tech/quickstart/test-your-app" })] }) }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { children: [_jsxs(Text, { color: "#20a832", children: ["\u2192", " "] }), _jsx(Text, { children: "If you like Skybridge, please " }), _jsxs(Text, { color: "white", bold: true, children: ["give it a star", " "] }), _jsx(Text, { children: "on GitHub: " }), _jsx(Text, { color: "white", underline: true, children: "https://github.com/alpic-ai/skybridge" }), _jsx(Text, { color: "grey", children: " \uD83D\uDE4F" })] }) }), tsErrors.length > 0 && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: "red", bold: true, children: "\u26A0\uFE0F TypeScript errors found:" }), tsErrors.map((error) => (_jsxs(Box, { marginLeft: 2, flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "white", children: error.file }), _jsxs(Text, { color: "grey", children: ["(", error.line, ",", error.col, "):", " "] })] }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "red", children: error.message }) })] }, `${error.file}:${error.line}:${error.col}`)))] })), messages.length > 0 && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: "white", bold: true, children: "Logs:" }), messages.map((message, index) => (_jsx(Box, { marginLeft: 2, children: message.type === "restart" ? (_jsxs(_Fragment, { children: [_jsxs(Text, { color: "green", children: ["\u2713", " "] }), _jsx(Text, { color: "white", children: message.text })] })) : message.type === "error" ? (_jsx(Text, { color: "red", children: message.text })) : (_jsx(Text, { children: message.text })) }, `${message.type}-${index}-${message.text.slice(0, 20)}`)))] }))] }));
|
|
27
38
|
};
|
|
28
39
|
render(_jsx(App, {}), { exitOnCtrlC: true, patchConsole: true });
|
|
29
40
|
}
|
package/dist/commands/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,OAAO;IACtC,MAAM,CAAU,WAAW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C,CACJ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAC7B,KAAC,IAAI,IAAC,KAAK,EAAC,KAAK,YAAE,OAAO,CAAC,IAAI,GAAQ,CACxC,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,cAAE,OAAO,CAAC,IAAI,GAAQ,CAC5B,IAZI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAaxD,CACP,CAAC,IACE,CACP,IACG,CACP,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,CAAC,KAAC,GAAG,KAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC"}
|
package/dist/commands/start.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Command } from "@oclif/core";
|
|
|
2
2
|
export default class Start extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
|
-
static flags: {
|
|
5
|
+
static flags: {
|
|
6
|
+
port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
};
|
|
6
8
|
run(): Promise<void>;
|
|
7
9
|
}
|
package/dist/commands/start.js
CHANGED
|
@@ -1,27 +1,51 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { Command } from "@oclif/core";
|
|
3
|
+
import { Command, Flags } from "@oclif/core";
|
|
4
|
+
import { resolvePort } from "../cli/detect-port.js";
|
|
4
5
|
import { runCommand } from "../cli/run-command.js";
|
|
5
6
|
export default class Start extends Command {
|
|
6
7
|
static description = "Start production server";
|
|
7
8
|
static examples = ["skybridge start"];
|
|
8
|
-
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
|
+
};
|
|
9
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
|
+
}
|
|
10
22
|
console.clear();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
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");
|
|
14
30
|
console.error("");
|
|
15
31
|
console.error("Please build your project first:");
|
|
16
32
|
console.error(" skybridge build");
|
|
17
33
|
console.error("");
|
|
18
34
|
process.exit(1);
|
|
35
|
+
return;
|
|
19
36
|
}
|
|
20
37
|
console.log(`\x1b[36m\x1b[1m⛰ Welcome to Skybridge\x1b[0m \x1b[36mv${this.config.version}\x1b[0m`);
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
if (fallback) {
|
|
39
|
+
console.log(`\x1b[33mPort 3000 is in use, falling back to port ${port}\x1b[0m`);
|
|
40
|
+
}
|
|
41
|
+
console.log(`Server running at: \x1b[32m\x1b[1mhttp://localhost:${port}/mcp\x1b[0m`);
|
|
42
|
+
await runCommand(`node ${indexPath}`, {
|
|
23
43
|
stdio: ["ignore", "inherit", "inherit"],
|
|
24
|
-
env: {
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
NODE_ENV: "production",
|
|
47
|
+
__PORT: String(port),
|
|
48
|
+
},
|
|
25
49
|
});
|
|
26
50
|
}
|
|
27
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/comm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AAE,0BAA0B,CAAC;YAClD,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC;SACxC,CAAC;QAEF,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE9C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAChD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;YAClD,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACnC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CACT,0DAA0D,IAAI,CAAC,MAAM,CAAC,OAAO,SAAS,CACvF,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CACT,qDAAqD,IAAI,SAAS,CACnE,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,GAAG,CACT,sDAAsD,IAAI,aAAa,CACxE,CAAC;QAEF,MAAM,UAAU,CAAC,QAAQ,SAAS,EAAE,EAAE;YACpC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC;YACvC,GAAG,EAAE;gBACH,GAAG,OAAO,CAAC,GAAG;gBACd,QAAQ,EAAE,YAAY;gBACtB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;aACrB;SACF,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_HMR_PORT = 24678;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/server/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC"}
|
package/dist/server/express.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import type { McpServer } from "./server";
|
|
3
|
-
export declare function createServer({ server, }: {
|
|
3
|
+
export declare function createServer({ server, customMiddleware, }: {
|
|
4
4
|
server: McpServer;
|
|
5
|
+
customMiddleware?: {
|
|
6
|
+
path?: string;
|
|
7
|
+
handlers: express.RequestHandler[];
|
|
8
|
+
}[];
|
|
5
9
|
}): Promise<express.Express>;
|
package/dist/server/express.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
2
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
3
|
import cors from "cors";
|
|
5
4
|
import express from "express";
|
|
6
|
-
export async function createServer({ server, }) {
|
|
5
|
+
export async function createServer({ server, customMiddleware = [], }) {
|
|
7
6
|
const app = express();
|
|
8
7
|
app.use(express.json());
|
|
9
8
|
const env = process.env.NODE_ENV || "development";
|
|
9
|
+
for (const middleware of customMiddleware) {
|
|
10
|
+
if (middleware.path) {
|
|
11
|
+
app.use(middleware.path, ...middleware.handlers);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
app.use(...middleware.handlers);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
10
17
|
if (env !== "production") {
|
|
11
18
|
const { devtoolsStaticServer } = await import("@skybridge/devtools");
|
|
12
19
|
app.use(await devtoolsStaticServer());
|
|
@@ -14,10 +21,9 @@ export async function createServer({ server, }) {
|
|
|
14
21
|
app.use(await widgetsDevServer());
|
|
15
22
|
}
|
|
16
23
|
if (env === "production") {
|
|
17
|
-
const
|
|
18
|
-
const __dirname = path.dirname(__filename);
|
|
24
|
+
const assetsPath = path.join(process.cwd(), "dist", "assets");
|
|
19
25
|
app.use("/assets", cors());
|
|
20
|
-
app.use("/assets", express.static(
|
|
26
|
+
app.use("/assets", express.static(assetsPath));
|
|
21
27
|
}
|
|
22
28
|
app.use("/mcp", mcpMiddleware(server));
|
|
23
29
|
return app;
|
|
@@ -43,6 +49,9 @@ const mcpMiddleware = (server) => {
|
|
|
43
49
|
transport.close();
|
|
44
50
|
});
|
|
45
51
|
await server.connect(transport);
|
|
52
|
+
// Express strips the mount path from req.url (e.g. "/mcp" becomes "/").
|
|
53
|
+
// Restore it so the SDK builds the correct requestInfo.url.
|
|
54
|
+
req.url = req.originalUrl;
|
|
46
55
|
await transport.handleRequest(req, res, req.body);
|
|
47
56
|
}
|
|
48
57
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAAA,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,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,MAAM,EACN,gBAAgB,GAAG,EAAE,GAItB;IACC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAElD,KAAK,MAAM,UAAU,IAAI,gBAAgB,EAAE,CAAC;QAC1C,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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E,EAAE,IAAI;aACT,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;gBAClD,kBAAkB,EAAE,SAAS;aAC9B,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,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,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,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,CAAC,KAAK;wBACZ,OAAO,EAAE,uBAAuB;qBACjC;oBACD,EAAE,EAAE,IAAI;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
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: () => ((_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
|
+
describe("createServer", () => {
|
|
26
|
+
it("runs global custom middleware before the /mcp handler", async () => {
|
|
27
|
+
const { createServer } = await import("./express.js");
|
|
28
|
+
const calls = [];
|
|
29
|
+
const mw = (_req, _res, next) => {
|
|
30
|
+
calls.push("custom");
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
const app = await createServer({
|
|
34
|
+
server: fakeServer,
|
|
35
|
+
customMiddleware: [{ handlers: [mw] }],
|
|
36
|
+
});
|
|
37
|
+
const { port, server } = await listen(app);
|
|
38
|
+
openServer = server;
|
|
39
|
+
await postMcp(port);
|
|
40
|
+
expect(calls).toEqual(["custom"]);
|
|
41
|
+
});
|
|
42
|
+
it("runs path-scoped middleware on /mcp", async () => {
|
|
43
|
+
const { createServer } = await import("./express.js");
|
|
44
|
+
const calls = [];
|
|
45
|
+
const mw = (_req, _res, next) => {
|
|
46
|
+
calls.push("auth");
|
|
47
|
+
next();
|
|
48
|
+
};
|
|
49
|
+
const app = await createServer({
|
|
50
|
+
server: fakeServer,
|
|
51
|
+
customMiddleware: [{ path: "/mcp", handlers: [mw] }],
|
|
52
|
+
});
|
|
53
|
+
const { port, server } = await listen(app);
|
|
54
|
+
openServer = server;
|
|
55
|
+
await postMcp(port);
|
|
56
|
+
expect(calls).toEqual(["auth"]);
|
|
57
|
+
});
|
|
58
|
+
it("allows middleware to short-circuit with 401", async () => {
|
|
59
|
+
const { createServer } = await import("./express.js");
|
|
60
|
+
const reject = (_req, res) => {
|
|
61
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
62
|
+
};
|
|
63
|
+
const app = await createServer({
|
|
64
|
+
server: fakeServer,
|
|
65
|
+
customMiddleware: [{ path: "/mcp", handlers: [reject] }],
|
|
66
|
+
});
|
|
67
|
+
const { port, server } = await listen(app);
|
|
68
|
+
openServer = server;
|
|
69
|
+
const res = await postMcp(port);
|
|
70
|
+
expect(res.status).toBe(401);
|
|
71
|
+
expect(await res.json()).toEqual({ error: "Unauthorized" });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
//# 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,GAAG,EAAE,CAAC,CAAC;IACpC,oBAAoB,EAAE,GAAG,EAAE,CACzB,CAAC,CAAC,IAAa,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE,CAClD,IAAI,EAAE,CAAmB;CAC9B,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,gBAAgB,EAAE,GAAG,EAAE,CACrB,CAAC,CAAC,IAAa,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE,CAClD,IAAI,EAAE,CAAmB;CAC9B,CAAC,CAAC,CAAC;AAEJ,MAAM,UAAU,GAAG,EAAe,CAAC;AAEnC,KAAK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mB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC3C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QAClD,CAAC,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC;YAC7B,MAAM,EAAE,UAAU;YAClB,gBAAgB,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;SACzD,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3C,UAAU,GAAG,MAAM,CAAC;QAEpB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -68,11 +68,7 @@ type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
|
68
68
|
}>;
|
|
69
69
|
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
70
70
|
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
71
|
-
}
|
|
72
|
-
use(...handlers: RequestHandler[]): AddTool<TTools, TName, TInput, TOutput, TResponseMetadata>;
|
|
73
|
-
use(path: string, ...handlers: RequestHandler[]): AddTool<TTools, TName, TInput, TOutput, TResponseMetadata>;
|
|
74
|
-
run(): Promise<void>;
|
|
75
|
-
};
|
|
71
|
+
}>;
|
|
76
72
|
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
77
73
|
title?: string;
|
|
78
74
|
description?: string;
|
package/dist/server/server.js
CHANGED
|
@@ -4,6 +4,7 @@ import http from "node:http";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
6
|
import { mergeWith, union } from "es-toolkit";
|
|
7
|
+
import { DEFAULT_HMR_PORT } from "./const.js";
|
|
7
8
|
import { createServer } from "./express.js";
|
|
8
9
|
import { templateHelper } from "./templateHelper.js";
|
|
9
10
|
const mergeWithUnion = (target, source) => {
|
|
@@ -34,15 +35,8 @@ export class McpServer extends McpServerBase {
|
|
|
34
35
|
if (!this.express) {
|
|
35
36
|
this.express = await createServer({
|
|
36
37
|
server: this,
|
|
38
|
+
customMiddleware: this.customMiddleware,
|
|
37
39
|
});
|
|
38
|
-
for (const middleware of this.customMiddleware) {
|
|
39
|
-
if (middleware.path) {
|
|
40
|
-
this.express.use(middleware.path, ...middleware.handlers);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.express.use(...middleware.handlers);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
40
|
}
|
|
47
41
|
const express = this.express;
|
|
48
42
|
return new Promise((resolve, reject) => {
|
|
@@ -51,7 +45,8 @@ export class McpServer extends McpServerBase {
|
|
|
51
45
|
console.error("Failed to start server:", error);
|
|
52
46
|
reject(error);
|
|
53
47
|
});
|
|
54
|
-
|
|
48
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
49
|
+
server.listen(port, () => {
|
|
55
50
|
resolve();
|
|
56
51
|
});
|
|
57
52
|
});
|
|
@@ -66,7 +61,7 @@ export class McpServer extends McpServerBase {
|
|
|
66
61
|
hostType: "apps-sdk",
|
|
67
62
|
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
68
63
|
mimeType: "text/html+skybridge",
|
|
69
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
64
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
70
65
|
const userUi = userMeta?.ui;
|
|
71
66
|
const userCsp = userUi?.csp;
|
|
72
67
|
const defaults = {
|
|
@@ -75,7 +70,7 @@ export class McpServer extends McpServerBase {
|
|
|
75
70
|
connect_domains: connectDomains,
|
|
76
71
|
},
|
|
77
72
|
"openai/widgetDomain": domain,
|
|
78
|
-
"openai/widgetDescription":
|
|
73
|
+
"openai/widgetDescription": resourceConfig.description,
|
|
79
74
|
};
|
|
80
75
|
const fromUi = {
|
|
81
76
|
"openai/widgetCSP": {
|
|
@@ -88,7 +83,7 @@ export class McpServer extends McpServerBase {
|
|
|
88
83
|
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
89
84
|
};
|
|
90
85
|
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
91
|
-
return mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys);
|
|
86
|
+
return mergeWithUnion(mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys), { "openai/widgetDomain": overrides.domain });
|
|
92
87
|
},
|
|
93
88
|
};
|
|
94
89
|
this.registerWidgetResource({
|
|
@@ -103,7 +98,7 @@ export class McpServer extends McpServerBase {
|
|
|
103
98
|
hostType: "mcp-app",
|
|
104
99
|
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
105
100
|
mimeType: "text/html;profile=mcp-app",
|
|
106
|
-
buildContentMeta: ({ resourceDomains, connectDomains, domain }) => {
|
|
101
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
107
102
|
const defaults = {
|
|
108
103
|
ui: {
|
|
109
104
|
csp: {
|
|
@@ -113,7 +108,9 @@ export class McpServer extends McpServerBase {
|
|
|
113
108
|
domain,
|
|
114
109
|
},
|
|
115
110
|
};
|
|
116
|
-
return mergeWithUnion(defaults, {
|
|
111
|
+
return mergeWithUnion(defaults, {
|
|
112
|
+
ui: { ...userMeta?.ui, ...overrides },
|
|
113
|
+
});
|
|
117
114
|
},
|
|
118
115
|
};
|
|
119
116
|
this.registerWidgetResource({
|
|
@@ -144,9 +141,10 @@ export class McpServer extends McpServerBase {
|
|
|
144
141
|
const hostFromHeaders = extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
145
142
|
extra?.requestInfo?.headers?.host;
|
|
146
143
|
const useExternalHost = isProduction || useForwardedHost || isClaude;
|
|
144
|
+
const devPort = process.env.__PORT || "3000";
|
|
147
145
|
const serverUrl = useExternalHost
|
|
148
146
|
? `https://${hostFromHeaders}`
|
|
149
|
-
:
|
|
147
|
+
: `http://localhost:${devPort}`;
|
|
150
148
|
const html = isProduction
|
|
151
149
|
? templateHelper.renderProduction({
|
|
152
150
|
hostType,
|
|
@@ -162,21 +160,26 @@ export class McpServer extends McpServerBase {
|
|
|
162
160
|
});
|
|
163
161
|
const connectDomains = [serverUrl];
|
|
164
162
|
if (!isProduction) {
|
|
165
|
-
const
|
|
163
|
+
const hmrPort = process.env.__SKYBRIDGE_HMR_PORT ?? DEFAULT_HMR_PORT;
|
|
164
|
+
const VITE_HMR_WEBSOCKET_DEFAULT_URL = `ws://localhost:${hmrPort}`;
|
|
166
165
|
connectDomains.push(VITE_HMR_WEBSOCKET_DEFAULT_URL);
|
|
167
166
|
}
|
|
167
|
+
const contentMetaOverrides = isClaude
|
|
168
|
+
? {
|
|
169
|
+
domain: `${crypto
|
|
170
|
+
.createHash("sha256")
|
|
171
|
+
.update(extra.requestInfo?.url?.href ||
|
|
172
|
+
`https://${hostFromHeaders}/mcp`)
|
|
173
|
+
.digest("hex")
|
|
174
|
+
.slice(0, 32)}.claudemcpcontent.com`,
|
|
175
|
+
}
|
|
176
|
+
: {};
|
|
168
177
|
const contentMeta = buildContentMeta({
|
|
169
178
|
resourceDomains: [serverUrl],
|
|
170
179
|
connectDomains,
|
|
171
|
-
domain:
|
|
172
|
-
? `${crypto
|
|
173
|
-
.createHash("sha256")
|
|
174
|
-
.update(`https://${hostFromHeaders}/mcp`)
|
|
175
|
-
.digest("hex")
|
|
176
|
-
.slice(0, 32)}.claudemcpcontent.com`
|
|
177
|
-
: serverUrl,
|
|
180
|
+
domain: serverUrl,
|
|
178
181
|
baseUriDomains: [serverUrl],
|
|
179
|
-
});
|
|
182
|
+
}, contentMetaOverrides);
|
|
180
183
|
return {
|
|
181
184
|
contents: [
|
|
182
185
|
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|