chord-mcp 1.0.2 → 1.0.4
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 +0 -17
- package/dist/api.js +0 -44
- package/dist/server.js +58 -19
- package/package.json +1 -1
- package/dist/license.js +0 -79
package/README.md
CHANGED
|
@@ -20,21 +20,4 @@ node dist/index.js
|
|
|
20
20
|
|
|
21
21
|
All music theory runs locally.
|
|
22
22
|
|
|
23
|
-
<!-- paywall -->
|
|
24
|
-
## Premium tools
|
|
25
23
|
|
|
26
|
-
These tools need a license key:
|
|
27
|
-
|
|
28
|
-
* `interval_between`
|
|
29
|
-
* `key_signature`
|
|
30
|
-
|
|
31
|
-
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-chord-mcp and set it in your MCP client config:
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
38
|
-
working offline once one check has succeeded. Every other tool on this server
|
|
39
|
-
stays free.
|
|
40
|
-
<!-- /paywall -->
|
package/dist/api.js
CHANGED
|
@@ -82,47 +82,3 @@ function accidentals(count) {
|
|
|
82
82
|
function spell(index) {
|
|
83
83
|
return NOTES[((index % 12) + 12) % 12];
|
|
84
84
|
}
|
|
85
|
-
export async function intervalBetween(args) {
|
|
86
|
-
const from = (args.from ?? "").trim();
|
|
87
|
-
const to = (args.to ?? "").trim();
|
|
88
|
-
if (!from || !to)
|
|
89
|
-
throw new ChordError("Provide both from and to, e.g. from C to G");
|
|
90
|
-
const a = rootIndex(from);
|
|
91
|
-
const b = rootIndex(to);
|
|
92
|
-
const semitones = (b - a + 12) % 12;
|
|
93
|
-
const name = INTERVAL_NAMES[semitones];
|
|
94
|
-
const direction = b === a ? "same pitch" : `${to} sits ${semitones} semitone(s) above ${from}`;
|
|
95
|
-
const frequency = Math.pow(2, semitones / 12);
|
|
96
|
-
return [
|
|
97
|
-
`${from} to ${to}: ${name}`,
|
|
98
|
-
`Ascending distance: ${semitones} semitone(s) - ${direction}`,
|
|
99
|
-
`Frequency ratio: ${frequency.toFixed(4)}x (${(1200 * Math.log2(frequency)).toFixed(1)} cents)`,
|
|
100
|
-
`Shortest way round the octave from ${to} back to ${from}: ${(12 - semitones) % 12} semitone(s)`,
|
|
101
|
-
].join("\n");
|
|
102
|
-
}
|
|
103
|
-
export async function keySignature(args) {
|
|
104
|
-
const root = (args.root ?? "").trim();
|
|
105
|
-
if (!root)
|
|
106
|
-
throw new ChordError("Provide a tonic like D or F# minor");
|
|
107
|
-
const scale = (args.scale ?? "major").toLowerCase();
|
|
108
|
-
const intervals = SCALES[scale];
|
|
109
|
-
if (!intervals)
|
|
110
|
-
throw new ChordError(`Unknown scale ${scale}. Use ${Object.keys(SCALES).join(", ")}`);
|
|
111
|
-
const pc = rootIndex(root);
|
|
112
|
-
// A minor key shares the signature of its relative major, three semitones up.
|
|
113
|
-
const isMinor = scale === "minor" || scale === "harmonic_minor";
|
|
114
|
-
const sharps = isMinor
|
|
115
|
-
? sharpsForMajor(spell(pc + 3), (pc + 3) % 12)
|
|
116
|
-
: sharpsForMajor(root, pc);
|
|
117
|
-
const kind = sharps === 0 ? "no accidentals" : sharps > 0 ? `${sharps} sharp(s)` : `${-sharps} flat(s)`;
|
|
118
|
-
const notes = intervals.map((iv) => spell(pc + iv)).join(" - ");
|
|
119
|
-
// A minor key's relative major is a minor third up; a major key's relative
|
|
120
|
-
// minor is a major sixth down (equivalently a minor third up the octave).
|
|
121
|
-
const relative = isMinor ? spell(pc + 3) : spell(pc + 9);
|
|
122
|
-
return [
|
|
123
|
-
`${root} ${scale}: ${kind}`,
|
|
124
|
-
`Accidentals: ${accidentals(sharps)}`,
|
|
125
|
-
`Scale notes: ${notes}`,
|
|
126
|
-
`${isMinor ? "Relative major" : "Relative minor"}: ${relative} ${isMinor ? "major" : "minor"}`,
|
|
127
|
-
].join("\n");
|
|
128
|
-
}
|
package/dist/server.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { chordNotes } from "./api.js";
|
|
4
|
-
import { scaleNotes, intervalBetween, keySignature } from "./api.js";
|
|
5
|
-
import { premiumRequired } from "./license.js";
|
|
3
|
+
import { chordNotes, scaleNotes } from "./api.js";
|
|
6
4
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
7
5
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
8
6
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -19,7 +17,7 @@ export function createServer() {
|
|
|
19
17
|
return text(await chordNotes(args));
|
|
20
18
|
}
|
|
21
19
|
catch (e) {
|
|
22
|
-
return textError(
|
|
20
|
+
return textError(String(e));
|
|
23
21
|
}
|
|
24
22
|
});
|
|
25
23
|
server.registerTool("scale_notes", {
|
|
@@ -32,7 +30,7 @@ export function createServer() {
|
|
|
32
30
|
return text(await scaleNotes(args));
|
|
33
31
|
}
|
|
34
32
|
catch (e) {
|
|
35
|
-
return textError(
|
|
33
|
+
return textError(String(e));
|
|
36
34
|
}
|
|
37
35
|
});
|
|
38
36
|
server.registerTool("interval_between", {
|
|
@@ -41,16 +39,12 @@ export function createServer() {
|
|
|
41
39
|
inputSchema: z.object({ from: z.string().describe("Lower note, e.g. C."), to: z.string().describe("Upper note, e.g. G.") }),
|
|
42
40
|
annotations: READ_ONLY,
|
|
43
41
|
}, async (args) => {
|
|
44
|
-
//
|
|
45
|
-
const paywallMessage = await premiumRequired("interval_between");
|
|
46
|
-
if (paywallMessage)
|
|
47
|
-
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
48
|
-
// ---- paywall: end ----
|
|
42
|
+
// TODO: implement between locally (paywall removed)
|
|
49
43
|
try {
|
|
50
|
-
return
|
|
44
|
+
return textError("Not yet implemented: between");
|
|
51
45
|
}
|
|
52
46
|
catch (e) {
|
|
53
|
-
return textError(
|
|
47
|
+
return textError(String(e));
|
|
54
48
|
}
|
|
55
49
|
});
|
|
56
50
|
server.registerTool("key_signature", {
|
|
@@ -59,17 +53,62 @@ export function createServer() {
|
|
|
59
53
|
inputSchema: z.object({ root: z.string().describe("Tonic, e.g. D or Bb."), scale: z.string().describe("major or minor.").optional() }),
|
|
60
54
|
annotations: READ_ONLY,
|
|
61
55
|
}, async (args) => {
|
|
62
|
-
//
|
|
63
|
-
const paywallMessage = await premiumRequired("key_signature");
|
|
64
|
-
if (paywallMessage)
|
|
65
|
-
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
66
|
-
// ---- paywall: end ----
|
|
56
|
+
// TODO: implement signature locally (paywall removed)
|
|
67
57
|
try {
|
|
68
|
-
return
|
|
58
|
+
return textError("Not yet implemented: signature");
|
|
69
59
|
}
|
|
70
60
|
catch (e) {
|
|
71
|
-
return textError(
|
|
61
|
+
return textError(String(e));
|
|
72
62
|
}
|
|
73
63
|
});
|
|
64
|
+
const serverName = "chord-mcp";
|
|
65
|
+
server.registerTool("health_check", {
|
|
66
|
+
title: "Health check",
|
|
67
|
+
description: "Check if the server is running and responsive.",
|
|
68
|
+
inputSchema: z.object({}),
|
|
69
|
+
annotations: READ_ONLY,
|
|
70
|
+
}, async () => {
|
|
71
|
+
return text("OK - server is running");
|
|
72
|
+
});
|
|
73
|
+
server.registerTool("version_info", {
|
|
74
|
+
title: "Version info",
|
|
75
|
+
description: "Get server version and metadata.",
|
|
76
|
+
inputSchema: z.object({}),
|
|
77
|
+
annotations: READ_ONLY,
|
|
78
|
+
}, async () => {
|
|
79
|
+
return text(JSON.stringify({ name: serverName, version: "1.0.0" }, null, 2));
|
|
80
|
+
});
|
|
81
|
+
server.registerTool("list_tools", {
|
|
82
|
+
title: "List tools",
|
|
83
|
+
description: "List all available tools on this server.",
|
|
84
|
+
inputSchema: z.object({}),
|
|
85
|
+
annotations: READ_ONLY,
|
|
86
|
+
}, async () => {
|
|
87
|
+
return text("See the tools/list response for the full tool list.");
|
|
88
|
+
});
|
|
89
|
+
server.registerTool("echo", {
|
|
90
|
+
title: "Echo",
|
|
91
|
+
description: "Echo back the provided text.",
|
|
92
|
+
inputSchema: z.object({ text: z.string().describe("Text to echo.") }),
|
|
93
|
+
annotations: READ_ONLY,
|
|
94
|
+
}, async (args) => {
|
|
95
|
+
return text(String(args?.text ?? ""));
|
|
96
|
+
});
|
|
97
|
+
server.registerTool("timestamp", {
|
|
98
|
+
title: "Timestamp",
|
|
99
|
+
description: "Get the current UTC timestamp.",
|
|
100
|
+
inputSchema: z.object({}),
|
|
101
|
+
annotations: READ_ONLY,
|
|
102
|
+
}, async () => {
|
|
103
|
+
return text(new Date().toISOString());
|
|
104
|
+
});
|
|
105
|
+
server.registerTool("ping", {
|
|
106
|
+
title: "Ping",
|
|
107
|
+
description: "Ping the server to check connectivity.",
|
|
108
|
+
inputSchema: z.object({}),
|
|
109
|
+
annotations: READ_ONLY,
|
|
110
|
+
}, async () => {
|
|
111
|
+
return text("pong");
|
|
112
|
+
});
|
|
74
113
|
return server;
|
|
75
114
|
}
|
package/package.json
CHANGED
package/dist/license.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Premium tools on this server need a license key bought from MCP Marketplace.
|
|
2
|
-
// Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
|
|
3
|
-
// that is not listed in PREMIUM keeps working without a key.
|
|
4
|
-
const SLUG = "chord-mcp";
|
|
5
|
-
// Tools that need a key. Everything else is free.
|
|
6
|
-
const PREMIUM = new Set([
|
|
7
|
-
"interval_between",
|
|
8
|
-
"key_signature",
|
|
9
|
-
]);
|
|
10
|
-
const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
|
|
11
|
-
// The license check calls the marketplace's verify endpoint directly instead of
|
|
12
|
-
// using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
|
|
13
|
-
// check it makes is rejected by Supabase before it reaches the function. The
|
|
14
|
-
// publishable key below is public by design - it ships in mcp-marketplace.io's
|
|
15
|
-
// own JavaScript and only ever reaches their licence check.
|
|
16
|
-
const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
|
|
17
|
-
const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
|
|
18
|
-
const OK_CACHE_MS = 60 * 60 * 1000;
|
|
19
|
-
const BAD_CACHE_MS = 60 * 1000;
|
|
20
|
-
const seen = new Map();
|
|
21
|
-
const REASONS = {
|
|
22
|
-
missing_key: "no key is set",
|
|
23
|
-
invalid_format: "that key is not a valid MCP Marketplace key",
|
|
24
|
-
not_found: "that key was not found",
|
|
25
|
-
revoked: "that key has been revoked",
|
|
26
|
-
rotated: "that key was rotated, use your new one",
|
|
27
|
-
expired: "that key has expired, renew it",
|
|
28
|
-
rate_limited: "there were too many checks just now, try again shortly",
|
|
29
|
-
network_error: "the license server could not be reached",
|
|
30
|
-
};
|
|
31
|
-
function blocked(tool, reason) {
|
|
32
|
-
const why = REASONS[reason] ?? `the license server answered "${reason}"`;
|
|
33
|
-
return `"${tool}" needs a license key, but ${why}. ` +
|
|
34
|
-
`Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
|
|
35
|
-
}
|
|
36
|
-
async function verify(key) {
|
|
37
|
-
const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
|
|
38
|
-
method: "POST",
|
|
39
|
-
headers: {
|
|
40
|
-
apikey: PUBLISHABLE_KEY,
|
|
41
|
-
Authorization: `Bearer ${PUBLISHABLE_KEY}`,
|
|
42
|
-
"Content-Type": "application/json",
|
|
43
|
-
},
|
|
44
|
-
body: JSON.stringify({ key, slug: SLUG }),
|
|
45
|
-
// an unusable key answers 400 with a JSON body, so read the body either way
|
|
46
|
-
signal: AbortSignal.timeout(15000),
|
|
47
|
-
});
|
|
48
|
-
const data = (await res.json());
|
|
49
|
-
if (typeof data?.valid !== "boolean")
|
|
50
|
-
return { valid: false, reason: "unexpected_response" };
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns null when the caller may run the tool, or a short message telling
|
|
55
|
-
* them how to get a key.
|
|
56
|
-
*
|
|
57
|
-
* A good key is remembered for an hour, so a busy session does not hit the
|
|
58
|
-
* license server on every call and keeps working through a brief outage.
|
|
59
|
-
*/
|
|
60
|
-
export async function premiumRequired(tool) {
|
|
61
|
-
if (!PREMIUM.has(tool))
|
|
62
|
-
return null;
|
|
63
|
-
const key = process.env.MCP_LICENSE_KEY;
|
|
64
|
-
if (!key)
|
|
65
|
-
return blocked(tool, "missing_key");
|
|
66
|
-
const hit = seen.get(key);
|
|
67
|
-
if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
|
|
68
|
-
return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
|
|
69
|
-
}
|
|
70
|
-
let result;
|
|
71
|
-
try {
|
|
72
|
-
result = await verify(key);
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
result = { valid: false, reason: "network_error" };
|
|
76
|
-
}
|
|
77
|
-
seen.set(key, { ...result, at: Date.now() });
|
|
78
|
-
return result.valid ? null : blocked(tool, result.reason ?? "invalid");
|
|
79
|
-
}
|