@meterbox/mcp 0.1.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/LICENSE +21 -0
- package/README.md +106 -0
- package/bin/meterbox-mcp.js +71 -0
- package/index.js +49 -0
- package/lib/bridge.js +124 -0
- package/lib/catalog.js +35 -0
- package/lib/http.js +49 -0
- package/lib/policy.js +111 -0
- package/lib/redact.js +36 -0
- package/lib/result.js +74 -0
- package/lib/server.js +57 -0
- package/lib/tiers.js +315 -0
- package/lib/tools.js +450 -0
- package/package.json +38 -0
package/lib/tools.js
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tools.js — the MCP tool surface: seven meta-tools instead of one tool per
|
|
3
|
+
* API operation.
|
|
4
|
+
*
|
|
5
|
+
* meterbox_whoami where this connection acts, and with what
|
|
6
|
+
* meterbox_search_operations find operations by keyword / toolset
|
|
7
|
+
* meterbox_describe_operation one operation's inputs
|
|
8
|
+
* meterbox_read run a read operation
|
|
9
|
+
* meterbox_create run a purely additive operation
|
|
10
|
+
* meterbox_update run an operation that changes records
|
|
11
|
+
* meterbox_destructive run an irreversible / money-moving one
|
|
12
|
+
*
|
|
13
|
+
* Which tools a principal sees depends on ./policy.js, and each execute tool
|
|
14
|
+
* only accepts operations of its own tier. The host supplies `dispatch`,
|
|
15
|
+
* which actually calls the API, plus optional audit hooks.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const { fromJsonSchema } = require("@modelcontextprotocol/server");
|
|
19
|
+
const { TIER_TOOL, allowedTiers, authorize, visibleOperations } = require("./policy");
|
|
20
|
+
const { formatEnvelope, textResult } = require("./result");
|
|
21
|
+
const { redact } = require("./redact");
|
|
22
|
+
|
|
23
|
+
const SEARCH_DEFAULT_LIMIT = 20;
|
|
24
|
+
const SEARCH_MAX_LIMIT = 50;
|
|
25
|
+
|
|
26
|
+
const INSPECT = {
|
|
27
|
+
readOnlyHint: true,
|
|
28
|
+
destructiveHint: false,
|
|
29
|
+
idempotentHint: true,
|
|
30
|
+
openWorldHint: false,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const EXECUTE_INPUT = {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
operation: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Operation name from meterbox_search_operations, e.g. get_v1_customers.",
|
|
39
|
+
},
|
|
40
|
+
path_params: {
|
|
41
|
+
type: "object",
|
|
42
|
+
description: 'Values for the {placeholders} in the operation\'s path, e.g. {"id": "cus_42"}.',
|
|
43
|
+
additionalProperties: { type: ["string", "number"] },
|
|
44
|
+
},
|
|
45
|
+
query: {
|
|
46
|
+
type: "object",
|
|
47
|
+
description: 'Query parameters, e.g. {"limit": 20}.',
|
|
48
|
+
},
|
|
49
|
+
body: {
|
|
50
|
+
description: "JSON request body, for operations that take one.",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ["operation"],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function toolDefinitions(apiReferenceUrl) {
|
|
57
|
+
const ref = apiReferenceUrl ? ` API reference: ${apiReferenceUrl}` : "";
|
|
58
|
+
const calls = `Calls the Meterbox REST API (/v1).${ref}`;
|
|
59
|
+
const howTo =
|
|
60
|
+
"Find the operation with meterbox_search_operations and check its inputs with meterbox_describe_operation first.";
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
name: "meterbox_whoami",
|
|
64
|
+
title: "Show connection details",
|
|
65
|
+
description:
|
|
66
|
+
"Show which Meterbox environment this connection acts on (sandbox or production), whether it can make changes, which toolsets it can use, and which tools are available. Call this first.",
|
|
67
|
+
inputSchema: { type: "object", properties: {} },
|
|
68
|
+
annotations: INSPECT,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "meterbox_search_operations",
|
|
72
|
+
title: "Search Meterbox operations",
|
|
73
|
+
description:
|
|
74
|
+
"Find Meterbox API operations by keyword (all words must match; falls back to any word), optionally filtered by toolset or tier. Returns each operation's name, the tool that runs it, its HTTP method and path, and a summary. Only operations this connection may run are listed.",
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
query: { type: "string", description: 'Keywords, e.g. "customer credits".' },
|
|
79
|
+
toolset: {
|
|
80
|
+
type: "string",
|
|
81
|
+
description: 'Limit to one toolset, e.g. "customers" or "catalog".',
|
|
82
|
+
},
|
|
83
|
+
tier: {
|
|
84
|
+
type: "string",
|
|
85
|
+
enum: ["read", "create", "update", "destructive"],
|
|
86
|
+
description: "Limit to one tier.",
|
|
87
|
+
},
|
|
88
|
+
limit: {
|
|
89
|
+
type: "integer",
|
|
90
|
+
minimum: 1,
|
|
91
|
+
maximum: SEARCH_MAX_LIMIT,
|
|
92
|
+
description: `Maximum results (default ${SEARCH_DEFAULT_LIMIT}).`,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
annotations: INSPECT,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "meterbox_describe_operation",
|
|
100
|
+
title: "Describe a Meterbox operation",
|
|
101
|
+
description:
|
|
102
|
+
"Show one operation's path parameters, query parameters and request body schema, plus the tool that runs it.",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: {
|
|
106
|
+
operation: { type: "string", description: "Operation name, e.g. post_v1_plans." },
|
|
107
|
+
},
|
|
108
|
+
required: ["operation"],
|
|
109
|
+
},
|
|
110
|
+
annotations: INSPECT,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "meterbox_read",
|
|
114
|
+
tier: "read",
|
|
115
|
+
title: "Read from Meterbox",
|
|
116
|
+
description: `Run a read-only Meterbox operation: a GET, or a preview, quote, validation or simulation that changes nothing. ${howTo} ${calls}`,
|
|
117
|
+
inputSchema: EXECUTE_INPUT,
|
|
118
|
+
annotations: {
|
|
119
|
+
readOnlyHint: true,
|
|
120
|
+
destructiveHint: false,
|
|
121
|
+
idempotentHint: true,
|
|
122
|
+
openWorldHint: true,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "meterbox_create",
|
|
127
|
+
tier: "create",
|
|
128
|
+
title: "Create in Meterbox",
|
|
129
|
+
description: `Run an operation that only adds a new record (e.g. a coupon, a quote, an alert rule) and never changes or removes existing ones or moves money. ${howTo} ${calls}`,
|
|
130
|
+
inputSchema: EXECUTE_INPUT,
|
|
131
|
+
annotations: {
|
|
132
|
+
readOnlyHint: false,
|
|
133
|
+
destructiveHint: false,
|
|
134
|
+
idempotentHint: false,
|
|
135
|
+
openWorldHint: true,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "meterbox_update",
|
|
140
|
+
tier: "update",
|
|
141
|
+
title: "Change records in Meterbox",
|
|
142
|
+
description: `Run an operation that changes or replaces existing records or settings (e.g. replace a plan, edit a customer's tags). Changes are reversible and never move money. ${howTo} ${calls}`,
|
|
143
|
+
inputSchema: EXECUTE_INPUT,
|
|
144
|
+
annotations: {
|
|
145
|
+
readOnlyHint: false,
|
|
146
|
+
destructiveHint: true,
|
|
147
|
+
idempotentHint: false,
|
|
148
|
+
openWorldHint: true,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "meterbox_destructive",
|
|
153
|
+
tier: "destructive",
|
|
154
|
+
title: "Irreversible or money-moving change",
|
|
155
|
+
description: `Run an irreversible or money-moving operation: deletes, invoice approval or voiding, credit notes, credit and wallet grants, plan changes with proration, usage ingestion, month-end close. Sandbox only. Confirm the exact operation and arguments with the user before calling. ${howTo} ${calls}`,
|
|
156
|
+
inputSchema: EXECUTE_INPUT,
|
|
157
|
+
annotations: {
|
|
158
|
+
readOnlyHint: false,
|
|
159
|
+
destructiveHint: true,
|
|
160
|
+
idempotentHint: false,
|
|
161
|
+
openWorldHint: true,
|
|
162
|
+
},
|
|
163
|
+
_meta: { "anthropic/requiresUserInteraction": true },
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
169
|
+
|
|
170
|
+
function paramsIn(op, where) {
|
|
171
|
+
return (op.parameters || []).filter((p) => p.in === where);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function isScalar(v) {
|
|
175
|
+
return typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function prepareArgs(op, args) {
|
|
179
|
+
const pathParams = {};
|
|
180
|
+
const given = args.path_params || {};
|
|
181
|
+
for (const { name } of paramsIn(op, "path")) {
|
|
182
|
+
const v = given[name];
|
|
183
|
+
if (v === undefined || v === null || v === "")
|
|
184
|
+
return { error: `Missing path parameter '${name}'.` };
|
|
185
|
+
if (typeof v !== "string" && typeof v !== "number") {
|
|
186
|
+
return { error: `Path parameter '${name}' must be a string or number.` };
|
|
187
|
+
}
|
|
188
|
+
// encodeURIComponent leaves dots alone, so "." and ".." would become
|
|
189
|
+
// dot-segments that walk the URL path.
|
|
190
|
+
if (String(v) === "." || String(v) === "..")
|
|
191
|
+
return { error: `Path parameter '${name}' is not a valid id.` };
|
|
192
|
+
pathParams[name] = String(v);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const queryNames = new Set(paramsIn(op, "query").map((p) => p.name));
|
|
196
|
+
const query = {};
|
|
197
|
+
const unknown = [];
|
|
198
|
+
for (const [k, v] of Object.entries(args.query || {})) {
|
|
199
|
+
if (!queryNames.has(k)) {
|
|
200
|
+
unknown.push(k);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (v === undefined || v === null) continue;
|
|
204
|
+
if (!isScalar(v) && !(Array.isArray(v) && v.every(isScalar))) {
|
|
205
|
+
return {
|
|
206
|
+
error: `Query parameter '${k}' must be a string, number, boolean or a list of those.`,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
query[k] = v;
|
|
210
|
+
}
|
|
211
|
+
if (unknown.length) {
|
|
212
|
+
return {
|
|
213
|
+
error: `Unknown query parameter(s) for ${op.name}: ${unknown.join(", ")}. Use meterbox_describe_operation to see its inputs.`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const { body } = args;
|
|
218
|
+
if (op.hasBody) {
|
|
219
|
+
if (body === undefined && (op.inputSchema.required || []).includes("body")) {
|
|
220
|
+
return {
|
|
221
|
+
error: `${op.name} requires a body. Use meterbox_describe_operation to see its schema.`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
} else if (body !== undefined) {
|
|
225
|
+
return { error: `${op.name} takes no request body.` };
|
|
226
|
+
}
|
|
227
|
+
return { pathParams, query, body: op.hasBody ? body : undefined };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const LOST_CONNECTION = new Set([
|
|
231
|
+
"ETIMEDOUT",
|
|
232
|
+
"ECONNRESET",
|
|
233
|
+
"EPIPE",
|
|
234
|
+
"UND_ERR_SOCKET",
|
|
235
|
+
"ABORT_ERR",
|
|
236
|
+
]);
|
|
237
|
+
const NOT_SENT = new Set(["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN"]);
|
|
238
|
+
|
|
239
|
+
function outcomeUnknown(op) {
|
|
240
|
+
return `Outcome unknown: ${op.method} ${op.path} lost its connection after the request was sent, so it may have been applied. Check the current state with meterbox_read before retrying.`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function describeFailure(err, op) {
|
|
244
|
+
const lost =
|
|
245
|
+
LOST_CONNECTION.has(err.code) || err.name === "AbortError" || err.name === "TimeoutError";
|
|
246
|
+
if (NOT_SENT.has(err.code))
|
|
247
|
+
return "Meterbox is temporarily unreachable and nothing was sent. Retry shortly.";
|
|
248
|
+
if (lost && op.tier !== "read") return outcomeUnknown(op);
|
|
249
|
+
if (lost) return `${op.method} ${op.path} timed out. It changes nothing, so it's safe to retry.`;
|
|
250
|
+
return `${op.method} ${op.path} failed: ${err.message}`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function errorDetail(body) {
|
|
254
|
+
if (!body) return "";
|
|
255
|
+
if (typeof body === "string") return body.slice(0, 500);
|
|
256
|
+
return JSON.stringify(redact(body)).slice(0, 2000);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function describeHttpError({ status, body }, op) {
|
|
260
|
+
if (op.tier !== "read" && (status === 502 || status === 504)) return outcomeUnknown(op);
|
|
261
|
+
if (status === 503)
|
|
262
|
+
return "Meterbox is temporarily unavailable and nothing was applied. Retry shortly.";
|
|
263
|
+
if (status >= 500 && op.tier === "read") {
|
|
264
|
+
return `${op.method} ${op.path} failed with HTTP ${status}. It changes nothing, so it's safe to retry. ${errorDetail(body)}`.trim();
|
|
265
|
+
}
|
|
266
|
+
return `HTTP ${status} from ${op.method} ${op.path}: ${errorDetail(body)}`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function safeHook(fn, event) {
|
|
270
|
+
if (!fn) return;
|
|
271
|
+
try {
|
|
272
|
+
await fn(event);
|
|
273
|
+
} catch (_) {
|
|
274
|
+
// Reporting hooks never change a tool's result.
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function describeOperation(op) {
|
|
279
|
+
const schemaFor = (names) =>
|
|
280
|
+
Object.fromEntries(names.map((n) => [n, op.inputSchema.properties[n]]).filter(([, s]) => s));
|
|
281
|
+
const pathNames = paramsIn(op, "path").map((p) => p.name);
|
|
282
|
+
const queryNames = paramsIn(op, "query").map((p) => p.name);
|
|
283
|
+
const required = op.inputSchema.required || [];
|
|
284
|
+
return {
|
|
285
|
+
operation: op.name,
|
|
286
|
+
tool: TIER_TOOL[op.tier],
|
|
287
|
+
method: op.method,
|
|
288
|
+
path: op.path,
|
|
289
|
+
summary: op.summary,
|
|
290
|
+
toolsets: op.toolsets,
|
|
291
|
+
path_params: schemaFor(pathNames),
|
|
292
|
+
query: schemaFor(queryNames),
|
|
293
|
+
query_required: queryNames.filter((n) => required.includes(n)),
|
|
294
|
+
body: op.hasBody ? op.inputSchema.properties.body : null,
|
|
295
|
+
body_required: required.includes("body"),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function searchOperations(visible, { query, toolset, tier, limit }) {
|
|
300
|
+
let pool = visible;
|
|
301
|
+
if (toolset) pool = pool.filter((op) => op.toolsets.includes(toolset));
|
|
302
|
+
if (tier) pool = pool.filter((op) => op.tier === tier);
|
|
303
|
+
const terms = String(query || "")
|
|
304
|
+
.toLowerCase()
|
|
305
|
+
.split(/\s+/)
|
|
306
|
+
.filter(Boolean);
|
|
307
|
+
let ranked = pool.map((op) => ({ op, score: 0 }));
|
|
308
|
+
if (terms.length) {
|
|
309
|
+
const scored = pool.map((op) => {
|
|
310
|
+
const hay = `${op.name} ${op.summary} ${op.path} ${op.toolsets.join(" ")}`.toLowerCase();
|
|
311
|
+
return { op, score: terms.filter((t) => hay.includes(t)).length };
|
|
312
|
+
});
|
|
313
|
+
const all = scored.filter((s) => s.score === terms.length);
|
|
314
|
+
ranked = (all.length ? all : scored.filter((s) => s.score > 0)).sort(
|
|
315
|
+
(a, b) => b.score - a.score || a.op.name.localeCompare(b.op.name),
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const max = Math.min(Math.max(Number(limit) || SEARCH_DEFAULT_LIMIT, 1), SEARCH_MAX_LIMIT);
|
|
319
|
+
return {
|
|
320
|
+
total: ranked.length,
|
|
321
|
+
matches: ranked.slice(0, max).map(({ op }) => ({
|
|
322
|
+
operation: op.name,
|
|
323
|
+
tool: TIER_TOOL[op.tier],
|
|
324
|
+
method: op.method,
|
|
325
|
+
path: op.path,
|
|
326
|
+
summary: op.summary,
|
|
327
|
+
toolsets: op.toolsets,
|
|
328
|
+
})),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ── registration ─────────────────────────────────────────────────────────────
|
|
333
|
+
|
|
334
|
+
function registerTools(
|
|
335
|
+
server,
|
|
336
|
+
{ catalog, principal, dispatch, hooks = {}, apiReferenceUrl, policy = {} },
|
|
337
|
+
) {
|
|
338
|
+
const tiers = allowedTiers(principal, policy);
|
|
339
|
+
const visible = visibleOperations(catalog, principal, policy);
|
|
340
|
+
const byName = new Map(catalog.map((op) => [op.name, op]));
|
|
341
|
+
const definitions = toolDefinitions(apiReferenceUrl).filter((d) => !d.tier || tiers.has(d.tier));
|
|
342
|
+
const toolNames = definitions.map((d) => d.name);
|
|
343
|
+
|
|
344
|
+
const handlers = {
|
|
345
|
+
meterbox_whoami: async () =>
|
|
346
|
+
textResult(
|
|
347
|
+
formatEnvelope({
|
|
348
|
+
environment: principal.environment,
|
|
349
|
+
access: principal.access,
|
|
350
|
+
toolsets: principal.toolsets || "all",
|
|
351
|
+
key_id: principal.key_id || null,
|
|
352
|
+
tools: toolNames,
|
|
353
|
+
operations_available: visible.length,
|
|
354
|
+
api_reference: apiReferenceUrl || null,
|
|
355
|
+
}),
|
|
356
|
+
),
|
|
357
|
+
|
|
358
|
+
meterbox_search_operations: async (args) =>
|
|
359
|
+
textResult(formatEnvelope(searchOperations(visible, args || {}))),
|
|
360
|
+
|
|
361
|
+
meterbox_describe_operation: async ({ operation }) => {
|
|
362
|
+
const op = byName.get(operation);
|
|
363
|
+
const verdict = authorize(principal, op ? TIER_TOOL[op.tier] : "meterbox_read", op, policy);
|
|
364
|
+
if (!verdict.allowed) return textResult(verdict.message, true);
|
|
365
|
+
return textResult(formatEnvelope(describeOperation(op)));
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const execute = (tool) => async (args, extra) => {
|
|
370
|
+
const op = byName.get(args.operation);
|
|
371
|
+
const verdict = authorize(principal, tool, op, policy);
|
|
372
|
+
if (!verdict.allowed) {
|
|
373
|
+
await safeHook(hooks.onDenied, {
|
|
374
|
+
principal,
|
|
375
|
+
tool,
|
|
376
|
+
operation: args.operation,
|
|
377
|
+
code: verdict.code,
|
|
378
|
+
});
|
|
379
|
+
return textResult(verdict.message, true);
|
|
380
|
+
}
|
|
381
|
+
const prepared = prepareArgs(op, args);
|
|
382
|
+
if (prepared.error) return textResult(prepared.error, true);
|
|
383
|
+
|
|
384
|
+
if (hooks.beforeCall) {
|
|
385
|
+
try {
|
|
386
|
+
const decision = await hooks.beforeCall({ principal, tool, op, args: prepared });
|
|
387
|
+
if (decision && decision.denied) return textResult(decision.message, true);
|
|
388
|
+
} catch (_) {
|
|
389
|
+
// A write that can't be recorded doesn't run; a read still can.
|
|
390
|
+
if (op.tier !== "read") {
|
|
391
|
+
return textResult(
|
|
392
|
+
"Meterbox couldn't record this call for audit, so it wasn't run. Retry shortly.",
|
|
393
|
+
true,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const signal = extra && extra.http && extra.http.req ? extra.http.req.signal : undefined;
|
|
400
|
+
const started = Date.now();
|
|
401
|
+
let response;
|
|
402
|
+
let failure;
|
|
403
|
+
try {
|
|
404
|
+
response = await dispatch(op, prepared, { principal, signal });
|
|
405
|
+
} catch (err) {
|
|
406
|
+
failure = err;
|
|
407
|
+
}
|
|
408
|
+
await safeHook(hooks.afterCall, {
|
|
409
|
+
principal,
|
|
410
|
+
tool,
|
|
411
|
+
op,
|
|
412
|
+
args: prepared,
|
|
413
|
+
status: response ? response.status : null,
|
|
414
|
+
error: failure || null,
|
|
415
|
+
durationMs: Date.now() - started,
|
|
416
|
+
});
|
|
417
|
+
if (failure) return textResult(describeFailure(failure, op), true);
|
|
418
|
+
if (response.status >= 400) return textResult(describeHttpError(response, op), true);
|
|
419
|
+
return textResult(
|
|
420
|
+
formatEnvelope({
|
|
421
|
+
environment: principal.environment,
|
|
422
|
+
operation: op.name,
|
|
423
|
+
status: response.status,
|
|
424
|
+
data: response.body === undefined ? null : response.body,
|
|
425
|
+
}),
|
|
426
|
+
);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
for (const def of definitions) {
|
|
430
|
+
const handler = def.tier ? execute(def.name) : handlers[def.name];
|
|
431
|
+
const config = {
|
|
432
|
+
title: def.title,
|
|
433
|
+
description: def.description,
|
|
434
|
+
inputSchema: fromJsonSchema(def.inputSchema),
|
|
435
|
+
annotations: { title: def.title, ...def.annotations },
|
|
436
|
+
};
|
|
437
|
+
if (def._meta) config._meta = def._meta;
|
|
438
|
+
server.registerTool(def.name, config, handler);
|
|
439
|
+
}
|
|
440
|
+
return toolNames;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
module.exports = {
|
|
444
|
+
registerTools,
|
|
445
|
+
toolDefinitions,
|
|
446
|
+
prepareArgs,
|
|
447
|
+
searchOperations,
|
|
448
|
+
describeHttpError,
|
|
449
|
+
describeFailure,
|
|
450
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meterbox/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Meterbox MCP server: the hosted /mcp endpoint's tools and policy, plus a stdio bridge (npx @meterbox/mcp) for MCP clients that only speak stdio.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://meterbox.ai",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"meterbox-mcp": "./bin/meterbox-mcp.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"lib/",
|
|
14
|
+
"bin/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@meterbox/ops": "0.1.0",
|
|
26
|
+
"@modelcontextprotocol/client": "2.2.0",
|
|
27
|
+
"@modelcontextprotocol/node": "2.1.0",
|
|
28
|
+
"@modelcontextprotocol/server": "2.2.0",
|
|
29
|
+
"hono": "^4.11.4"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"meterbox",
|
|
33
|
+
"mcp",
|
|
34
|
+
"model-context-protocol",
|
|
35
|
+
"billing",
|
|
36
|
+
"claude"
|
|
37
|
+
]
|
|
38
|
+
}
|