@meloduo/mcp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/daemon.js +207 -0
- package/dist/index.js +130 -0
- package/dist/stop.js +8 -0
- package/package.json +47 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ilya Shumchenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/daemon.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/daemon.ts
|
|
4
|
+
import { readFileSync, watch, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { WebSocketServer } from "ws";
|
|
9
|
+
var log = (...a) => console.error("[bridge]", ...a);
|
|
10
|
+
var PORT = Number(process.env.MELODUO_PORT ?? 8787);
|
|
11
|
+
var CALL_TIMEOUT_MS = 12e4;
|
|
12
|
+
var RENDER_TIMEOUT_MS = 6e5;
|
|
13
|
+
var timeoutOf = (tool) => tool === "render_preview" || tool === "match_loudness" || tool === "match_eq" ? RENDER_TIMEOUT_MS : CALL_TIMEOUT_MS;
|
|
14
|
+
var IDLE_MS = Number(process.env.MELODUO_IDLE_MS ?? 15 * 6e4);
|
|
15
|
+
var APP_ORIGINS = ["https://meloduo.github.io", "http://localhost:5173", "http://127.0.0.1:5173"];
|
|
16
|
+
var TAB_ORIGINS = /* @__PURE__ */ new Set([...APP_ORIGINS, ...(process.env.MELODUO_ORIGINS ?? "").split(",").filter(Boolean)]);
|
|
17
|
+
var wss = new WebSocketServer({
|
|
18
|
+
host: "127.0.0.1",
|
|
19
|
+
port: PORT,
|
|
20
|
+
verifyClient: ({ origin, req }) => req.url === "/agent" ? !origin : !origin || TAB_ORIGINS.has(origin)
|
|
21
|
+
});
|
|
22
|
+
wss.on("error", (e) => {
|
|
23
|
+
log(e.code === "EADDRINUSE" ? `port ${PORT} is busy: a bridge is already running, or another program holds the port (set MELODUO_PORT to use another one)` : e);
|
|
24
|
+
process.exit(e.code === "EADDRINUSE" ? 0 : 1);
|
|
25
|
+
});
|
|
26
|
+
var agents = /* @__PURE__ */ new Map();
|
|
27
|
+
var tabs = [];
|
|
28
|
+
var nextTab = 1;
|
|
29
|
+
var openTabs = () => tabs.filter((t) => t.ws.readyState === t.ws.OPEN);
|
|
30
|
+
var tabFor = (pick) => {
|
|
31
|
+
if (!pick) return openTabs().at(-1);
|
|
32
|
+
const has = openTabs().filter((t) => t.project?.id === pick);
|
|
33
|
+
return has.filter((t) => !t.readOnly).at(-1) ?? has.at(-1);
|
|
34
|
+
};
|
|
35
|
+
var tellTabs = () => {
|
|
36
|
+
const users = [...agents.values()].reverse();
|
|
37
|
+
for (const tab of openTabs()) tab.ws.send(JSON.stringify({ type: "client", client: users.find((a) => a.client && tabFor(a.pick) === tab)?.client ?? null }));
|
|
38
|
+
};
|
|
39
|
+
var tabView = (pick) => {
|
|
40
|
+
const latest = tabFor();
|
|
41
|
+
const used = tabFor(pick);
|
|
42
|
+
return {
|
|
43
|
+
tabs: openTabs().map((t) => ({ tab: t.name, projectId: t.project?.id ?? null, project: t.project?.name ?? null, readOnly: !!t.readOnly, latest: t === latest, yours: t === used })),
|
|
44
|
+
using: pick ? { projectId: pick, tab: used?.name ?? null } : "latest"
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var BRIDGE_TOOLS = [
|
|
48
|
+
{
|
|
49
|
+
name: "list_tabs",
|
|
50
|
+
description: "List the open Meloduo tabs: tab, projectId, project (name), readOnly (another tab edits this project), latest (the last opened tab), yours (where your calls go). Without use_tab, calls go to the last opened tab. Call it when the user talks about another project or your edits land in the wrong place.",
|
|
51
|
+
inputSchema: { type: "object", properties: {} }
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "use_tab",
|
|
55
|
+
description: "Pick the project for this session: all later calls go to the tab with this project, also after it reloads. Take projectId from list_tabs. Without projectId the session follows the last opened tab again. Call get_project_state after the pick.",
|
|
56
|
+
inputSchema: { type: "object", properties: { projectId: { type: "string", description: "Project id from list_tabs; empty means the last opened tab." } } }
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
var nextCall = 1;
|
|
60
|
+
var nextSession = 1;
|
|
61
|
+
var BOOT = Date.now().toString(36);
|
|
62
|
+
function callTab(tool, args, session, signal, { pick, sid, client }) {
|
|
63
|
+
const ws = tabFor(pick)?.ws;
|
|
64
|
+
if (!ws && pick) return Promise.reject(new Error(`No open tab has the project you picked (${pick}). Ask the user to open it, or call list_tabs and use_tab (use_tab with no projectId follows the latest tab).`));
|
|
65
|
+
if (!ws) return Promise.reject(new Error("No Meloduo tab is open. Ask the user to open Meloduo in the browser, then retry."));
|
|
66
|
+
const id = nextCall++;
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const timer = setTimeout(() => done(() => (ws.send(JSON.stringify({ type: "cancel", id })), reject(new Error("Tab did not answer in time. The call was cancelled: retry it with fromBar and toBar (a part of the song), stems false and no spectrum to make it faster.")))), timeoutOf(tool));
|
|
69
|
+
const onMessage = (raw) => {
|
|
70
|
+
let msg;
|
|
71
|
+
try {
|
|
72
|
+
msg = JSON.parse(raw.toString());
|
|
73
|
+
} catch {
|
|
74
|
+
log("tab sent invalid JSON, ignored");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (msg.id !== id) return;
|
|
78
|
+
done(() => msg.error ? reject(new Error(msg.error)) : resolve(msg.result));
|
|
79
|
+
};
|
|
80
|
+
const onClose = () => done(() => reject(new Error("The DAW tab closed during the call. Open the tab and call get_project_state before retrying.")));
|
|
81
|
+
const onAbort = () => done(() => (ws.send(JSON.stringify({ type: "cancel", id })), reject(new Error("Cancelled by the client."))));
|
|
82
|
+
const done = (finish) => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
ws.off("message", onMessage);
|
|
85
|
+
ws.off("close", onClose);
|
|
86
|
+
signal.removeEventListener("abort", onAbort);
|
|
87
|
+
finish();
|
|
88
|
+
};
|
|
89
|
+
ws.on("message", onMessage);
|
|
90
|
+
ws.on("close", onClose);
|
|
91
|
+
signal.addEventListener("abort", onAbort);
|
|
92
|
+
ws.send(JSON.stringify({ id, tool, args, session, sid, client }));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var CACHE = join(tmpdir(), `meloduo-tools-${PORT}.json`);
|
|
96
|
+
var cached = [];
|
|
97
|
+
try {
|
|
98
|
+
cached = JSON.parse(readFileSync(CACHE, "utf8"));
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
var tabTools = () => openTabs().filter((t) => t.tools).at(-1)?.tools ?? cached;
|
|
102
|
+
var toolDefs = () => [...tabTools(), ...BRIDGE_TOOLS];
|
|
103
|
+
var tellAgents = () => {
|
|
104
|
+
const msg = JSON.stringify({ type: "tools", tools: toolDefs() });
|
|
105
|
+
for (const ws of agents.keys()) if (ws.readyState === ws.OPEN) ws.send(msg);
|
|
106
|
+
};
|
|
107
|
+
var isTool = (t) => !!t && typeof t.name === "string" && /^[a-z0-9_]{1,64}$/.test(t.name) && typeof t.inputSchema === "object";
|
|
108
|
+
var takeTools = (tab, list) => {
|
|
109
|
+
if (!Array.isArray(list) || !list.every(isTool)) return log("tab sent an invalid tool list, ignored");
|
|
110
|
+
const before = JSON.stringify(tabTools());
|
|
111
|
+
tab.tools = list;
|
|
112
|
+
if (JSON.stringify(tabTools()) === before) return;
|
|
113
|
+
cached = tabTools();
|
|
114
|
+
if (tab.trusted)
|
|
115
|
+
try {
|
|
116
|
+
writeFileSync(CACHE, JSON.stringify(cached));
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
tellAgents();
|
|
120
|
+
};
|
|
121
|
+
var idleTimer;
|
|
122
|
+
var armIdle = () => {
|
|
123
|
+
clearTimeout(idleTimer);
|
|
124
|
+
if (agents.size === 0) idleTimer = setTimeout(() => (log("no sessions, closing"), process.exit(0)), IDLE_MS);
|
|
125
|
+
};
|
|
126
|
+
wss.on("connection", (ws, req) => {
|
|
127
|
+
if (req.url !== "/agent") {
|
|
128
|
+
const origin = req.headers.origin;
|
|
129
|
+
const tab = { ws, name: `tab${nextTab++}`, trusted: !origin || APP_ORIGINS.includes(origin) };
|
|
130
|
+
tabs.push(tab);
|
|
131
|
+
tellTabs();
|
|
132
|
+
log(`tab connected (${tabs.length} open)`);
|
|
133
|
+
ws.on("message", (raw) => {
|
|
134
|
+
try {
|
|
135
|
+
const msg = JSON.parse(raw.toString());
|
|
136
|
+
if (msg.type === "tab") tab.project = msg.project, tab.readOnly = !!msg.readOnly, tellTabs();
|
|
137
|
+
if (msg.type === "tools") takeTools(tab, msg.tools);
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
ws.on("close", () => {
|
|
142
|
+
const before = JSON.stringify(tabTools());
|
|
143
|
+
tabs.splice(tabs.indexOf(tab), 1);
|
|
144
|
+
if (JSON.stringify(tabTools()) !== before) tellAgents();
|
|
145
|
+
tellTabs();
|
|
146
|
+
log(`tab disconnected (${tabs.length} open)`);
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const session = nextSession++;
|
|
151
|
+
const me = { client: null, sid: `${BOOT}-${session}` };
|
|
152
|
+
agents.set(ws, me);
|
|
153
|
+
const running = /* @__PURE__ */ new Map();
|
|
154
|
+
armIdle();
|
|
155
|
+
log(`session connected (${agents.size} open)`);
|
|
156
|
+
ws.on("close", () => {
|
|
157
|
+
for (const ctl of running.values()) ctl.abort();
|
|
158
|
+
agents.delete(ws);
|
|
159
|
+
tellTabs();
|
|
160
|
+
armIdle();
|
|
161
|
+
log(`session disconnected (${agents.size} open)`);
|
|
162
|
+
});
|
|
163
|
+
ws.on("message", async (raw) => {
|
|
164
|
+
let msg;
|
|
165
|
+
try {
|
|
166
|
+
msg = JSON.parse(raw.toString());
|
|
167
|
+
} catch {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (msg.type === "hello") return void (me.client = msg.client ?? null, me.pick = msg.pick || void 0, me.sid = msg.sid || me.sid, tellTabs());
|
|
171
|
+
if (msg.type === "tools") return void ws.send(JSON.stringify({ type: "tools", tools: toolDefs() }));
|
|
172
|
+
if (msg.type === "quit") return process.exit(0);
|
|
173
|
+
if (msg.type === "cancel") return void (msg.id !== void 0 && running.get(msg.id)?.abort());
|
|
174
|
+
const { id, tool, args } = msg;
|
|
175
|
+
const reply = (r) => ws.readyState === ws.OPEN && ws.send(JSON.stringify({ id, ...r }));
|
|
176
|
+
if (tool === "list_tabs") return reply({ result: tabView(me.pick) });
|
|
177
|
+
if (tool === "use_tab") {
|
|
178
|
+
const pick = args?.projectId;
|
|
179
|
+
if (pick !== void 0 && typeof pick !== "string") return reply({ error: "projectId must be a string from list_tabs. Call list_tabs and retry." });
|
|
180
|
+
if (pick && !tabFor(pick)) return reply({ error: `No open tab has project ${pick}. Call list_tabs for the open projects, or ask the user to open it.` });
|
|
181
|
+
me.pick = pick || void 0;
|
|
182
|
+
ws.send(JSON.stringify({ type: "pick", pick: me.pick ?? null }));
|
|
183
|
+
tellTabs();
|
|
184
|
+
return reply({ result: tabView(me.pick) });
|
|
185
|
+
}
|
|
186
|
+
if (typeof tool !== "string") return reply({ error: "A call needs a tool name." });
|
|
187
|
+
const ctl = new AbortController();
|
|
188
|
+
running.set(id, ctl);
|
|
189
|
+
try {
|
|
190
|
+
reply({ result: await callTab(tool, args, session, ctl.signal, me) });
|
|
191
|
+
} catch (e) {
|
|
192
|
+
reply({ error: e instanceof Error ? e.message : String(e) });
|
|
193
|
+
} finally {
|
|
194
|
+
running.delete(id);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
if (!process.env.MELODUO_NO_WATCH && import.meta.url.endsWith(".ts")) {
|
|
199
|
+
let timer;
|
|
200
|
+
watch(fileURLToPath(new URL(".", import.meta.url)), { recursive: true }, (_e, file) => {
|
|
201
|
+
if (!file || !/\.ts$/.test(file) || /\.test\.ts$|smoke\.ts$/.test(file)) return;
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
timer = setTimeout(() => (log(`${file} changed, restarting`), process.exit(0)), 400);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
armIdle();
|
|
207
|
+
log(`ready, ws on 127.0.0.1:${PORT}`);
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { closeSync, openSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { WebSocket } from "ws";
|
|
14
|
+
if (process.argv[2] === "stop") {
|
|
15
|
+
await import(new URL(import.meta.url.endsWith(".ts") ? "./stop.ts" : "./stop.js", import.meta.url).href);
|
|
16
|
+
await new Promise(() => {
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
var log = (...a) => console.error("[proxy]", ...a);
|
|
20
|
+
var PORT = Number(process.env.MELODUO_PORT ?? 8787);
|
|
21
|
+
var ENDPOINT = `ws://127.0.0.1:${PORT}/agent`;
|
|
22
|
+
function spawnDaemon() {
|
|
23
|
+
const logFile = openSync(join(tmpdir(), "meloduo-bridge.log"), "a");
|
|
24
|
+
const dev = import.meta.url.endsWith(".ts");
|
|
25
|
+
const daemon2 = fileURLToPath(new URL(dev ? "./daemon.ts" : "./daemon.js", import.meta.url));
|
|
26
|
+
const child = spawn(process.execPath, dev ? ["--import", "tsx", daemon2] : [daemon2], {
|
|
27
|
+
// tsx resolves from the package folder; the package runs from temp so it never locks the npx cache folder on Windows.
|
|
28
|
+
cwd: dev ? fileURLToPath(new URL("..", import.meta.url)) : tmpdir(),
|
|
29
|
+
detached: true,
|
|
30
|
+
windowsHide: true,
|
|
31
|
+
stdio: ["ignore", logFile, logFile]
|
|
32
|
+
});
|
|
33
|
+
child.unref();
|
|
34
|
+
closeSync(logFile);
|
|
35
|
+
log(`started the shared bridge (log: ${join(tmpdir(), "meloduo-bridge.log")})`);
|
|
36
|
+
}
|
|
37
|
+
var daemon;
|
|
38
|
+
var defs = [];
|
|
39
|
+
var known = false;
|
|
40
|
+
var lastSpawn = 0;
|
|
41
|
+
var nextId = 1;
|
|
42
|
+
var pending = /* @__PURE__ */ new Map();
|
|
43
|
+
var client = null;
|
|
44
|
+
var pick;
|
|
45
|
+
var sid = randomUUID();
|
|
46
|
+
var INSTRUCTIONS = [
|
|
47
|
+
"Meloduo is a browser DAW (channel rack, piano roll, playlist, mixer). You edit the project open in the user's tab, and the user sees each edit at once.",
|
|
48
|
+
"- Start with get_project_state. Take ids from it and from tool results: ids have gaps, so never guess the next one.",
|
|
49
|
+
`- Every edit tool takes why: one short sentence for the user, in the user's language, with the reason, not the arguments ("bass an octave down so it does not fight the kick").`,
|
|
50
|
+
"- A call is all or nothing. Your whole turn is one undo step for the user.",
|
|
51
|
+
"- If someone changed the project since your last call, the result has changedSinceYourLastCall. Keep those edits. An edit after such changes is rejected once with the list (STALE_EDIT); retry it if it still makes sense.",
|
|
52
|
+
"- Units: a step is a 1/16 note, 16 per bar, counted from 0 inside a pattern. Bars count from 0; a range fromBar\u2026toBar includes fromBar and excludes toBar. pitch is MIDI (60 = C4). Levels are in dB.",
|
|
53
|
+
'- A choice parameter takes its option name or its number: "1/16", "Ladder".',
|
|
54
|
+
"- Descriptions are short. Ranges, options, presets and notes come from get_synth, get_drum, get_808, get_effect and get_web_plugin. An error names the allowed values and the next step.",
|
|
55
|
+
"- You cannot hear the audio. render_preview returns loudness, spectrum and warnings: decide by them, edit, render again.",
|
|
56
|
+
"- Several tabs open: list_tabs and use_tab pick the project."
|
|
57
|
+
].join("\n");
|
|
58
|
+
var server = new Server({ name: "meloduo", version: "0.0.1" }, { capabilities: { tools: { listChanged: true } }, instructions: INSTRUCTIONS });
|
|
59
|
+
function connect() {
|
|
60
|
+
const ws = new WebSocket(ENDPOINT);
|
|
61
|
+
ws.on("open", () => {
|
|
62
|
+
daemon = ws;
|
|
63
|
+
ws.send(JSON.stringify({ type: "hello", client, pick, sid }));
|
|
64
|
+
ws.send(JSON.stringify({ type: "tools" }));
|
|
65
|
+
});
|
|
66
|
+
ws.on("message", (raw) => {
|
|
67
|
+
let msg;
|
|
68
|
+
try {
|
|
69
|
+
msg = JSON.parse(raw.toString());
|
|
70
|
+
} catch {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (msg.type === "pick") return void (pick = msg.pick ?? void 0);
|
|
74
|
+
if (msg.type === "tools") {
|
|
75
|
+
const changed = known && JSON.stringify(msg.tools) !== JSON.stringify(defs);
|
|
76
|
+
defs = msg.tools ?? [];
|
|
77
|
+
known = true;
|
|
78
|
+
if (changed) void server.sendToolListChanged().catch(() => {
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const call = msg.id === void 0 ? void 0 : pending.get(msg.id);
|
|
83
|
+
if (!call || msg.id === void 0) return;
|
|
84
|
+
pending.delete(msg.id);
|
|
85
|
+
msg.error ? call.reject(new Error(msg.error)) : call.resolve(msg.result);
|
|
86
|
+
});
|
|
87
|
+
ws.on("error", () => {
|
|
88
|
+
});
|
|
89
|
+
ws.on("close", () => {
|
|
90
|
+
if (daemon === ws) daemon = void 0;
|
|
91
|
+
for (const [id, call] of pending) pending.delete(id), call.reject(new Error("The bridge restarted during the call. Call get_project_state, then retry."));
|
|
92
|
+
if (Date.now() - lastSpawn > 3e3) {
|
|
93
|
+
lastSpawn = Date.now();
|
|
94
|
+
spawnDaemon();
|
|
95
|
+
}
|
|
96
|
+
setTimeout(connect, 400);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
var whenReady = async () => {
|
|
100
|
+
const deadline = Date.now() + 2e4;
|
|
101
|
+
while (!(daemon && daemon.readyState === WebSocket.OPEN && defs.length)) {
|
|
102
|
+
if (Date.now() > deadline) throw new Error(`The Meloduo bridge did not start. See its log in ${join(tmpdir(), "meloduo-bridge.log")}, then retry.`);
|
|
103
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => (await whenReady(), { tools: defs }));
|
|
107
|
+
server.setRequestHandler(CallToolRequestSchema, async ({ params }, extra) => {
|
|
108
|
+
try {
|
|
109
|
+
await whenReady();
|
|
110
|
+
const id = nextId++;
|
|
111
|
+
const result = await new Promise((resolve, reject) => {
|
|
112
|
+
pending.set(id, { resolve, reject });
|
|
113
|
+
daemon.send(JSON.stringify({ id, tool: params.name, args: params.arguments ?? {} }));
|
|
114
|
+
extra.signal.addEventListener("abort", () => daemon?.send(JSON.stringify({ type: "cancel", id })), { once: true });
|
|
115
|
+
});
|
|
116
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return { isError: true, content: [{ type: "text", text: String(e instanceof Error ? e.message : e) }] };
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
server.oninitialized = () => {
|
|
122
|
+
const v = server.getClientVersion();
|
|
123
|
+
client = v ? { name: v.name, version: v.version } : null;
|
|
124
|
+
log(`client ${client?.name ?? "?"} ${client?.version ?? ""}`);
|
|
125
|
+
if (daemon?.readyState === WebSocket.OPEN) daemon.send(JSON.stringify({ type: "hello", client, pick, sid }));
|
|
126
|
+
};
|
|
127
|
+
server.onclose = () => setTimeout(() => process.exit(0), 100);
|
|
128
|
+
connect();
|
|
129
|
+
await server.connect(new StdioServerTransport());
|
|
130
|
+
log("ready");
|
package/dist/stop.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/stop.ts
|
|
4
|
+
import { WebSocket } from "ws";
|
|
5
|
+
var PORT = Number(process.env.MELODUO_PORT ?? 8787);
|
|
6
|
+
var ws = new WebSocket(`ws://127.0.0.1:${PORT}/agent`);
|
|
7
|
+
ws.on("open", () => (ws.send(JSON.stringify({ type: "quit" })), console.log(`bridge on ${PORT} stopped`), setTimeout(() => process.exit(0), 100)));
|
|
8
|
+
ws.on("error", () => (console.log(`no bridge on ${PORT}`), process.exit(0)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meloduo/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP bridge for Meloduo, a browser DAW: lets any MCP client edit the project open in your browser tab.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"daw",
|
|
9
|
+
"music",
|
|
10
|
+
"meloduo"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Ilya Shumchenko <meloduo.demo@gmail.com>",
|
|
14
|
+
"homepage": "https://meloduo.github.io/",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/meloduo/meloduo-agent.git",
|
|
18
|
+
"directory": "mcp"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"meloduo-mcp": "dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"start": "tsx src/index.ts",
|
|
32
|
+
"stop": "tsx src/stop.ts",
|
|
33
|
+
"smoke": "tsx src/smoke.ts",
|
|
34
|
+
"typecheck": "tsc -p .",
|
|
35
|
+
"build": "esbuild src/index.ts src/daemon.ts src/stop.ts --bundle --platform=node --format=esm --target=node20 --packages=external --outdir=dist --banner:js=\"#!/usr/bin/env node\"",
|
|
36
|
+
"prepublishOnly": "pnpm typecheck && pnpm build"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
40
|
+
"ws": "^8.18.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"@types/ws": "^8.5.12",
|
|
45
|
+
"esbuild": "^0.28.2",
|
|
46
|
+
"tsx": "^4.19.0",
|
|
47
|
+
"typescript": "^5.6.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/README.md
DELETED