cocktails-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 +19 -0
- package/dist/api.js +162 -0
- package/dist/license.js +79 -0
- package/dist/server.js +51 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -20,3 +20,22 @@ node dist/index.js
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
Recipe data comes from the public TheCocktailDB API.
|
|
23
|
+
|
|
24
|
+
<!-- paywall -->
|
|
25
|
+
## Premium tools
|
|
26
|
+
|
|
27
|
+
These tools need a license key:
|
|
28
|
+
|
|
29
|
+
* `filter_cocktails`
|
|
30
|
+
* `shopping_list`
|
|
31
|
+
|
|
32
|
+
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-cocktails-mcp and set it in your MCP client config:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
39
|
+
working offline once one check has succeeded. Every other tool on this server
|
|
40
|
+
stays free.
|
|
41
|
+
<!-- /paywall -->
|
package/dist/api.js
CHANGED
|
@@ -51,3 +51,165 @@ export async function cocktailDetails(args) {
|
|
|
51
51
|
const ings = ingredients(c);
|
|
52
52
|
return `# ${c.strDrink}\n${c.strAlcoholic ?? ""} | ${c.strGlass ?? ""}\n\nIngredients:\n${ings.map((i) => `- ${i}`).join("\n")}\n\nInstructions:\n${c.strInstructions ?? ""}`;
|
|
53
53
|
}
|
|
54
|
+
const COCKTAIL_PARAM = { category: "c", glass: "g", strength: "a" };
|
|
55
|
+
const COCKTAIL_LIST_KEY = {
|
|
56
|
+
category: "strCategory",
|
|
57
|
+
glass: "strGlass",
|
|
58
|
+
strength: "strAlcoholic",
|
|
59
|
+
};
|
|
60
|
+
const COCKTAIL_FACETS = ["category", "glass", "strength"];
|
|
61
|
+
// filter.php answers an unknown value with the string "no data found" instead
|
|
62
|
+
// of an empty list, so the shape has to be checked rather than trusted.
|
|
63
|
+
function cocktailRows(payload) {
|
|
64
|
+
return Array.isArray(payload?.drinks) ? payload.drinks : null;
|
|
65
|
+
}
|
|
66
|
+
async function cocktailFacetValues(facet) {
|
|
67
|
+
const d = await get(`${BASE}/list.php?${COCKTAIL_PARAM[facet]}=list`);
|
|
68
|
+
const rows = Array.isArray(d?.drinks) ? d.drinks : [];
|
|
69
|
+
const key = COCKTAIL_LIST_KEY[facet];
|
|
70
|
+
return rows
|
|
71
|
+
.map((row) => row?.[key])
|
|
72
|
+
.filter((value) => typeof value === "string" && value.trim().length > 0);
|
|
73
|
+
}
|
|
74
|
+
function cocktailFacet(facet) {
|
|
75
|
+
return COCKTAIL_FACETS.includes(facet) ? facet : null;
|
|
76
|
+
}
|
|
77
|
+
function cocktailPairs(drink) {
|
|
78
|
+
const pairs = [];
|
|
79
|
+
for (let i = 1; i <= 15; i++) {
|
|
80
|
+
const name = drink?.[`strIngredient${i}`];
|
|
81
|
+
if (typeof name !== "string" || !name.trim())
|
|
82
|
+
continue;
|
|
83
|
+
const measure = drink?.[`strMeasure${i}`];
|
|
84
|
+
pairs.push({ name: name.trim(), measure: typeof measure === "string" ? measure.trim() : "" });
|
|
85
|
+
}
|
|
86
|
+
return pairs;
|
|
87
|
+
}
|
|
88
|
+
function cocktailSummary(drink) {
|
|
89
|
+
const parts = [drink?.strCategory, drink?.strAlcoholic, drink?.strGlass].filter((value) => typeof value === "string" && value.trim());
|
|
90
|
+
return parts.length ? parts.join(" | ") : "no classification published";
|
|
91
|
+
}
|
|
92
|
+
export async function filterCocktails(args) {
|
|
93
|
+
const wanted = (args.facet ?? "").trim().toLowerCase();
|
|
94
|
+
const limit = Math.max(1, Math.min(Math.trunc(args.limit ?? 25) || 25, 100));
|
|
95
|
+
if (!wanted) {
|
|
96
|
+
const lines = ["Cocktails can be browsed by three facets:"];
|
|
97
|
+
for (const facet of COCKTAIL_FACETS) {
|
|
98
|
+
const values = await cocktailFacetValues(facet);
|
|
99
|
+
lines.push("", ` ${facet} (${values.length}): ${values.join(", ")}`);
|
|
100
|
+
}
|
|
101
|
+
lines.push("", " Pass facet and value to list the cocktails in one of them.");
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
const facet = cocktailFacet(wanted);
|
|
105
|
+
if (!facet) {
|
|
106
|
+
throw new CocktailsError(`Unknown facet "${args.facet}". Use one of ${COCKTAIL_FACETS.join(", ")}`);
|
|
107
|
+
}
|
|
108
|
+
const values = await cocktailFacetValues(facet);
|
|
109
|
+
const value = (args.value ?? "").trim();
|
|
110
|
+
if (!value) {
|
|
111
|
+
return [
|
|
112
|
+
`${facet} values (${values.length}):`,
|
|
113
|
+
...values.map((entry) => ` ${entry}`),
|
|
114
|
+
"",
|
|
115
|
+
" Pass one of these as value to list the cocktails in it.",
|
|
116
|
+
].join("\n");
|
|
117
|
+
}
|
|
118
|
+
const requested = value.toLowerCase();
|
|
119
|
+
const match = values.find((entry) => entry.toLowerCase() === requested) ?? values.find((entry) => entry.toLowerCase().includes(requested));
|
|
120
|
+
if (!match) {
|
|
121
|
+
throw new CocktailsError(`TheCocktailDB has no ${facet} called "${value}". It lists ${values.length}: ${values.join(", ")}`);
|
|
122
|
+
}
|
|
123
|
+
// The public key expects spaces in the filter value, which encoding handles.
|
|
124
|
+
const d = await get(`${BASE}/filter.php?${COCKTAIL_PARAM[facet]}=${encodeURIComponent(match)}`);
|
|
125
|
+
const rows = cocktailRows(d);
|
|
126
|
+
if (!rows) {
|
|
127
|
+
return `TheCocktailDB returned no cocktails for ${facet} "${match}".`;
|
|
128
|
+
}
|
|
129
|
+
if (!rows.length)
|
|
130
|
+
return `TheCocktailDB has no cocktails in ${facet} "${match}".`;
|
|
131
|
+
const shown = rows.slice(0, limit);
|
|
132
|
+
const lines = [
|
|
133
|
+
`Cocktails in ${facet} "${match}": ${rows.length} returned${rows.length === 100 ? ", which is the cap the public key applies" : ""}`,
|
|
134
|
+
...shown.map((row) => ` ${row.strDrink ?? "?"} (id ${row.idDrink ?? "?"})`),
|
|
135
|
+
];
|
|
136
|
+
if (rows.length > shown.length)
|
|
137
|
+
lines.push(` ${rows.length - shown.length} more, raise limit to see them`);
|
|
138
|
+
lines.push("", " The value is matched against the published facet list, so it does not have to be spelled exactly as the endpoint expects.");
|
|
139
|
+
return lines.join("\n");
|
|
140
|
+
}
|
|
141
|
+
export async function shoppingList(args) {
|
|
142
|
+
const raw = Array.isArray(args.ids) ? args.ids : [];
|
|
143
|
+
const ids = [...new Set(raw.flatMap((entry) => String(entry ?? "").split(/[\s,]+/)).filter((entry) => entry.trim()))].slice(0, 12);
|
|
144
|
+
if (!ids.length)
|
|
145
|
+
throw new CocktailsError("Provide one or more cocktail ids, like [\"11007\", \"11117\"]");
|
|
146
|
+
const needed = new Map();
|
|
147
|
+
const missing = [];
|
|
148
|
+
const found = [];
|
|
149
|
+
for (const id of ids) {
|
|
150
|
+
const d = await get(`${BASE}/lookup.php?i=${encodeURIComponent(id)}`);
|
|
151
|
+
const drink = Array.isArray(d?.drinks) ? d.drinks[0] : null;
|
|
152
|
+
if (!drink) {
|
|
153
|
+
missing.push(id);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const name = typeof drink.strDrink === "string" ? drink.strDrink : `id ${id}`;
|
|
157
|
+
found.push(`${name} (id ${id})`);
|
|
158
|
+
for (const pair of cocktailPairs(drink)) {
|
|
159
|
+
const key = pair.name.toLowerCase();
|
|
160
|
+
const bucket = needed.get(key) ?? { measures: new Set(), drinks: new Set() };
|
|
161
|
+
if (pair.measure)
|
|
162
|
+
bucket.measures.add(pair.measure);
|
|
163
|
+
bucket.drinks.add(name);
|
|
164
|
+
needed.set(key, bucket);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!needed.size) {
|
|
168
|
+
return `None of the given ids resolved to a cocktail (${missing.join(", ")}). TheCocktailDB answers an unknown id with an empty drink list.`;
|
|
169
|
+
}
|
|
170
|
+
const ordered = [...needed.entries()].sort((a, b) => {
|
|
171
|
+
const spread = b[1].drinks.size - a[1].drinks.size;
|
|
172
|
+
return spread !== 0 ? spread : a[0].localeCompare(b[0]);
|
|
173
|
+
});
|
|
174
|
+
const shared = ordered.filter(([, bucket]) => bucket.drinks.size > 1);
|
|
175
|
+
const lines = [
|
|
176
|
+
`Shopping list for ${found.length} cocktail${found.length === 1 ? "" : "s"}: ${needed.size} distinct ingredients`,
|
|
177
|
+
"",
|
|
178
|
+
...found.map((entry) => ` ${entry}`),
|
|
179
|
+
"",
|
|
180
|
+
...ordered.map(([key, bucket]) => {
|
|
181
|
+
const name = key.replace(/\b[a-z]/g, (letter) => letter.toUpperCase());
|
|
182
|
+
const measures = [...bucket.measures].join(" + ") || "no measure published";
|
|
183
|
+
const from = bucket.drinks.size > 1 ? ` (for ${bucket.drinks.size} drinks)` : "";
|
|
184
|
+
return ` ${name.padEnd(24)} ${measures}${from}`;
|
|
185
|
+
}),
|
|
186
|
+
"",
|
|
187
|
+
shared.length
|
|
188
|
+
? ` ${shared.length} of these are needed by more than one drink, listed first.`
|
|
189
|
+
: " No ingredient is shared between these drinks.",
|
|
190
|
+
missing.length ? ` Could not resolve: ${missing.join(", ")}` : "",
|
|
191
|
+
" Measures are printed exactly as the database records them and are never added together, because they mix units such as oz and tsp.",
|
|
192
|
+
];
|
|
193
|
+
return lines.filter((line) => line !== "").join("\n");
|
|
194
|
+
}
|
|
195
|
+
export async function randomCocktail(_args) {
|
|
196
|
+
const d = await get(`${BASE}/random.php`);
|
|
197
|
+
const drink = Array.isArray(d?.drinks) ? d.drinks[0] : null;
|
|
198
|
+
if (!drink)
|
|
199
|
+
throw new CocktailsError("TheCocktailDB returned no random cocktail");
|
|
200
|
+
const ings = ingredients(drink);
|
|
201
|
+
return [
|
|
202
|
+
`# ${drink.strDrink ?? "Unknown"} (id ${drink.idDrink ?? "?"})`,
|
|
203
|
+
` ${cocktailSummary(drink)}`,
|
|
204
|
+
drink.strIBA ? ` IBA official cocktail: ${drink.strIBA}` : "",
|
|
205
|
+
drink.strTags ? ` Tags: ${drink.strTags}` : "",
|
|
206
|
+
"",
|
|
207
|
+
"Ingredients:",
|
|
208
|
+
...(ings.length ? ings.map((entry) => `- ${entry}`) : ["- none published"]),
|
|
209
|
+
"",
|
|
210
|
+
"Instructions:",
|
|
211
|
+
drink.strInstructions ?? "not published",
|
|
212
|
+
]
|
|
213
|
+
.filter((line) => line !== "")
|
|
214
|
+
.join("\n");
|
|
215
|
+
}
|
package/dist/license.js
ADDED
|
@@ -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 = "cocktails-mcp";
|
|
5
|
+
// Tools that need a key. Everything else is free.
|
|
6
|
+
const PREMIUM = new Set([
|
|
7
|
+
"filter_cocktails",
|
|
8
|
+
"shopping_list",
|
|
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
|
@@ -2,7 +2,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { byIngredient } from "./api.js";
|
|
4
4
|
import { cocktailDetails } from "./api.js";
|
|
5
|
-
import { searchCocktails } from "./api.js";
|
|
5
|
+
import { searchCocktails, filterCocktails, shoppingList, randomCocktail } from "./api.js";
|
|
6
|
+
import { premiumRequired } from "./license.js";
|
|
6
7
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
7
8
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
8
9
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -48,5 +49,54 @@ export function createServer() {
|
|
|
48
49
|
return textError(error(e));
|
|
49
50
|
}
|
|
50
51
|
});
|
|
52
|
+
server.registerTool("filter_cocktails", {
|
|
53
|
+
title: "Filter cocktails",
|
|
54
|
+
description: "Browse TheCocktailDB by category, glass or strength, or list the values each facet offers. The existing tools only search by name or ingredient.",
|
|
55
|
+
inputSchema: z.object({ facet: z.string().describe("One of category, glass or strength. Omit to see all three.").optional(), value: z.string().describe("Facet value to list, like Shot or Cocktail glass. Omit to see the values.").optional(), limit: z.number().describe("How many cocktails to list, 1-100. Defaults to 25.").optional() }),
|
|
56
|
+
annotations: READ_ONLY,
|
|
57
|
+
}, async (args) => {
|
|
58
|
+
// ---- paywall: filter_cocktails ----
|
|
59
|
+
const paywallMessage = await premiumRequired("filter_cocktails");
|
|
60
|
+
if (paywallMessage)
|
|
61
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
62
|
+
// ---- paywall: end ----
|
|
63
|
+
try {
|
|
64
|
+
return text(await filterCocktails(args));
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return textError(error(e));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
server.registerTool("shopping_list", {
|
|
71
|
+
title: "Shopping list",
|
|
72
|
+
description: "Merge the ingredients of several cocktails into one shopping list, flagging what more than one drink needs.",
|
|
73
|
+
inputSchema: z.object({ ids: z.array(z.string()).describe("Cocktail ids, up to 12, like [\"11007\", \"11117\"].") }),
|
|
74
|
+
annotations: READ_ONLY,
|
|
75
|
+
}, async (args) => {
|
|
76
|
+
// ---- paywall: shopping_list ----
|
|
77
|
+
const paywallMessage = await premiumRequired("shopping_list");
|
|
78
|
+
if (paywallMessage)
|
|
79
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
80
|
+
// ---- paywall: end ----
|
|
81
|
+
try {
|
|
82
|
+
return text(await shoppingList(args));
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return textError(error(e));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
server.registerTool("random_cocktail", {
|
|
89
|
+
title: "Random cocktail",
|
|
90
|
+
description: "One random cocktail with its full ingredient list and instructions.",
|
|
91
|
+
inputSchema: z.object({}),
|
|
92
|
+
annotations: READ_ONLY,
|
|
93
|
+
}, async (args) => {
|
|
94
|
+
try {
|
|
95
|
+
return text(await randomCocktail(args));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
return textError(error(e));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
51
101
|
return server;
|
|
52
102
|
}
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/mrfentmen/cocktails-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.1",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "cocktails-mcp",
|
|
14
|
-
"version": "1.0.
|
|
14
|
+
"version": "1.0.1",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
}
|