@vibekiln/cutline-mcp-cli 0.5.0 → 0.6.0
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 -0
- package/dist/commands/serve.d.ts +8 -1
- package/dist/commands/serve.js +175 -4
- package/dist/index.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,6 +135,19 @@ cutline-mcp serve output # Export and rendering
|
|
|
135
135
|
cutline-mcp serve integrations # External integrations
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
HTTP bridge mode (for registries/hosts that require an HTTPS MCP URL):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
cutline-mcp serve constraints --http --host 0.0.0.0 --port 8080 --path /mcp
|
|
142
|
+
# Health: GET /health
|
|
143
|
+
# MCP endpoint: POST /mcp
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Bridge notes:
|
|
147
|
+
- Default mode remains stdio (no behavior change for Cursor/Claude Desktop local configs).
|
|
148
|
+
- The bridge forwards JSON-RPC requests to the bundled stdio server process.
|
|
149
|
+
- Batch JSON-RPC payloads are not supported by the bridge.
|
|
150
|
+
|
|
138
151
|
### `upgrade`
|
|
139
152
|
|
|
140
153
|
Open the upgrade page and refresh your session.
|
|
@@ -206,6 +219,10 @@ Config: [`server.json`](./server.json)
|
|
|
206
219
|
|
|
207
220
|
Config: [`smithery.yaml`](./smithery.yaml) with [`Dockerfile`](./Dockerfile)
|
|
208
221
|
|
|
222
|
+
If the publish UI requires an MCP Server URL, deploy the bridge and provide your public HTTPS endpoint, for example:
|
|
223
|
+
|
|
224
|
+
`https://mcp.thecutline.ai/mcp`
|
|
225
|
+
|
|
209
226
|
### Claude Desktop Extension
|
|
210
227
|
|
|
211
228
|
```bash
|
package/dist/commands/serve.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface ServeOptions {
|
|
2
|
+
http?: boolean;
|
|
3
|
+
host?: string;
|
|
4
|
+
port?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function serveCommand(serverName: string, options?: ServeOptions): void;
|
|
8
|
+
export {};
|
package/dist/commands/serve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
1
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
2
3
|
import { resolve, dirname } from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { existsSync } from 'node:fs';
|
|
@@ -11,7 +12,174 @@ const SERVER_MAP = {
|
|
|
11
12
|
output: 'output-server.js',
|
|
12
13
|
integrations: 'integrations-server.js',
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
function readJsonBody(req) {
|
|
16
|
+
return new Promise((resolveBody, rejectBody) => {
|
|
17
|
+
const chunks = [];
|
|
18
|
+
let total = 0;
|
|
19
|
+
const MAX_BODY_BYTES = 1024 * 1024; // 1MB safety cap
|
|
20
|
+
req.on('data', (chunk) => {
|
|
21
|
+
total += chunk.length;
|
|
22
|
+
if (total > MAX_BODY_BYTES) {
|
|
23
|
+
rejectBody(new Error('Request body too large'));
|
|
24
|
+
req.destroy();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
chunks.push(chunk);
|
|
28
|
+
});
|
|
29
|
+
req.on('end', () => {
|
|
30
|
+
try {
|
|
31
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
32
|
+
resolveBody(text ? JSON.parse(text) : {});
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
rejectBody(new Error('Invalid JSON body'));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
req.on('error', rejectBody);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function writeJson(res, statusCode, body) {
|
|
42
|
+
const payload = JSON.stringify(body);
|
|
43
|
+
res.writeHead(statusCode, {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
'Content-Length': Buffer.byteLength(payload),
|
|
46
|
+
});
|
|
47
|
+
res.end(payload);
|
|
48
|
+
}
|
|
49
|
+
function normalizeId(id) {
|
|
50
|
+
if (typeof id === 'string' || typeof id === 'number')
|
|
51
|
+
return String(id);
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
function serveHttpBridge(serverName, serverPath, opts) {
|
|
55
|
+
const host = opts.host || process.env.CUTLINE_MCP_HTTP_HOST || '0.0.0.0';
|
|
56
|
+
const port = Number(opts.port || process.env.CUTLINE_MCP_HTTP_PORT || '8080');
|
|
57
|
+
const mcpPath = opts.path || process.env.CUTLINE_MCP_HTTP_PATH || '/mcp';
|
|
58
|
+
const requestTimeoutMs = Number(process.env.CUTLINE_MCP_HTTP_TIMEOUT_MS || '30000');
|
|
59
|
+
if (!Number.isFinite(port) || port <= 0) {
|
|
60
|
+
console.error(`Invalid --port value: ${opts.port}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const child = spawn(process.execPath, [serverPath], {
|
|
64
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
65
|
+
env: process.env,
|
|
66
|
+
});
|
|
67
|
+
const pending = new Map();
|
|
68
|
+
let stdoutBuffer = Buffer.alloc(0);
|
|
69
|
+
const failAllPending = (reason) => {
|
|
70
|
+
for (const [key, entry] of pending.entries()) {
|
|
71
|
+
clearTimeout(entry.timer);
|
|
72
|
+
entry.reject(reason);
|
|
73
|
+
pending.delete(key);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const sendToStdioServer = (message) => {
|
|
77
|
+
if (!child.stdin || child.killed) {
|
|
78
|
+
throw new Error('MCP stdio server is not available');
|
|
79
|
+
}
|
|
80
|
+
const body = JSON.stringify(message);
|
|
81
|
+
const packet = `Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`;
|
|
82
|
+
child.stdin.write(packet, 'utf8');
|
|
83
|
+
};
|
|
84
|
+
child.stdout?.on('data', (chunk) => {
|
|
85
|
+
stdoutBuffer = Buffer.concat([stdoutBuffer, chunk]);
|
|
86
|
+
while (true) {
|
|
87
|
+
const separatorIndex = stdoutBuffer.indexOf('\r\n\r\n');
|
|
88
|
+
if (separatorIndex < 0)
|
|
89
|
+
break;
|
|
90
|
+
const headers = stdoutBuffer.slice(0, separatorIndex).toString('utf8');
|
|
91
|
+
const lengthMatch = headers.match(/content-length:\s*(\d+)/i);
|
|
92
|
+
if (!lengthMatch) {
|
|
93
|
+
stdoutBuffer = stdoutBuffer.slice(separatorIndex + 4);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const contentLength = Number(lengthMatch[1]);
|
|
97
|
+
const packetLength = separatorIndex + 4 + contentLength;
|
|
98
|
+
if (stdoutBuffer.length < packetLength)
|
|
99
|
+
break;
|
|
100
|
+
const jsonBytes = stdoutBuffer.slice(separatorIndex + 4, packetLength);
|
|
101
|
+
stdoutBuffer = stdoutBuffer.slice(packetLength);
|
|
102
|
+
try {
|
|
103
|
+
const message = JSON.parse(jsonBytes.toString('utf8'));
|
|
104
|
+
const id = normalizeId(message?.id);
|
|
105
|
+
if (!id)
|
|
106
|
+
continue;
|
|
107
|
+
const entry = pending.get(id);
|
|
108
|
+
if (!entry)
|
|
109
|
+
continue;
|
|
110
|
+
clearTimeout(entry.timer);
|
|
111
|
+
pending.delete(id);
|
|
112
|
+
entry.resolve(message);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Ignore malformed child output and keep processing subsequent frames.
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
child.on('exit', (code, signal) => {
|
|
120
|
+
failAllPending(new Error(`MCP stdio server exited unexpectedly (${signal ? `signal ${signal}` : `code ${code ?? 'unknown'}`})`));
|
|
121
|
+
});
|
|
122
|
+
const httpServer = createServer(async (req, res) => {
|
|
123
|
+
const { method } = req;
|
|
124
|
+
const reqPath = (req.url || '/').split('?')[0];
|
|
125
|
+
if (method === 'GET' && reqPath === '/health') {
|
|
126
|
+
writeJson(res, 200, {
|
|
127
|
+
ok: true,
|
|
128
|
+
server: serverName,
|
|
129
|
+
transport: 'http-bridge-stdio',
|
|
130
|
+
mcp_path: mcpPath,
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (method !== 'POST' || reqPath !== mcpPath) {
|
|
135
|
+
writeJson(res, 404, { error: `Not found. Use POST ${mcpPath}` });
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const body = await readJsonBody(req);
|
|
140
|
+
if (Array.isArray(body)) {
|
|
141
|
+
writeJson(res, 400, { error: 'Batch JSON-RPC is not supported by this bridge' });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const message = body;
|
|
145
|
+
const id = normalizeId(message?.id);
|
|
146
|
+
// Notifications do not have an id and do not expect a response.
|
|
147
|
+
if (!id) {
|
|
148
|
+
sendToStdioServer(message);
|
|
149
|
+
writeJson(res, 202, { ok: true });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const response = await new Promise((resolveResponse, rejectResponse) => {
|
|
153
|
+
const timer = setTimeout(() => {
|
|
154
|
+
pending.delete(id);
|
|
155
|
+
rejectResponse(new Error(`Timed out waiting for response id=${id}`));
|
|
156
|
+
}, requestTimeoutMs);
|
|
157
|
+
pending.set(id, {
|
|
158
|
+
resolve: resolveResponse,
|
|
159
|
+
reject: rejectResponse,
|
|
160
|
+
timer,
|
|
161
|
+
});
|
|
162
|
+
try {
|
|
163
|
+
sendToStdioServer(message);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
clearTimeout(timer);
|
|
167
|
+
pending.delete(id);
|
|
168
|
+
rejectResponse(error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
writeJson(res, 200, response);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
writeJson(res, 500, { error: error?.message || 'Bridge request failed' });
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
httpServer.listen(port, host, () => {
|
|
178
|
+
console.error(`Cutline MCP HTTP bridge listening on http://${host}:${port}${mcpPath}`);
|
|
179
|
+
console.error(`Health check: http://${host}:${port}/health`);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
export function serveCommand(serverName, options = {}) {
|
|
15
183
|
const fileName = SERVER_MAP[serverName];
|
|
16
184
|
if (!fileName) {
|
|
17
185
|
const valid = Object.keys(SERVER_MAP).join(', ');
|
|
@@ -24,8 +192,11 @@ export function serveCommand(serverName) {
|
|
|
24
192
|
console.error('The package may not have been built correctly.');
|
|
25
193
|
process.exit(1);
|
|
26
194
|
}
|
|
27
|
-
|
|
28
|
-
|
|
195
|
+
if (options.http) {
|
|
196
|
+
serveHttpBridge(serverName, serverPath, options);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Replace this process with the MCP server (default stdio mode).
|
|
29
200
|
try {
|
|
30
201
|
execFileSync(process.execPath, [serverPath], {
|
|
31
202
|
stdio: 'inherit',
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,16 @@ program
|
|
|
47
47
|
program
|
|
48
48
|
.command('serve <server>')
|
|
49
49
|
.description('Start an MCP server (constraints, premortem, exploration, tools, output, integrations)')
|
|
50
|
-
.
|
|
50
|
+
.option('--http', 'Expose the selected stdio server over an HTTP bridge')
|
|
51
|
+
.option('--host <host>', 'HTTP bind host for bridge mode (default: 0.0.0.0)')
|
|
52
|
+
.option('--port <port>', 'HTTP port for bridge mode (default: 8080)')
|
|
53
|
+
.option('--path <path>', 'HTTP MCP path for bridge mode (default: /mcp)')
|
|
54
|
+
.action((server, opts) => serveCommand(server, {
|
|
55
|
+
http: opts.http,
|
|
56
|
+
host: opts.host,
|
|
57
|
+
port: opts.port,
|
|
58
|
+
path: opts.path,
|
|
59
|
+
}));
|
|
51
60
|
program
|
|
52
61
|
.command('setup')
|
|
53
62
|
.description('One-command onboarding: authenticate, write IDE MCP config, generate rules')
|
package/package.json
CHANGED