chord-mcp 1.0.0 → 1.0.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/README.md CHANGED
@@ -19,3 +19,22 @@ node dist/index.js
19
19
  ```
20
20
 
21
21
  All music theory runs locally.
22
+
23
+ <!-- paywall -->
24
+ ## Premium tools
25
+
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
@@ -42,3 +42,87 @@ export async function scaleNotes(args) {
42
42
  const notes = intervals.map((iv) => NOTES[(r + iv) % 12]);
43
43
  return `${root} ${scale}: ${notes.join(" - ")}`;
44
44
  }
45
+ // ---- muxA tools:
46
+ const INTERVAL_NAMES = [
47
+ "unison", "minor 2nd", "major 2nd", "minor 3rd", "major 3rd", "perfect 4th",
48
+ "tritone", "perfect 5th", "minor 6th", "major 6th", "minor 7th", "major 7th",
49
+ "octave",
50
+ ];
51
+ // The 17 standard key signatures, by tonic spelling. A key signature is really
52
+ // a position on the circle of fifths, so a key is stored as a signed accidental
53
+ // count: positive is sharps, negative is flats.
54
+ const MAJOR_SHARPS_BY_NAME = {
55
+ C: 0, G: 1, D: 2, A: 3, E: 4, B: 5, "F#": 6, "C#": 7, "D#": 9, "A#": 10,
56
+ F: -1, Bb: -2, Eb: -3, Ab: -4, Db: -5, Gb: -6,
57
+ };
58
+ // Same thing indexed by pitch class, for tonics the name table does not cover.
59
+ const MAJOR_SHARPS_BY_CLASS = {
60
+ 5: -1, 0: 0, 7: 1, 2: 2, 9: 3, 4: 4, 11: 5, 6: 6, 1: 7, 8: 8, 3: 9, 10: 10,
61
+ };
62
+ const SHARP_ORDER = ["F", "C", "G", "D", "A", "E", "B"];
63
+ const FLAT_ORDER = ["B", "E", "A", "D", "G", "C", "F"];
64
+ function sharpsForMajor(root, pitchClass) {
65
+ const named = MAJOR_SHARPS_BY_NAME[root];
66
+ if (named !== undefined)
67
+ return named;
68
+ const byClass = MAJOR_SHARPS_BY_CLASS[pitchClass];
69
+ // Beyond the standard signatures the count keeps climbing by fifths; say so
70
+ // rather than inventing a signature nobody uses.
71
+ if (byClass === undefined) {
72
+ throw new ChordError(`No standard key signature for ${root}. Try a tonic like C#, F# or Bb.`);
73
+ }
74
+ return byClass;
75
+ }
76
+ function accidentals(count) {
77
+ if (count === 0)
78
+ return "none";
79
+ const order = count > 0 ? SHARP_ORDER : FLAT_ORDER;
80
+ return order.slice(0, Math.abs(count)).map((n) => `${n}${count > 0 ? "#" : "b"}`).join(" ");
81
+ }
82
+ function spell(index) {
83
+ return NOTES[((index % 12) + 12) % 12];
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
+ }
@@ -0,0 +1,79 @@
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
+ }
package/dist/server.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { chordNotes } from "./api.js";
4
- import { scaleNotes } from "./api.js";
4
+ import { scaleNotes, intervalBetween, keySignature } from "./api.js";
5
+ import { premiumRequired } from "./license.js";
5
6
  const text = (value) => ({ content: [{ type: "text", text: value }] });
6
7
  const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
7
8
  const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
@@ -34,5 +35,41 @@ export function createServer() {
34
35
  return textError(error(e));
35
36
  }
36
37
  });
38
+ server.registerTool("interval_between", {
39
+ title: "Interval between notes",
40
+ description: "Name and size of the interval between two notes, in semitones and cents.",
41
+ inputSchema: z.object({ from: z.string().describe("Lower note, e.g. C."), to: z.string().describe("Upper note, e.g. G.") }),
42
+ annotations: READ_ONLY,
43
+ }, async (args) => {
44
+ // ---- paywall: interval_between ----
45
+ const paywallMessage = await premiumRequired("interval_between");
46
+ if (paywallMessage)
47
+ return { content: [{ type: "text", text: paywallMessage }], isError: true };
48
+ // ---- paywall: end ----
49
+ try {
50
+ return text(await intervalBetween(args));
51
+ }
52
+ catch (e) {
53
+ return textError(error(e));
54
+ }
55
+ });
56
+ server.registerTool("key_signature", {
57
+ title: "Key signature",
58
+ description: "Accidentals in a key signature, the sharps or flats by name, and the relative key.",
59
+ inputSchema: z.object({ root: z.string().describe("Tonic, e.g. D or Bb."), scale: z.string().describe("major or minor.").optional() }),
60
+ annotations: READ_ONLY,
61
+ }, async (args) => {
62
+ // ---- paywall: key_signature ----
63
+ const paywallMessage = await premiumRequired("key_signature");
64
+ if (paywallMessage)
65
+ return { content: [{ type: "text", text: paywallMessage }], isError: true };
66
+ // ---- paywall: end ----
67
+ try {
68
+ return text(await keySignature(args));
69
+ }
70
+ catch (e) {
71
+ return textError(error(e));
72
+ }
73
+ });
37
74
  return server;
38
75
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0",
2
+ "version": "1.0.2",
3
3
  "type": "module",
4
4
  "repository": {
5
5
  "type": "git",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/mrfentmen/chord-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "1.0.0",
9
+ "version": "1.0.1",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "chord-mcp",
14
- "version": "1.0.0",
14
+ "version": "1.0.1",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  }