@_davideast/stitch-mcp 0.5.1 → 0.5.2
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/chunk-1fbzpreg.js +137 -0
- package/dist/chunk-1fbzpreg.js.map +10 -0
- package/dist/chunk-4zqw9exz.js +370 -0
- package/dist/chunk-4zqw9exz.js.map +16 -0
- package/dist/chunk-9g1t32qk.js +273 -0
- package/dist/chunk-9g1t32qk.js.map +10 -0
- package/dist/chunk-aa5ptn4s.js +768 -0
- package/dist/chunk-aa5ptn4s.js.map +18 -0
- package/dist/chunk-b9nzx4rf.js +19 -0
- package/dist/chunk-b9nzx4rf.js.map +9 -0
- package/dist/chunk-c87d10w8.js +109 -0
- package/dist/chunk-c87d10w8.js.map +10 -0
- package/dist/chunk-d0ffvq20.js +19 -0
- package/dist/chunk-d0ffvq20.js.map +9 -0
- package/dist/chunk-d8nttd6z.js +683 -0
- package/dist/chunk-d8nttd6z.js.map +17 -0
- package/dist/chunk-e4q3v109.js +31464 -0
- package/dist/chunk-e4q3v109.js.map +245 -0
- package/dist/chunk-etcps0m5.js +1495 -0
- package/dist/chunk-etcps0m5.js.map +23 -0
- package/dist/chunk-f89ve6pt.js +256 -0
- package/dist/chunk-f89ve6pt.js.map +11 -0
- package/dist/chunk-gydabgsn.js +10 -0
- package/dist/chunk-gydabgsn.js.map +9 -0
- package/dist/chunk-m4fp3pqc.js +167 -0
- package/dist/chunk-m4fp3pqc.js.map +10 -0
- package/dist/chunk-nnep362g.js +124 -0
- package/dist/chunk-nnep362g.js.map +12 -0
- package/dist/chunk-pgqvwkcy.js +736 -0
- package/dist/chunk-pgqvwkcy.js.map +16 -0
- package/dist/chunk-q8cr9t2z.js +415 -0
- package/dist/chunk-q8cr9t2z.js.map +20 -0
- package/dist/chunk-s2d39pkr.js +19 -0
- package/dist/chunk-s2d39pkr.js.map +9 -0
- package/dist/chunk-ststnnry.js +44150 -0
- package/dist/chunk-ststnnry.js.map +237 -0
- package/dist/chunk-sv2nt87j.js +24 -0
- package/dist/chunk-sv2nt87j.js.map +9 -0
- package/dist/chunk-t2razx5k.js +69 -0
- package/dist/chunk-t2razx5k.js.map +10 -0
- package/dist/commands/doctor/command.js +10 -6
- package/dist/commands/doctor/command.js.map +4 -4
- package/dist/commands/doctor/spec.d.ts +6 -0
- package/dist/commands/init/command.js +17 -9
- package/dist/commands/init/command.js.map +4 -4
- package/dist/commands/init/spec.d.ts +6 -0
- package/dist/commands/proxy/command.js +2 -3
- package/dist/commands/proxy/command.js.map +3 -3
- package/dist/commands/screens/command.js +2 -2
- package/dist/commands/serve/command.js +3 -3
- package/dist/commands/site/command.js +1 -1
- package/dist/commands/snapshot/command.js +1 -1
- package/dist/commands/tool/command.js +1 -1
- package/dist/commands/view/command.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openUrl,
|
|
3
|
+
require_jsx_dev_runtime
|
|
4
|
+
} from "./chunk-krfqppg2.js";
|
|
5
|
+
import {
|
|
6
|
+
StitchViteServer
|
|
7
|
+
} from "./chunk-ststnnry.js";
|
|
8
|
+
import"./chunk-abf1r0jh.js";
|
|
9
|
+
import {
|
|
10
|
+
Box_default,
|
|
11
|
+
Text,
|
|
12
|
+
use_app_default,
|
|
13
|
+
use_input_default
|
|
14
|
+
} from "./chunk-7y4xzvkz.js";
|
|
15
|
+
import {
|
|
16
|
+
require_react
|
|
17
|
+
} from "./chunk-4jwmvjb4.js";
|
|
18
|
+
import {
|
|
19
|
+
downloadText
|
|
20
|
+
} from "./chunk-34w2wfyp.js";
|
|
21
|
+
import"./chunk-akd997ec.js";
|
|
22
|
+
import"./chunk-q6sv0243.js";
|
|
23
|
+
import"./chunk-4jygt4d6.js";
|
|
24
|
+
import"./chunk-tz7wnw4s.js";
|
|
25
|
+
import"./chunk-3sfn889r.js";
|
|
26
|
+
import {
|
|
27
|
+
__toESM
|
|
28
|
+
} from "./chunk-9wyra8hs.js";
|
|
29
|
+
|
|
30
|
+
// src/commands/serve/ServeView.tsx
|
|
31
|
+
var import_react = __toESM(require_react(), 1);
|
|
32
|
+
var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
|
|
33
|
+
function ServeView({ projectId, projectTitle, screens }) {
|
|
34
|
+
const { exit } = use_app_default();
|
|
35
|
+
const [selectedIndex, setSelectedIndex] = import_react.useState(0);
|
|
36
|
+
const [serverUrl, setServerUrl] = import_react.useState(null);
|
|
37
|
+
const [status, setStatus] = import_react.useState("Starting server...");
|
|
38
|
+
const [server, setServer] = import_react.useState(null);
|
|
39
|
+
import_react.useEffect(() => {
|
|
40
|
+
const srv = new StitchViteServer;
|
|
41
|
+
setServer(srv);
|
|
42
|
+
let mounted = true;
|
|
43
|
+
async function init() {
|
|
44
|
+
try {
|
|
45
|
+
const url = await srv.start(0);
|
|
46
|
+
if (mounted)
|
|
47
|
+
setServerUrl(url);
|
|
48
|
+
await Promise.all(screens.map(async (screen) => {
|
|
49
|
+
try {
|
|
50
|
+
const html = await downloadText(screen.codeUrl);
|
|
51
|
+
srv.mount(`/screens/${screen.screenId}`, html);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error(`Failed to load ${screen.screenId}`);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
const indexHtml = `<!DOCTYPE html>
|
|
57
|
+
<html>
|
|
58
|
+
<head>
|
|
59
|
+
<title>${projectTitle}</title>
|
|
60
|
+
<style>
|
|
61
|
+
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; background: #1a1a1a; color: #fff; }
|
|
62
|
+
ul { list-style: none; padding: 0; }
|
|
63
|
+
li { margin: 12px 0; padding: 16px; background: #252525; border-radius: 8px; }
|
|
64
|
+
a { color: #4fc3f7; text-decoration: none; font-size: 18px; display: block; }
|
|
65
|
+
a:hover { text-decoration: underline; }
|
|
66
|
+
</style>
|
|
67
|
+
</head>
|
|
68
|
+
<body>
|
|
69
|
+
<h1>${projectTitle}</h1>
|
|
70
|
+
<ul>
|
|
71
|
+
${screens.map((s) => `<li>
|
|
72
|
+
<a href="/screens/${s.screenId}">${s.title}</a>
|
|
73
|
+
</li>`).join(`
|
|
74
|
+
`)}
|
|
75
|
+
</ul>
|
|
76
|
+
</body>
|
|
77
|
+
</html>`;
|
|
78
|
+
srv.mount("/", indexHtml);
|
|
79
|
+
if (mounted)
|
|
80
|
+
setStatus("Ready");
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (mounted)
|
|
83
|
+
setStatus(`Error: ${e.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
init();
|
|
87
|
+
return () => {
|
|
88
|
+
mounted = false;
|
|
89
|
+
srv.stop();
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
use_input_default((input, key) => {
|
|
93
|
+
if (input === "q") {
|
|
94
|
+
exit();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (key.upArrow || input === "k") {
|
|
98
|
+
setSelectedIndex((prev) => Math.max(0, prev - 1));
|
|
99
|
+
}
|
|
100
|
+
if (key.downArrow || input === "j") {
|
|
101
|
+
setSelectedIndex((prev) => Math.min(screens.length, prev + 1));
|
|
102
|
+
}
|
|
103
|
+
if (key.return && serverUrl) {
|
|
104
|
+
let target = serverUrl;
|
|
105
|
+
if (selectedIndex > 0) {
|
|
106
|
+
const screen = screens[selectedIndex - 1];
|
|
107
|
+
if (screen) {
|
|
108
|
+
target = `${serverUrl}/screens/${screen.screenId}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
openUrl(target);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
|
|
115
|
+
flexDirection: "column",
|
|
116
|
+
padding: 1,
|
|
117
|
+
children: [
|
|
118
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
119
|
+
bold: true,
|
|
120
|
+
children: projectTitle
|
|
121
|
+
}, undefined, false, undefined, this),
|
|
122
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
123
|
+
color: "green",
|
|
124
|
+
children: serverUrl || "Starting..."
|
|
125
|
+
}, undefined, false, undefined, this),
|
|
126
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
127
|
+
children: status
|
|
128
|
+
}, undefined, false, undefined, this),
|
|
129
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
|
|
130
|
+
marginTop: 1,
|
|
131
|
+
flexDirection: "column",
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
134
|
+
color: selectedIndex === 0 ? "cyan" : undefined,
|
|
135
|
+
children: [
|
|
136
|
+
selectedIndex === 0 ? "> " : " ",
|
|
137
|
+
" Index (/)"
|
|
138
|
+
]
|
|
139
|
+
}, undefined, true, undefined, this),
|
|
140
|
+
screens.map((s, i) => /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
141
|
+
color: selectedIndex === i + 1 ? "cyan" : undefined,
|
|
142
|
+
children: [
|
|
143
|
+
selectedIndex === i + 1 ? "> " : " ",
|
|
144
|
+
" ",
|
|
145
|
+
s.title,
|
|
146
|
+
" (/screens/",
|
|
147
|
+
s.screenId,
|
|
148
|
+
")"
|
|
149
|
+
]
|
|
150
|
+
}, s.screenId, true, undefined, this))
|
|
151
|
+
]
|
|
152
|
+
}, undefined, true, undefined, this),
|
|
153
|
+
/* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
|
|
154
|
+
marginTop: 1,
|
|
155
|
+
children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
|
|
156
|
+
dimColor: true,
|
|
157
|
+
children: "[Enter] Open | [q] Quit"
|
|
158
|
+
}, undefined, false, undefined, this)
|
|
159
|
+
}, undefined, false, undefined, this)
|
|
160
|
+
]
|
|
161
|
+
}, undefined, true, undefined, this);
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
ServeView
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
//# debugId=4BCD01A43CD1D53A64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/commands/serve/ServeView.tsx"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import React, { useState, useEffect } from 'react';\nimport { Box, Text, useInput, useApp } from 'ink';\nimport { StitchViteServer } from '../../lib/server/vite/StitchViteServer.js';\nimport { downloadText } from '../../ui/copy-behaviors/clipboard.js';\nimport { openUrl } from '../../platform/browser.js';\n\ninterface CodeScreen {\n screenId: string;\n title: string;\n codeUrl: string;\n}\n\ninterface ServeViewProps {\n projectId: string;\n projectTitle: string;\n screens: CodeScreen[];\n}\n\nexport function ServeView({ projectId, projectTitle, screens }: ServeViewProps) {\n const { exit } = useApp();\n const [selectedIndex, setSelectedIndex] = useState(0);\n const [serverUrl, setServerUrl] = useState<string | null>(null);\n const [status, setStatus] = useState('Starting server...');\n const [server, setServer] = useState<StitchViteServer | null>(null);\n\n useEffect(() => {\n const srv = new StitchViteServer();\n setServer(srv);\n let mounted = true;\n\n async function init() {\n try {\n const url = await srv.start(0);\n if (mounted) setServerUrl(url);\n\n // Fetch and mount screens\n await Promise.all(screens.map(async (screen) => {\n try {\n const html = await downloadText(screen.codeUrl);\n srv.mount(`/screens/${screen.screenId}`, html);\n } catch (e) {\n console.error(`Failed to load ${screen.screenId}`);\n }\n }));\n\n // Generate Index\n const indexHtml = `<!DOCTYPE html>\n<html>\n<head>\n <title>${projectTitle}</title>\n <style>\n body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; background: #1a1a1a; color: #fff; }\n ul { list-style: none; padding: 0; }\n li { margin: 12px 0; padding: 16px; background: #252525; border-radius: 8px; }\n a { color: #4fc3f7; text-decoration: none; font-size: 18px; display: block; }\n a:hover { text-decoration: underline; }\n </style>\n</head>\n<body>\n <h1>${projectTitle}</h1>\n <ul>\n ${screens.map(s => `<li>\n <a href=\"/screens/${s.screenId}\">${s.title}</a>\n </li>`).join('\\n')}\n </ul>\n</body>\n</html>`;\n srv.mount('/', indexHtml);\n\n if (mounted) setStatus('Ready');\n } catch (e: any) {\n if (mounted) setStatus(`Error: ${e.message}`);\n }\n }\n\n init();\n\n return () => {\n mounted = false;\n srv.stop();\n };\n }, []);\n\n useInput((input, key) => {\n if (input === 'q') {\n exit();\n return;\n }\n\n if (key.upArrow || input === 'k') {\n setSelectedIndex(prev => Math.max(0, prev - 1));\n }\n if (key.downArrow || input === 'j') {\n setSelectedIndex(prev => Math.min(screens.length, prev + 1));\n }\n\n if (key.return && serverUrl) {\n let target = serverUrl;\n if (selectedIndex > 0) {\n const screen = screens[selectedIndex - 1];\n if (screen) {\n target = `${serverUrl}/screens/${screen.screenId}`;\n }\n }\n openUrl(target);\n }\n });\n\n return (\n <Box flexDirection=\"column\" padding={1}>\n <Text bold>{projectTitle}</Text>\n <Text color=\"green\">{serverUrl || 'Starting...'}</Text>\n <Text>{status}</Text>\n <Box marginTop={1} flexDirection=\"column\">\n <Text color={selectedIndex === 0 ? 'cyan' : undefined}>\n {selectedIndex === 0 ? '> ' : ' '} Index (/)\n </Text>\n {screens.map((s, i) => (\n <Text key={s.screenId} color={selectedIndex === i + 1 ? 'cyan' : undefined}>\n {selectedIndex === i + 1 ? '> ' : ' '} {s.title} (/screens/{s.screenId})\n </Text>\n ))}\n </Box>\n <Box marginTop={1}>\n <Text dimColor>[Enter] Open | [q] Quit</Text>\n </Box>\n </Box>\n );\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAkBO,SAAS,SAAS,GAAG,WAAW,cAAc,WAA2B;AAAA,EAC9E,QAAQ,SAAS,gBAAO;AAAA,EACxB,OAAO,eAAe,oBA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;AAAA,YAAjE,UAEE;AAAA,cADG,kBAAkB,IAAI,IAAI,OAAO;AAAA,cADtC;AAAA,cAC6C,EAAE;AAAA,cAD/C;AAAA,cACiE,EAAE;AAAA,cADnE;AAAA;AAAA,aAAW,EAAE,UAAb,qBAEE,CACL;AAAA;AAAA,SARL,gCASE;AAAA,sBACF,uBAEE,aAFF;AAAA,QAAK,WAAW;AAAA,QAAhB,0BACI,uBAAwC,MAAxC;AAAA,UAAM,UAAQ;AAAA,UAAd;AAAA,4CAAwC;AAAA,SAD5C,iCAEE;AAAA;AAAA,KAhBN,gCAiBE;AAAA;",
|
|
8
|
+
"debugId": "4BCD01A43CD1D53A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JSONRPCMessageSchema,
|
|
3
|
+
StitchProxy
|
|
4
|
+
} from "./chunk-e4q3v109.js";
|
|
5
|
+
import"./chunk-c6ge431q.js";
|
|
6
|
+
import"./chunk-9wyra8hs.js";
|
|
7
|
+
|
|
8
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
9
|
+
import process2 from "node:process";
|
|
10
|
+
|
|
11
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
12
|
+
class ReadBuffer {
|
|
13
|
+
append(chunk) {
|
|
14
|
+
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
15
|
+
}
|
|
16
|
+
readMessage() {
|
|
17
|
+
if (!this._buffer) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const index = this._buffer.indexOf(`
|
|
21
|
+
`);
|
|
22
|
+
if (index === -1) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
|
|
26
|
+
this._buffer = this._buffer.subarray(index + 1);
|
|
27
|
+
return deserializeMessage(line);
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
this._buffer = undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function deserializeMessage(line) {
|
|
34
|
+
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
|
35
|
+
}
|
|
36
|
+
function serializeMessage(message) {
|
|
37
|
+
return JSON.stringify(message) + `
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
42
|
+
class StdioServerTransport {
|
|
43
|
+
constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
|
|
44
|
+
this._stdin = _stdin;
|
|
45
|
+
this._stdout = _stdout;
|
|
46
|
+
this._readBuffer = new ReadBuffer;
|
|
47
|
+
this._started = false;
|
|
48
|
+
this._ondata = (chunk) => {
|
|
49
|
+
this._readBuffer.append(chunk);
|
|
50
|
+
this.processReadBuffer();
|
|
51
|
+
};
|
|
52
|
+
this._onerror = (error) => {
|
|
53
|
+
this.onerror?.(error);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async start() {
|
|
57
|
+
if (this._started) {
|
|
58
|
+
throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
|
|
59
|
+
}
|
|
60
|
+
this._started = true;
|
|
61
|
+
this._stdin.on("data", this._ondata);
|
|
62
|
+
this._stdin.on("error", this._onerror);
|
|
63
|
+
}
|
|
64
|
+
processReadBuffer() {
|
|
65
|
+
while (true) {
|
|
66
|
+
try {
|
|
67
|
+
const message = this._readBuffer.readMessage();
|
|
68
|
+
if (message === null) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
this.onmessage?.(message);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
this.onerror?.(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async close() {
|
|
78
|
+
this._stdin.off("data", this._ondata);
|
|
79
|
+
this._stdin.off("error", this._onerror);
|
|
80
|
+
const remainingDataListeners = this._stdin.listenerCount("data");
|
|
81
|
+
if (remainingDataListeners === 0) {
|
|
82
|
+
this._stdin.pause();
|
|
83
|
+
}
|
|
84
|
+
this._readBuffer.clear();
|
|
85
|
+
this.onclose?.();
|
|
86
|
+
}
|
|
87
|
+
send(message) {
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
const json = serializeMessage(message);
|
|
90
|
+
if (this._stdout.write(json)) {
|
|
91
|
+
resolve();
|
|
92
|
+
} else {
|
|
93
|
+
this._stdout.once("drain", resolve);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/commands/proxy/handler.ts
|
|
100
|
+
class ProxyCommandHandler {
|
|
101
|
+
createProxy;
|
|
102
|
+
createTransport;
|
|
103
|
+
constructor(deps) {
|
|
104
|
+
this.createProxy = deps?.createProxy ?? ((opts) => new StitchProxy(opts));
|
|
105
|
+
this.createTransport = deps?.createTransport ?? (() => new StdioServerTransport);
|
|
106
|
+
}
|
|
107
|
+
async execute(input) {
|
|
108
|
+
try {
|
|
109
|
+
const proxy = this.createProxy({
|
|
110
|
+
apiKey: process.env.STITCH_API_KEY
|
|
111
|
+
});
|
|
112
|
+
const transport = this.createTransport();
|
|
113
|
+
await proxy.start(transport);
|
|
114
|
+
return { success: true, data: { status: "running" } };
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return { success: false, error: { code: "PROXY_START_ERROR", message: e.message, recoverable: false } };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
ProxyCommandHandler
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//# debugId=6D6044F9ACFF7CD764756E2164756E21
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js", "../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js", "../src/commands/proxy/handler.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import process from 'node:process';\nimport { ReadBuffer, serializeMessage } from '../shared/stdio.js';\n/**\n * Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioServerTransport {\n constructor(_stdin = process.stdin, _stdout = process.stdout) {\n this._stdin = _stdin;\n this._stdout = _stdout;\n this._readBuffer = new ReadBuffer();\n this._started = false;\n // Arrow functions to bind `this` properly, while maintaining function identity.\n this._ondata = (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n };\n this._onerror = (error) => {\n this.onerror?.(error);\n };\n }\n /**\n * Starts listening for messages on stdin.\n */\n async start() {\n if (this._started) {\n throw new Error('StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.');\n }\n this._started = true;\n this._stdin.on('data', this._ondata);\n this._stdin.on('error', this._onerror);\n }\n processReadBuffer() {\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n this.onmessage?.(message);\n }\n catch (error) {\n this.onerror?.(error);\n }\n }\n }\n async close() {\n // Remove our event listeners first\n this._stdin.off('data', this._ondata);\n this._stdin.off('error', this._onerror);\n // Check if we were the only data listener\n const remainingDataListeners = this._stdin.listenerCount('data');\n if (remainingDataListeners === 0) {\n // Only pause stdin if we were the only listener\n // This prevents interfering with other parts of the application that might be using stdin\n this._stdin.pause();\n }\n // Clear the buffer and notify closure\n this._readBuffer.clear();\n this.onclose?.();\n }\n send(message) {\n return new Promise(resolve => {\n const json = serializeMessage(message);\n if (this._stdout.write(json)) {\n resolve();\n }\n else {\n this._stdout.once('drain', resolve);\n }\n });\n }\n}\n//# sourceMappingURL=stdio.js.map",
|
|
6
|
+
"import { JSONRPCMessageSchema } from '../types.js';\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf('\\n');\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString('utf8', 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + '\\n';\n}\n//# sourceMappingURL=stdio.js.map",
|
|
7
|
+
"import { StitchProxy } from '@google/stitch-sdk';\nimport type { StitchProxy as StitchProxyType } from '@google/stitch-sdk';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\ninterface ProxyCommandInput {\n port?: number;\n debug?: boolean;\n}\n\ninterface ProxyCommandResult {\n success: boolean;\n data?: { status: string };\n error?: { code: string; message: string; recoverable: boolean };\n}\n\nexport class ProxyCommandHandler {\n private createProxy: (opts: { apiKey?: string }) => StitchProxyType;\n private createTransport: () => StdioServerTransport;\n\n constructor(deps?: {\n createProxy?: (opts: { apiKey?: string }) => StitchProxyType;\n createTransport?: () => StdioServerTransport;\n }) {\n this.createProxy = deps?.createProxy ?? ((opts) => new StitchProxy(opts));\n this.createTransport = deps?.createTransport ?? (() => new StdioServerTransport());\n }\n\n async execute(input: ProxyCommandInput): Promise<ProxyCommandResult> {\n try {\n const proxy = this.createProxy({\n apiKey: process.env.STITCH_API_KEY,\n });\n const transport = this.createTransport();\n await proxy.start(transport);\n return { success: true, data: { status: 'running' } };\n } catch (e: any) {\n return { success: false, error: { code: 'PROXY_START_ERROR', message: e.message, recoverable: false } };\n }\n }\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";;;;;;;;AAAA;;;ACIO,MAAM,WAAW;AAAA,EACpB,MAAM,CAAC,OAAO;AAAA,IACV,KAAK,UAAU,KAAK,UAAU,OAAO,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