cocktails-mcp 1.0.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 ADDED
@@ -0,0 +1,22 @@
1
+ # Cocktails MCP
2
+
3
+ Search cocktail recipes by name or ingredient from TheCocktailDB. No key required.
4
+
5
+ This file is self contained. It reads public data only and never writes to the machine. All output is bounded and honest about what could not be fetched.
6
+
7
+ ## Tools
8
+
9
+
10
+ * `search_cocktails` Search cocktails by name.
11
+ * `by_ingredient` Cocktails by ingredient.
12
+ * `cocktail_details` Full recipe details.
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ npm install
18
+ npm run build
19
+ node dist/index.js
20
+ ```
21
+
22
+ Recipe data comes from the public TheCocktailDB API.
package/dist/api.js ADDED
@@ -0,0 +1,53 @@
1
+ const BASE = "https://www.thecocktaildb.com/api/json/v1/1";
2
+ const UA = "mrfentmen-cocktails-mcp/1.0 (https://github.com/mrfentmen)";
3
+ export class CocktailsError extends Error {
4
+ }
5
+ async function get(url) {
6
+ const res = await fetch(url, { headers: { "User-Agent": UA, Accept: "application/json" }, signal: AbortSignal.timeout(25000) });
7
+ if (res.status === 429)
8
+ throw new CocktailsError("TheCocktailDB rate limit hit, wait and retry");
9
+ if (!res.ok)
10
+ throw new CocktailsError(`TheCocktailDB error ${res.status}`);
11
+ return (await res.json());
12
+ }
13
+ function ingredients(c) {
14
+ const out = [];
15
+ for (let i = 1; i <= 15; i++) {
16
+ const ing = c?.[`strIngredient${i}`];
17
+ const meas = c?.[`strMeasure${i}`];
18
+ if (ing && ing.trim())
19
+ out.push(`${meas ? meas.trim() + " " : ""}${ing.trim()}`);
20
+ }
21
+ return out;
22
+ }
23
+ export async function searchCocktails(args) {
24
+ const q = (args.query ?? "").trim();
25
+ if (!q)
26
+ throw new CocktailsError("Provide a cocktail name");
27
+ const d = await get(`${BASE}/search.php?s=${encodeURIComponent(q)}`);
28
+ const drinks = d?.drinks ?? [];
29
+ if (!drinks.length)
30
+ return "No cocktails found";
31
+ return drinks.map((c) => `${c.strDrink} (id ${c.idDrink})\n ${c.strCategory ?? ""} | ${c.strAlcoholic ?? ""} | ${c.strGlass ?? ""}`).join("\n\n");
32
+ }
33
+ export async function byIngredient(args) {
34
+ const ing = (args.ingredient ?? "").trim();
35
+ if (!ing)
36
+ throw new CocktailsError("Provide an ingredient");
37
+ const d = await get(`${BASE}/filter.php?i=${encodeURIComponent(ing)}`);
38
+ const drinks = d?.drinks ?? [];
39
+ if (!drinks.length)
40
+ return `No cocktails with ${ing}`;
41
+ return drinks.slice(0, 15).map((c, i) => `${i + 1}. ${c.strDrink} (id ${c.idDrink})`).join("\n");
42
+ }
43
+ export async function cocktailDetails(args) {
44
+ const id = (args.cocktailId ?? "").trim();
45
+ if (!id)
46
+ throw new CocktailsError("Provide a cocktail ID");
47
+ const d = await get(`${BASE}/lookup.php?i=${encodeURIComponent(id)}`);
48
+ const c = d?.drinks?.[0];
49
+ if (!c)
50
+ return "No cocktail found";
51
+ const ings = ingredients(c);
52
+ return `# ${c.strDrink}\n${c.strAlcoholic ?? ""} | ${c.strGlass ?? ""}\n\nIngredients:\n${ings.map((i) => `- ${i}`).join("\n")}\n\nInstructions:\n${c.strInstructions ?? ""}`;
53
+ }
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
+ import { createServer } from "./server.js";
3
+ const main = async () => { const server = createServer(); await server.connect(new StdioServerTransport()); };
4
+ main().catch((error) => { console.error("Fatal error:", error); process.exit(1); });
package/dist/server.js ADDED
@@ -0,0 +1,52 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import { byIngredient } from "./api.js";
4
+ import { cocktailDetails } from "./api.js";
5
+ import { searchCocktails } from "./api.js";
6
+ const text = (value) => ({ content: [{ type: "text", text: value }] });
7
+ const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
8
+ const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
9
+ const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
10
+ export function createServer() {
11
+ const server = new McpServer({ name: "cocktails-mcp", version: "1.0.0" });
12
+ server.registerTool("search_cocktails", {
13
+ title: "Search cocktails",
14
+ description: "Search cocktails by name.",
15
+ inputSchema: z.object({ query: z.string().describe("Cocktail name.") }),
16
+ annotations: READ_ONLY,
17
+ }, async (args) => {
18
+ try {
19
+ return text(await searchCocktails(args));
20
+ }
21
+ catch (e) {
22
+ return textError(error(e));
23
+ }
24
+ });
25
+ server.registerTool("by_ingredient", {
26
+ title: "By ingredient",
27
+ description: "Find cocktails by ingredient.",
28
+ inputSchema: z.object({ ingredient: z.string().describe("Ingredient name.") }),
29
+ annotations: READ_ONLY,
30
+ }, async (args) => {
31
+ try {
32
+ return text(await byIngredient(args));
33
+ }
34
+ catch (e) {
35
+ return textError(error(e));
36
+ }
37
+ });
38
+ server.registerTool("cocktail_details", {
39
+ title: "Cocktail details",
40
+ description: "Get a full cocktail recipe by ID.",
41
+ inputSchema: z.object({ cocktailId: z.string().describe("Cocktail ID.") }),
42
+ annotations: READ_ONLY,
43
+ }, async (args) => {
44
+ try {
45
+ return text(await cocktailDetails(args));
46
+ }
47
+ catch (e) {
48
+ return textError(error(e));
49
+ }
50
+ });
51
+ return server;
52
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "type": "module",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/mrfentmen/cocktails-mcp.git"
7
+ },
8
+ "bin": {
9
+ "cocktails-mcp": "./dist/index.js"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "files": [
13
+ "dist",
14
+ "server.json",
15
+ "README.md"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "start": "node dist/index.js",
20
+ "dev": "npm run build && node dist/index.js"
21
+ },
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.0.4",
25
+ "zod": "^3.23.8"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^22.0.0",
29
+ "typescript": "^5.6.0"
30
+ },
31
+ "name": "cocktails-mcp",
32
+ "description": "Search cocktail recipes by name or ingredient from TheCocktailDB. No key required.",
33
+ "mcpName": "io.github.mrfentmen/cocktails-mcp",
34
+ "keywords": [
35
+ "mcp",
36
+ "cocktails",
37
+ "drinks",
38
+ "recipes",
39
+ "bartending"
40
+ ],
41
+ "engines": {
42
+ "node": ">=20"
43
+ }
44
+ }
package/server.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.mrfentmen/cocktails-mcp",
4
+ "description": "Search cocktail recipes by name or ingredient from TheCocktailDB. No key required.",
5
+ "repository": {
6
+ "url": "https://github.com/mrfentmen/cocktails-mcp",
7
+ "source": "github"
8
+ },
9
+ "version": "1.0.0",
10
+ "packages": [
11
+ {
12
+ "registryType": "npm",
13
+ "identifier": "cocktails-mcp",
14
+ "version": "1.0.0",
15
+ "transport": {
16
+ "type": "stdio"
17
+ }
18
+ }
19
+ ]
20
+ }