@daften/mealie-mcp 0.1.0-alpha.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/.env.example +36 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/args.d.ts +14 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +132 -0
- package/dist/args.js.map +1 -0
- package/dist/auth/crypto.d.ts +9 -0
- package/dist/auth/crypto.d.ts.map +1 -0
- package/dist/auth/crypto.js +34 -0
- package/dist/auth/crypto.js.map +1 -0
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +77 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/login-method.d.ts +28 -0
- package/dist/auth/login-method.d.ts.map +1 -0
- package/dist/auth/login-method.js +2 -0
- package/dist/auth/login-method.js.map +1 -0
- package/dist/auth/mealie-session.d.ts +28 -0
- package/dist/auth/mealie-session.d.ts.map +1 -0
- package/dist/auth/mealie-session.js +81 -0
- package/dist/auth/mealie-session.js.map +1 -0
- package/dist/auth/password-login.d.ts +21 -0
- package/dist/auth/password-login.d.ts.map +1 -0
- package/dist/auth/password-login.js +168 -0
- package/dist/auth/password-login.js.map +1 -0
- package/dist/auth/provider.d.ts +41 -0
- package/dist/auth/provider.d.ts.map +1 -0
- package/dist/auth/provider.js +201 -0
- package/dist/auth/provider.js.map +1 -0
- package/dist/auth/redirects.d.ts +2 -0
- package/dist/auth/redirects.d.ts.map +1 -0
- package/dist/auth/redirects.js +71 -0
- package/dist/auth/redirects.js.map +1 -0
- package/dist/auth/store.d.ts +61 -0
- package/dist/auth/store.d.ts.map +1 -0
- package/dist/auth/store.js +201 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +180 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +82 -0
- package/dist/config.js.map +1 -0
- package/dist/http.d.ts +54 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +227 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +10 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/_annotations.d.ts +17 -0
- package/dist/tools/_annotations.d.ts.map +1 -0
- package/dist/tools/_annotations.js +9 -0
- package/dist/tools/_annotations.js.map +1 -0
- package/dist/tools/_helpers.d.ts +50 -0
- package/dist/tools/_helpers.d.ts.map +1 -0
- package/dist/tools/_helpers.js +67 -0
- package/dist/tools/_helpers.js.map +1 -0
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +53 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/ingredients.d.ts +4 -0
- package/dist/tools/ingredients.d.ts.map +1 -0
- package/dist/tools/ingredients.js +68 -0
- package/dist/tools/ingredients.js.map +1 -0
- package/dist/tools/mealplans.d.ts +4 -0
- package/dist/tools/mealplans.d.ts.map +1 -0
- package/dist/tools/mealplans.js +71 -0
- package/dist/tools/mealplans.js.map +1 -0
- package/dist/tools/organizers.d.ts +4 -0
- package/dist/tools/organizers.d.ts.map +1 -0
- package/dist/tools/organizers.js +49 -0
- package/dist/tools/organizers.js.map +1 -0
- package/dist/tools/recipe-assets.d.ts +4 -0
- package/dist/tools/recipe-assets.d.ts.map +1 -0
- package/dist/tools/recipe-assets.js +55 -0
- package/dist/tools/recipe-assets.js.map +1 -0
- package/dist/tools/recipes.d.ts +89 -0
- package/dist/tools/recipes.d.ts.map +1 -0
- package/dist/tools/recipes.js +206 -0
- package/dist/tools/recipes.js.map +1 -0
- package/dist/tools/shopping.d.ts +4 -0
- package/dist/tools/shopping.d.ts.map +1 -0
- package/dist/tools/shopping.js +94 -0
- package/dist/tools/shopping.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -0
package/dist/http.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import * as http from 'node:http';
|
|
3
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
4
|
+
export const requestContext = new AsyncLocalStorage();
|
|
5
|
+
// MCP request bodies carry JSON-RPC messages. The largest legitimate one is an image or asset upload, whose
|
|
6
|
+
// base64 payload is ~4/3 the file size, so 16 MiB admits files up to roughly 12 MB.
|
|
7
|
+
export const MCP_MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
8
|
+
export class PayloadTooLargeError extends Error {
|
|
9
|
+
limit;
|
|
10
|
+
constructor(limit) {
|
|
11
|
+
super(`Request body exceeds the ${limit}-byte limit.`);
|
|
12
|
+
this.limit = limit;
|
|
13
|
+
this.name = 'PayloadTooLargeError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads a request body into memory, refusing anything over `maxBytes`. Every unauthenticated route
|
|
18
|
+
* that reads a body goes through here: an unbounded read let one oversized POST either exhaust
|
|
19
|
+
* memory or, past V8's maximum string length, throw inside the stream listener and kill the process.
|
|
20
|
+
* Chunks are kept as Buffers and decoded once at the end, so a multi-byte UTF-8 character split
|
|
21
|
+
* across two chunks is not mangled.
|
|
22
|
+
*/
|
|
23
|
+
export function readBody(req, maxBytes) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const declared = Number(req.headers?.['content-length']);
|
|
26
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
27
|
+
reject(new PayloadTooLargeError(maxBytes));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const chunks = [];
|
|
31
|
+
let size = 0;
|
|
32
|
+
let settled = false;
|
|
33
|
+
req.on('data', (chunk) => {
|
|
34
|
+
if (settled)
|
|
35
|
+
return; // over the limit: drop the rest; the 413 closes the connection
|
|
36
|
+
size += chunk.length;
|
|
37
|
+
if (size > maxBytes) {
|
|
38
|
+
settled = true;
|
|
39
|
+
chunks.length = 0;
|
|
40
|
+
reject(new PayloadTooLargeError(maxBytes));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
chunks.push(chunk);
|
|
44
|
+
});
|
|
45
|
+
req.on('end', () => {
|
|
46
|
+
if (settled)
|
|
47
|
+
return;
|
|
48
|
+
settled = true;
|
|
49
|
+
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
50
|
+
});
|
|
51
|
+
req.on('error', (err) => {
|
|
52
|
+
if (settled)
|
|
53
|
+
return;
|
|
54
|
+
settled = true;
|
|
55
|
+
reject(err);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** 413 response for {@link PayloadTooLargeError}. `Connection: close` stops Node reading the rest. */
|
|
60
|
+
function rejectTooLarge(res, err, jsonRpc) {
|
|
61
|
+
const body = jsonRpc
|
|
62
|
+
? { jsonrpc: '2.0', error: { code: -32600, message: err.message }, id: null }
|
|
63
|
+
: { error: 'invalid_request', error_description: err.message };
|
|
64
|
+
res.writeHead(413, { 'Content-Type': 'application/json', Connection: 'close' });
|
|
65
|
+
res.end(JSON.stringify(body));
|
|
66
|
+
}
|
|
67
|
+
// Paths the login stack serves. Outside login mode they 404 instead of falling through to the bearer check.
|
|
68
|
+
export const AUTH_PATHS = [
|
|
69
|
+
'/.well-known/oauth-authorization-server',
|
|
70
|
+
'/.well-known/oauth-protected-resource',
|
|
71
|
+
'/authorize',
|
|
72
|
+
'/token',
|
|
73
|
+
'/register',
|
|
74
|
+
'/revoke',
|
|
75
|
+
'/oauth/login',
|
|
76
|
+
];
|
|
77
|
+
function unauthorized(res, challenge, description) {
|
|
78
|
+
res.writeHead(401, { 'WWW-Authenticate': challenge, 'Content-Type': 'application/json' });
|
|
79
|
+
res.end(JSON.stringify({ error: 'unauthorized', error_description: description }));
|
|
80
|
+
}
|
|
81
|
+
export function createHttpHandler(mode, mcpHandler) {
|
|
82
|
+
return async (req, res) => {
|
|
83
|
+
const pathname = new URL(req.url ?? '/', 'http://localhost').pathname;
|
|
84
|
+
// Liveness probe: no auth and mode-agnostic, so container health doesn't depend on the auth surface.
|
|
85
|
+
if ((req.method === 'GET' || req.method === 'HEAD') && pathname === '/health') {
|
|
86
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
87
|
+
res.end(req.method === 'HEAD' ? undefined : JSON.stringify({ status: 'ok' }));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (mode.kind === 'login' && mode.auth.isAuthPath(pathname)) {
|
|
91
|
+
mode.auth.handle(req, res);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (mode.kind !== 'login' && AUTH_PATHS.includes(pathname)) {
|
|
95
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
96
|
+
res.end(JSON.stringify({ error: 'not_found', error_description: 'Login is not enabled on this server.' }));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (mode.kind === 'server-key') {
|
|
100
|
+
// Deliberately ignores any Authorization header: this mode has exactly one identity.
|
|
101
|
+
await requestContext.run({ token: mode.token }, () => mcpHandler(req, res));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const header = req.headers.authorization;
|
|
105
|
+
const bearer = header?.startsWith('Bearer ') ? header.slice(7) : null;
|
|
106
|
+
if (mode.kind === 'login') {
|
|
107
|
+
const metadata = `resource_metadata="${mode.auth.baseUrl}/.well-known/oauth-protected-resource"`;
|
|
108
|
+
if (!bearer) {
|
|
109
|
+
unauthorized(res, `Bearer ${metadata}`, 'Log in to use this server.');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const token = mode.auth.resolveBearer(bearer);
|
|
113
|
+
if (!token) {
|
|
114
|
+
// Also the answer for a raw Mealie API key: login mode never forwards one.
|
|
115
|
+
unauthorized(res, `Bearer error="invalid_token", ${metadata}`, 'The access token is invalid or expired.');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await requestContext.run({ token }, () => mcpHandler(req, res));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!bearer) {
|
|
122
|
+
unauthorized(res, 'Bearer', 'Send your Mealie API token as a Bearer token.');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
await requestContext.run({ token: bearer }, () => mcpHandler(req, res));
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serves one MCP request. Stateless HTTP transport requires a fresh transport + server per request
|
|
130
|
+
* (the WebStandardStreamableHTTPServerTransport throws if reused across requests).
|
|
131
|
+
*
|
|
132
|
+
* The body is read here, under {@link MCP_MAX_BODY_BYTES}, and handed to the SDK pre-parsed, because
|
|
133
|
+
* the SDK buffers whatever arrives with no limit of its own. That matters even behind the Bearer
|
|
134
|
+
* guard: the guard only checks that *a* Bearer token is present (Mealie validates it later), so
|
|
135
|
+
* without this cap any caller could make the server hold an arbitrarily large body in memory.
|
|
136
|
+
*/
|
|
137
|
+
export function createMcpRequestHandler(createMcpServer) {
|
|
138
|
+
return async (req, res) => {
|
|
139
|
+
let parsedBody;
|
|
140
|
+
if (req.method === 'POST') {
|
|
141
|
+
let raw;
|
|
142
|
+
try {
|
|
143
|
+
raw = await readBody(req, MCP_MAX_BODY_BYTES);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
if (!(err instanceof PayloadTooLargeError))
|
|
147
|
+
throw err;
|
|
148
|
+
rejectTooLarge(res, err, true);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
parsedBody = JSON.parse(raw);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Same response the SDK itself sends for an unparseable body.
|
|
156
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
157
|
+
res.end(JSON.stringify({ jsonrpc: '2.0', error: { code: -32700, message: 'Parse error: Invalid JSON' }, id: null }));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
162
|
+
const server = createMcpServer();
|
|
163
|
+
await server.connect(transport);
|
|
164
|
+
await transport.handleRequest(req, res, parsedBody);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export function classifyHost(host) {
|
|
168
|
+
return ['127.0.0.1', '::1', 'localhost'].includes(host) ? 'loopback' : 'non-loopback';
|
|
169
|
+
}
|
|
170
|
+
export async function tryListen(httpServer, host, port) {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
httpServer.once('error', reject);
|
|
173
|
+
httpServer.listen(port, host, () => {
|
|
174
|
+
httpServer.removeListener('error', reject);
|
|
175
|
+
resolve();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export async function startHttpServer(createMcpServer, host, requestedPort, portWasExplicit, mode, tryListenFn = tryListen) {
|
|
180
|
+
const handler = createHttpHandler(mode, createMcpRequestHandler(createMcpServer));
|
|
181
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
182
|
+
try {
|
|
183
|
+
await handler(req, res);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
process.stderr.write(`HTTP request handler error: ${err}\n`);
|
|
187
|
+
if (!res.headersSent) {
|
|
188
|
+
res.writeHead(500);
|
|
189
|
+
res.end('Internal server error');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
let port = requestedPort;
|
|
194
|
+
let moved = false;
|
|
195
|
+
while (true) {
|
|
196
|
+
try {
|
|
197
|
+
await tryListenFn(httpServer, host, port);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
const nodeErr = err;
|
|
202
|
+
if (nodeErr.code !== 'EADDRINUSE') {
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
if (portWasExplicit) {
|
|
206
|
+
process.stderr.write(`Error: Port ${port} on ${host} is already in use. Choose a different port with --port.\n`);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
const attempted = port - requestedPort;
|
|
210
|
+
if (attempted >= 10) {
|
|
211
|
+
process.stderr.write(`Error: Ports ${requestedPort}–${requestedPort + 10} on ${host} are all in use. Specify an available port with --port.\n`);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
port++;
|
|
215
|
+
moved = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
httpServer.on('error', (err) => {
|
|
219
|
+
process.stderr.write(`HTTP server error: ${err}\n`);
|
|
220
|
+
});
|
|
221
|
+
process.stdout.write(`MCP server for Mealie listening on http://${host}:${port}\n`);
|
|
222
|
+
if (moved) {
|
|
223
|
+
process.stdout.write(`(port ${requestedPort} was in use — moved up automatically)\n`);
|
|
224
|
+
}
|
|
225
|
+
return httpServer;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAMnG,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AAEtE,4GAA4G;AAC5G,oFAAoF;AACpF,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AA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,CAAC;IAED,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;IACpF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,aAAa,yCAAyC,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { parseArgs } from './args.js';
|
|
4
|
+
import { MealieClient } from './client.js';
|
|
5
|
+
import { ConfigError, parseFlag, resolveHttpMode, startupWarnings } from './config.js';
|
|
6
|
+
import { requestContext, startHttpServer } from './http.js';
|
|
7
|
+
import { createServer } from './server.js';
|
|
8
|
+
function fail(message) {
|
|
9
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = parseArgs(process.argv.slice(2));
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
fail(err.message);
|
|
18
|
+
}
|
|
19
|
+
const { transport, host, port, portWasExplicit, filterOptions } = parsed;
|
|
20
|
+
const url = process.env.MEALIE_URL;
|
|
21
|
+
if (!url)
|
|
22
|
+
fail('MEALIE_URL environment variable is required. See .env.example for configuration instructions.');
|
|
23
|
+
async function runHttp(mealieUrl) {
|
|
24
|
+
let close = async () => { };
|
|
25
|
+
let keepPort = portWasExplicit;
|
|
26
|
+
let mode;
|
|
27
|
+
try {
|
|
28
|
+
const resolved = resolveHttpMode(process.env, host, port);
|
|
29
|
+
for (const warning of startupWarnings(resolved, host))
|
|
30
|
+
process.stderr.write(`${warning}\n`);
|
|
31
|
+
if (resolved.kind === 'login') {
|
|
32
|
+
// Loaded only here: non-login modes never touch SQLite or Express.
|
|
33
|
+
const { createLoginAuth, passwordLogin } = await import('./auth/index.js');
|
|
34
|
+
const auth = await createLoginAuth(resolved.config, mealieUrl, [passwordLogin()]);
|
|
35
|
+
close = auth.close;
|
|
36
|
+
mode = { kind: 'login', auth };
|
|
37
|
+
keepPort = true; // the OAuth issuer URL contains the port, so it must not drift
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
mode = resolved;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err instanceof ConfigError)
|
|
45
|
+
fail(err.message);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
const client = new MealieClient(mealieUrl, () => {
|
|
49
|
+
const store = requestContext.getStore();
|
|
50
|
+
if (!store)
|
|
51
|
+
throw new Error('No request context — the token was not set before this call');
|
|
52
|
+
return store.token;
|
|
53
|
+
});
|
|
54
|
+
const httpServer = await startHttpServer(() => createServer(client, filterOptions), host, port, keepPort, mode);
|
|
55
|
+
// PID 1 in a container ignores SIGTERM without a handler, which would make every `docker stop` wait out its timeout.
|
|
56
|
+
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
57
|
+
process.once(signal, () => {
|
|
58
|
+
httpServer.close();
|
|
59
|
+
httpServer.closeIdleConnections();
|
|
60
|
+
void close().finally(() => process.exit(0));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (transport === 'http') {
|
|
65
|
+
await runHttp(url);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const token = process.env.MEALIE_API_TOKEN;
|
|
69
|
+
if (!token)
|
|
70
|
+
fail('MEALIE_API_TOKEN environment variable is required for stdio transport.');
|
|
71
|
+
try {
|
|
72
|
+
if (parseFlag('MEALIE_MCP_PASSWORD_LOGIN', process.env.MEALIE_MCP_PASSWORD_LOGIN)) {
|
|
73
|
+
process.stderr.write('Note: MEALIE_MCP_PASSWORD_LOGIN only applies to --transport http; ignoring it over stdio.\n');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
fail(err.message);
|
|
78
|
+
}
|
|
79
|
+
const server = createServer(new MealieClient(url, token), filterOptions);
|
|
80
|
+
await server.connect(new StdioServerTransport());
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAmB,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAiB,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,SAAS,IAAI,CAAC,OAAe;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,OAAO,IAAI,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,MAAkB,CAAC;AACvB,IAAI,CAAC;IACH,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;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AO,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,CAAC;YAClF,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,6FAA6F,CAC9F,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC,CAAC;IACzE,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { MealieClient } from './client.js';
|
|
3
|
+
import { type ToolFilterOptions } from './tools/index.js';
|
|
4
|
+
export declare function createServer(client: MealieClient, filterOptions?: ToolFilterOptions): McpServer;
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI5E,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,GAAE,iBAAsB,GAAG,SAAS,CAInG"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { registerAllTools } from './tools/index.js';
|
|
4
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
|
+
export function createServer(client, filterOptions = {}) {
|
|
6
|
+
const server = new McpServer({ name: 'mealie-mcp', version: pkg.version });
|
|
7
|
+
registerAllTools(server, client, filterOptions);
|
|
8
|
+
return server;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,kBAAkB,CAAC;AAE5E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAwB,CAAC;AAEjH,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,aAAa,GAAsB,EAAE;IACtF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3E,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const READ_ANNOTATIONS: {
|
|
2
|
+
readonly readOnlyHint: true;
|
|
3
|
+
readonly openWorldHint: true;
|
|
4
|
+
readonly idempotentHint: true;
|
|
5
|
+
};
|
|
6
|
+
export declare const WRITE_ANNOTATIONS: {
|
|
7
|
+
readonly openWorldHint: true;
|
|
8
|
+
};
|
|
9
|
+
export declare const UPDATE_ANNOTATIONS: {
|
|
10
|
+
readonly openWorldHint: true;
|
|
11
|
+
readonly idempotentHint: true;
|
|
12
|
+
};
|
|
13
|
+
export declare const DELETE_ANNOTATIONS: {
|
|
14
|
+
readonly destructiveHint: true;
|
|
15
|
+
readonly openWorldHint: true;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=_annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_annotations.d.ts","sourceRoot":"","sources":["../../src/tools/_annotations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;aAC3B,YAAY;aACZ,aAAa;aACb,cAAc;CACN,CAAC;AAEX,eAAO,MAAM,iBAAiB;aAAK,aAAa;CAAiB,CAAC;AAClE,eAAO,MAAM,kBAAkB;aAAK,aAAa;aAAQ,cAAc;CAAiB,CAAC;AACzF,eAAO,MAAM,kBAAkB;aAAK,eAAe;aAAQ,aAAa;CAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const READ_ANNOTATIONS = {
|
|
2
|
+
readOnlyHint: true,
|
|
3
|
+
openWorldHint: true,
|
|
4
|
+
idempotentHint: true,
|
|
5
|
+
};
|
|
6
|
+
export const WRITE_ANNOTATIONS = { openWorldHint: true };
|
|
7
|
+
export const UPDATE_ANNOTATIONS = { openWorldHint: true, idempotentHint: true };
|
|
8
|
+
export const DELETE_ANNOTATIONS = { destructiveHint: true, openWorldHint: true };
|
|
9
|
+
//# sourceMappingURL=_annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_annotations.js","sourceRoot":"","sources":["../../src/tools/_annotations.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;IACnB,cAAc,EAAE,IAAI;CACZ,CAAC;AAEX,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,aAAa,EAAE,IAAI,EAAW,CAAC;AAClE,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAW,CAAC;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAW,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type MealieClient } from '../client.js';
|
|
4
|
+
import type { QueryParams } from '../types.js';
|
|
5
|
+
export type ToolShape = Record<string, z.ZodType>;
|
|
6
|
+
export type ToolArgs<Shape extends ToolShape> = z.infer<z.ZodObject<Shape>>;
|
|
7
|
+
type ToolConfig<Shape extends ToolShape> = {
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
inputSchema?: Shape;
|
|
11
|
+
annotations?: {
|
|
12
|
+
readOnlyHint?: boolean;
|
|
13
|
+
destructiveHint?: boolean;
|
|
14
|
+
idempotentHint?: boolean;
|
|
15
|
+
openWorldHint?: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function defineTool<Shape extends ToolShape>(server: McpServer, name: string, config: ToolConfig<Shape>, fetch: (args: ToolArgs<Shape>) => Promise<unknown>): void;
|
|
19
|
+
export declare const dateSchema: z.ZodString;
|
|
20
|
+
/** Rejects anything that could change which resource a path addresses; MealieClient refuses those paths too. */
|
|
21
|
+
export declare const slugSchema: z.ZodString;
|
|
22
|
+
export declare const idSchema: z.ZodUUID;
|
|
23
|
+
export declare const paginationShape: {
|
|
24
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
per_page: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
};
|
|
27
|
+
export declare function paginationQuery(params: {
|
|
28
|
+
page?: number;
|
|
29
|
+
per_page?: number;
|
|
30
|
+
}): QueryParams;
|
|
31
|
+
export interface Paginated<T = Record<string, unknown>> {
|
|
32
|
+
page: number;
|
|
33
|
+
per_page: number;
|
|
34
|
+
total: number;
|
|
35
|
+
total_pages: number;
|
|
36
|
+
items: T[];
|
|
37
|
+
}
|
|
38
|
+
/** Mealie's paginated envelope includes next/previous URLs nobody needs; keep the counters and items. */
|
|
39
|
+
export declare function shapePage<T = Record<string, unknown>, R = T>(response: Paginated<T>, map?: (item: T) => R): Paginated<R>;
|
|
40
|
+
/** Drops undefined fields so a partial update never overwrites a value the caller didn't mention. */
|
|
41
|
+
export declare function defined(fields: Record<string, unknown>): Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Many Mealie PUT routes require the whole object, including read-only ids. Fetching and overlaying
|
|
44
|
+
* the changes lets a tool expose a partial update without the model having to echo the full record.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mergePut(client: MealieClient, path: string, changes: Record<string, unknown>): Promise<unknown>;
|
|
47
|
+
/** Decodes base64 strictly: Buffer.from would silently skip invalid characters and upload garbage. */
|
|
48
|
+
export declare function decodeBase64(value: string, field: string): Uint8Array<ArrayBuffer>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=_helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_helpers.d.ts","sourceRoot":"","sources":["../../src/tools/_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAClD,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,SAAS,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAE5E,KAAK,UAAU,CAAC,KAAK,S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G,CAAC,EAC1D,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,EACtB,GAAG,GAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAkC,GACnD,SAAS,CAAC,CAAC,CAAC,CAQd;AAED,qGAAqG;AACrG,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEhF;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAGrH;AAED,sGAAsG;AACtG,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAMlF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { formatError } from '../client.js';
|
|
3
|
+
export function defineTool(server, name, config, fetch) {
|
|
4
|
+
server.registerTool(name, config, async (args) => {
|
|
5
|
+
try {
|
|
6
|
+
const result = await fetch(args);
|
|
7
|
+
return {
|
|
8
|
+
content: [
|
|
9
|
+
{
|
|
10
|
+
type: 'text',
|
|
11
|
+
// Compact: indentation adds roughly a third more tokens to every result for no gain to the model.
|
|
12
|
+
text: typeof result === 'string' ? result : JSON.stringify(result ?? { ok: true }),
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
return { content: [{ type: 'text', text: formatError(err) }], isError: true };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export const dateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Date must be YYYY-MM-DD');
|
|
23
|
+
/** Rejects anything that could change which resource a path addresses; MealieClient refuses those paths too. */
|
|
24
|
+
export const slugSchema = z
|
|
25
|
+
.string()
|
|
26
|
+
.regex(/^[^/\\?#%\s]+$/, 'Must be a recipe slug')
|
|
27
|
+
.refine((s) => s !== '.' && s !== '..', 'Must be a recipe slug')
|
|
28
|
+
.describe('Recipe slug, from search_recipes or get_recipe');
|
|
29
|
+
export const idSchema = z.uuid();
|
|
30
|
+
export const paginationShape = {
|
|
31
|
+
page: z.number().int().min(1).optional().describe('Page number, starting at 1'),
|
|
32
|
+
per_page: z.number().int().min(1).max(200).optional().describe('Items per page, 50 by default'),
|
|
33
|
+
};
|
|
34
|
+
export function paginationQuery(params) {
|
|
35
|
+
return { page: params.page ?? 1, perPage: params.per_page ?? 50 };
|
|
36
|
+
}
|
|
37
|
+
/** Mealie's paginated envelope includes next/previous URLs nobody needs; keep the counters and items. */
|
|
38
|
+
export function shapePage(response, map = (item) => item) {
|
|
39
|
+
return {
|
|
40
|
+
page: response.page,
|
|
41
|
+
per_page: response.per_page,
|
|
42
|
+
total: response.total,
|
|
43
|
+
total_pages: response.total_pages,
|
|
44
|
+
items: response.items.map(map),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Drops undefined fields so a partial update never overwrites a value the caller didn't mention. */
|
|
48
|
+
export function defined(fields) {
|
|
49
|
+
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Many Mealie PUT routes require the whole object, including read-only ids. Fetching and overlaying
|
|
53
|
+
* the changes lets a tool expose a partial update without the model having to echo the full record.
|
|
54
|
+
*/
|
|
55
|
+
export async function mergePut(client, path, changes) {
|
|
56
|
+
const current = await client.get(path);
|
|
57
|
+
return client.put(path, { ...current, ...defined(changes) });
|
|
58
|
+
}
|
|
59
|
+
/** Decodes base64 strictly: Buffer.from would silently skip invalid characters and upload garbage. */
|
|
60
|
+
export function decodeBase64(value, field) {
|
|
61
|
+
const compact = value.replace(/\s+/g, '');
|
|
62
|
+
if (compact === '' || compact.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(compact)) {
|
|
63
|
+
throw new Error(`${field} is not valid base64.`);
|
|
64
|
+
}
|
|
65
|
+
return new Uint8Array(Buffer.from(compact, 'base64'));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=_helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_helpers.js","sourceRoot":"","sources":["../../src/tools/_helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAqB,MAAM,cAAc,CAAC;AA0B9D,MAAM,UAAU,UAAU,CACxB,MAAiB,EACjB,IAAY,EACZ,MAA6B,EAC7B,KAA0D;IAE1D,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAA6B,EAAE,EAAE;QACxE,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,kGAAkG;wBAClG,IAAI,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;qBACnF;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBA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AAG,CAAC,GAAG,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,OAAO,CAAC,MAA+B;IACrD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;AAC/F,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAoB,EAAE,IAAY,EAAE,OAAgC;IACjG,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAA0B,IAAI,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1F,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uBAAuB,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { MealieClient } from '../client.js';
|
|
3
|
+
export declare const TOOL_GROUPS: readonly ['recipes', 'recipe-assets', 'ingredients', 'organizers', 'shopping', 'mealplans'];
|
|
4
|
+
export type ToolGroup = (typeof TOOL_GROUPS)[number];
|
|
5
|
+
export declare const PRESETS: {
|
|
6
|
+
minimal: "recipes"[];
|
|
7
|
+
default: ("mealplans" | "recipes" | "shopping")[];
|
|
8
|
+
full: ("ingredients" | "mealplans" | "organizers" | "recipe-assets" | "recipes" | "shopping")[];
|
|
9
|
+
};
|
|
10
|
+
export type PresetName = keyof typeof PRESETS;
|
|
11
|
+
export interface ToolFilterOptions {
|
|
12
|
+
preset?: PresetName;
|
|
13
|
+
groups?: ToolGroup[];
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function makeReadOnlyProxy(server: McpServer): McpServer;
|
|
17
|
+
export declare function registerAllTools(server: McpServer, client: MealieClient, options?: ToolFilterOptions): void;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,eAAO,MAAM,WAAW,YAAI,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,CAAU,CAAC;AAEvH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,eAAO,MAAM,OAAO;;;;CAImB,CAAC;AAExC,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,OAAO,CAAC;AAE9C,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAc9D;AAWD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAW/G"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { registerIngredientTools } from './ingredients.js';
|
|
2
|
+
import { registerMealplanTools } from './mealplans.js';
|
|
3
|
+
import { registerOrganizerTools } from './organizers.js';
|
|
4
|
+
import { registerRecipeAssetTools } from './recipe-assets.js';
|
|
5
|
+
import { registerRecipeTools } from './recipes.js';
|
|
6
|
+
import { registerShoppingTools } from './shopping.js';
|
|
7
|
+
export const TOOL_GROUPS = ['recipes', 'recipe-assets', 'ingredients', 'organizers', 'shopping', 'mealplans'];
|
|
8
|
+
export const PRESETS = {
|
|
9
|
+
minimal: ['recipes'],
|
|
10
|
+
default: ['recipes', 'shopping', 'mealplans'],
|
|
11
|
+
full: [...TOOL_GROUPS],
|
|
12
|
+
};
|
|
13
|
+
function isReadOnlyTool(config) {
|
|
14
|
+
return config?.annotations?.readOnlyHint === true;
|
|
15
|
+
}
|
|
16
|
+
export function makeReadOnlyProxy(server) {
|
|
17
|
+
return new Proxy(server, {
|
|
18
|
+
get(target, prop) {
|
|
19
|
+
if (prop === 'registerTool') {
|
|
20
|
+
return (name, config, handler) => {
|
|
21
|
+
if (isReadOnlyTool(config)) {
|
|
22
|
+
target.registerTool(name, config, handler);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const v = target[prop];
|
|
27
|
+
return typeof v === 'function' ? v.bind(target) : v;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const REGISTRARS = {
|
|
32
|
+
recipes: registerRecipeTools,
|
|
33
|
+
'recipe-assets': registerRecipeAssetTools,
|
|
34
|
+
ingredients: registerIngredientTools,
|
|
35
|
+
organizers: registerOrganizerTools,
|
|
36
|
+
shopping: registerShoppingTools,
|
|
37
|
+
mealplans: registerMealplanTools,
|
|
38
|
+
};
|
|
39
|
+
export function registerAllTools(server, client, options = {}) {
|
|
40
|
+
const { preset, groups, readOnly = false } = options;
|
|
41
|
+
// Own keys only: a name inherited from Object.prototype (toString, __proto__) is not a preset.
|
|
42
|
+
if (preset !== undefined && !Object.hasOwn(PRESETS, preset))
|
|
43
|
+
throw new Error(`Unknown preset "${preset}"`);
|
|
44
|
+
if (groups !== undefined && groups.length === 0)
|
|
45
|
+
throw new Error('No tool groups selected');
|
|
46
|
+
const active = new Set(preset ? PRESETS[preset] : (groups ?? TOOL_GROUPS));
|
|
47
|
+
const target = readOnly ? makeReadOnlyProxy(server) : server;
|
|
48
|
+
for (const group of TOOL_GROUPS) {
|
|
49
|
+
if (active.has(group))
|
|
50
|
+
REGISTRARS[group](target, client);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,CAAU,CAAC;AAIvH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO,EAAE,CAAC,SAAS,CAAC;IACpB,OAAO,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC;IAC7C,IAAI,EA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