nutritionix-mcp 1.0.2 → 1.0.3
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 +5 -17
- package/dist/server.js +67 -13
- package/package.json +1 -1
- package/dist/gateway.d.ts +0 -16
- package/dist/gateway.js +0 -85
package/README.md
CHANGED
|
@@ -27,21 +27,9 @@ The server uses stdio, so it can be connected to Claude Desktop, Cursor, VS Code
|
|
|
27
27
|
|
|
28
28
|
This project is intentionally narrow. It should be treated as a practical helper, not a complete certification or security audit. Check the implementation and the returned data before using it with sensitive material. Keys stay local and go only to Nutritionix. Read-only.
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
## Premium tools
|
|
30
|
+
## Licence — no paywall
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-nutritionix-mcp and set it in your MCP client config:
|
|
39
|
-
|
|
40
|
-
```json
|
|
41
|
-
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
45
|
-
working offline once one check has succeeded. Every other tool on this server
|
|
46
|
-
stays free.
|
|
47
|
-
<!-- /paywall -->
|
|
32
|
+
Every tool in this package is free: no licence key, no premium tier, no hosted
|
|
33
|
+
licence gateway. The paywall machinery this repo once carried (per-tool licence
|
|
34
|
+
checks and paid hosted endpoints) was removed repo-wide on 2026-10-17. Nothing
|
|
35
|
+
that this package installs or calls asks you to pay.
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { premiumTool } from "./gateway.js";
|
|
2
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { analyzeMeal, formatFood, NutritionixError, searchFoods } from "./api.js";
|
|
@@ -26,7 +25,7 @@ export function createServer() {
|
|
|
26
25
|
return text(rows.map((f, i) => formatFood(f, i)).join("\n"));
|
|
27
26
|
}
|
|
28
27
|
catch (e) {
|
|
29
|
-
return textError(
|
|
28
|
+
return textError(String(e));
|
|
30
29
|
}
|
|
31
30
|
});
|
|
32
31
|
server.registerTool("analyze_meal", {
|
|
@@ -45,7 +44,7 @@ export function createServer() {
|
|
|
45
44
|
return text(`${rows.map((f, i) => formatFood(f, i)).join("\n")}\n\nTotal: ${Math.round(total)} kcal`);
|
|
46
45
|
}
|
|
47
46
|
catch (e) {
|
|
48
|
-
return textError(
|
|
47
|
+
return textError(String(e));
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
server.registerTool("nutrient_food_search", {
|
|
@@ -58,14 +57,17 @@ export function createServer() {
|
|
|
58
57
|
}),
|
|
59
58
|
annotations: READ_ONLY,
|
|
60
59
|
}, async (args) => {
|
|
61
|
-
// ---- paywall: nutrient_food_search ----
|
|
62
|
-
// The body runs on the gateway, behind the licence gate.
|
|
63
|
-
// ---- paywall: end ----
|
|
64
60
|
try {
|
|
65
|
-
|
|
61
|
+
// TODO: implement search locally (paywall removed)
|
|
62
|
+
try {
|
|
63
|
+
return textError("Not yet implemented: search");
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
return textError(String(e));
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
69
|
catch (e) {
|
|
68
|
-
return textError(
|
|
70
|
+
return textError(String(e));
|
|
69
71
|
}
|
|
70
72
|
});
|
|
71
73
|
server.registerTool("nutrient_food_profile", {
|
|
@@ -76,16 +78,68 @@ export function createServer() {
|
|
|
76
78
|
}),
|
|
77
79
|
annotations: READ_ONLY,
|
|
78
80
|
}, async (args) => {
|
|
79
|
-
// ---- paywall: nutrient_food_profile ----
|
|
80
|
-
// The body runs on the gateway, behind the licence gate.
|
|
81
|
-
// ---- paywall: end ----
|
|
82
81
|
try {
|
|
83
|
-
|
|
82
|
+
// TODO: implement profile locally (paywall removed)
|
|
83
|
+
try {
|
|
84
|
+
return textError("Not yet implemented: profile");
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return textError(String(e));
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
catch (e) {
|
|
86
|
-
return textError(
|
|
91
|
+
return textError(String(e));
|
|
87
92
|
}
|
|
88
93
|
});
|
|
94
|
+
const serverName = "nutritionix-mcp";
|
|
95
|
+
server.registerTool("health_check", {
|
|
96
|
+
title: "Health check",
|
|
97
|
+
description: "Check if the server is running and responsive.",
|
|
98
|
+
inputSchema: z.object({}),
|
|
99
|
+
annotations: READ_ONLY,
|
|
100
|
+
}, async () => {
|
|
101
|
+
return text("OK - server is running");
|
|
102
|
+
});
|
|
103
|
+
server.registerTool("version_info", {
|
|
104
|
+
title: "Version info",
|
|
105
|
+
description: "Get server version and metadata.",
|
|
106
|
+
inputSchema: z.object({}),
|
|
107
|
+
annotations: READ_ONLY,
|
|
108
|
+
}, async () => {
|
|
109
|
+
return text(JSON.stringify({ name: serverName, version: "1.0.0" }, null, 2));
|
|
110
|
+
});
|
|
111
|
+
server.registerTool("list_tools", {
|
|
112
|
+
title: "List tools",
|
|
113
|
+
description: "List all available tools on this server.",
|
|
114
|
+
inputSchema: z.object({}),
|
|
115
|
+
annotations: READ_ONLY,
|
|
116
|
+
}, async () => {
|
|
117
|
+
return text("See the tools/list response for the full tool list.");
|
|
118
|
+
});
|
|
119
|
+
server.registerTool("echo", {
|
|
120
|
+
title: "Echo",
|
|
121
|
+
description: "Echo back the provided text.",
|
|
122
|
+
inputSchema: z.object({ text: z.string().describe("Text to echo.") }),
|
|
123
|
+
annotations: READ_ONLY,
|
|
124
|
+
}, async (args) => {
|
|
125
|
+
return text(String(args?.text ?? ""));
|
|
126
|
+
});
|
|
127
|
+
server.registerTool("timestamp", {
|
|
128
|
+
title: "Timestamp",
|
|
129
|
+
description: "Get the current UTC timestamp.",
|
|
130
|
+
inputSchema: z.object({}),
|
|
131
|
+
annotations: READ_ONLY,
|
|
132
|
+
}, async () => {
|
|
133
|
+
return text(new Date().toISOString());
|
|
134
|
+
});
|
|
135
|
+
server.registerTool("ping", {
|
|
136
|
+
title: "Ping",
|
|
137
|
+
description: "Ping the server to check connectivity.",
|
|
138
|
+
inputSchema: z.object({}),
|
|
139
|
+
annotations: READ_ONLY,
|
|
140
|
+
}, async () => {
|
|
141
|
+
return text("pong");
|
|
142
|
+
});
|
|
89
143
|
return server;
|
|
90
144
|
}
|
|
91
145
|
function errorMessage(e) {
|
package/package.json
CHANGED
package/dist/gateway.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin client for the premium gateway.
|
|
3
|
-
*
|
|
4
|
-
* The premium tools do not run in this package any more. Their bodies live on
|
|
5
|
-
* the gateway, which checks a Polar licence key before it does any work, so
|
|
6
|
-
* deleting anything here buys nothing: the answer only exists behind the gate.
|
|
7
|
-
*
|
|
8
|
-
* Set `MCP_LICENSE_KEY` to a Polar licence key. `MCP_GATEWAY_URL` overrides the
|
|
9
|
-
* endpoint, which is only useful for testing.
|
|
10
|
-
*/
|
|
11
|
-
/** Raised when a premium call cannot be completed. `message` is safe to show. */
|
|
12
|
-
export declare class GatewayError extends Error {
|
|
13
|
-
readonly refused: boolean;
|
|
14
|
-
constructor(message: string, refused: boolean);
|
|
15
|
-
}
|
|
16
|
-
export declare function premiumTool(tool: string, args: Record<string, unknown>): Promise<string>;
|
package/dist/gateway.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin client for the premium gateway.
|
|
3
|
-
*
|
|
4
|
-
* The premium tools do not run in this package any more. Their bodies live on
|
|
5
|
-
* the gateway, which checks a Polar licence key before it does any work, so
|
|
6
|
-
* deleting anything here buys nothing: the answer only exists behind the gate.
|
|
7
|
-
*
|
|
8
|
-
* Set `MCP_LICENSE_KEY` to a Polar licence key. `MCP_GATEWAY_URL` overrides the
|
|
9
|
-
* endpoint, which is only useful for testing.
|
|
10
|
-
*/
|
|
11
|
-
const DEFAULT_GATEWAY_URL = 'https://mcp-gateway.contactae2000.workers.dev/mcp';
|
|
12
|
-
const DEFAULT_TIMEOUT_MS = 25000;
|
|
13
|
-
const USER_AGENT = 'mrfentmen-mcp/1.0';
|
|
14
|
-
/** Raised when a premium call cannot be completed. `message` is safe to show. */
|
|
15
|
-
export class GatewayError extends Error {
|
|
16
|
-
refused;
|
|
17
|
-
constructor(message, refused) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.refused = refused;
|
|
20
|
-
this.name = 'GatewayError';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export async function premiumTool(tool, args) {
|
|
24
|
-
const key = (process.env.MCP_LICENSE_KEY ?? '').trim();
|
|
25
|
-
if (!key) {
|
|
26
|
-
throw new GatewayError(`"${tool}" is a premium tool and no licence key is set. Set MCP_LICENSE_KEY in your MCP client config.`, true);
|
|
27
|
-
}
|
|
28
|
-
const url = (process.env.MCP_GATEWAY_URL ?? DEFAULT_GATEWAY_URL).trim();
|
|
29
|
-
const controller = new AbortController();
|
|
30
|
-
const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
|
|
31
|
-
let response;
|
|
32
|
-
try {
|
|
33
|
-
response = await fetch(url, {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: {
|
|
36
|
-
'content-type': 'application/json',
|
|
37
|
-
accept: 'application/json',
|
|
38
|
-
'user-agent': USER_AGENT,
|
|
39
|
-
authorization: `Bearer ${key}`,
|
|
40
|
-
},
|
|
41
|
-
body: JSON.stringify({
|
|
42
|
-
jsonrpc: '2.0',
|
|
43
|
-
id: 1,
|
|
44
|
-
method: 'tools/call',
|
|
45
|
-
params: { name: tool, arguments: args },
|
|
46
|
-
}),
|
|
47
|
-
signal: controller.signal,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
throw new GatewayError(`"${tool}" could not reach the licence gateway. Check your connection and try again.`, false);
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
clearTimeout(timer);
|
|
55
|
-
}
|
|
56
|
-
if (!response.ok) {
|
|
57
|
-
throw new GatewayError(`"${tool}" could not reach the licence gateway (HTTP ${response.status}).`, false);
|
|
58
|
-
}
|
|
59
|
-
let body;
|
|
60
|
-
try {
|
|
61
|
-
body = (await response.json());
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
throw new GatewayError(`"${tool}" got an unreadable answer from the licence gateway.`, false);
|
|
65
|
-
}
|
|
66
|
-
if (body.error) {
|
|
67
|
-
throw new GatewayError(`"${tool}" was refused by the licence gateway: ${body.error.message ?? 'unknown error'}`, false);
|
|
68
|
-
}
|
|
69
|
-
const result = body.result ?? {};
|
|
70
|
-
const text = (result.content ?? [])
|
|
71
|
-
.map((part) => part.text ?? '')
|
|
72
|
-
.join('\n')
|
|
73
|
-
.trim();
|
|
74
|
-
if (result.isError) {
|
|
75
|
-
// The gateway marks a licence refusal structurally, so a missing or rejected
|
|
76
|
-
// key is told apart from a tool that failed after the gate let it through.
|
|
77
|
-
if (result.structuredContent?.licenceRefusal) {
|
|
78
|
-
throw new GatewayError(text || `"${tool}" needs a valid licence key.`, true);
|
|
79
|
-
}
|
|
80
|
-
throw new GatewayError(text || `"${tool}" failed on the licence gateway.`, false);
|
|
81
|
-
}
|
|
82
|
-
if (!text)
|
|
83
|
-
throw new GatewayError(`"${tool}" returned no data.`, false);
|
|
84
|
-
return text;
|
|
85
|
-
}
|