@lunora/mcp 1.0.0-alpha.21 → 1.0.0-alpha.22

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/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { connectStdio } from './packem_shared/connectStdio-mHv2dT3u.mjs';
2
+ import { connectStdio } from './packem_shared/connectStdio-CeI3w0q7.mjs';
3
3
 
4
4
  const ENABLED_ENV_VALUES = /* @__PURE__ */ new Set(["1", "on", "true", "yes"]);
5
5
  const isEnvEnabled = (value) => value !== void 0 && ENABLED_ENV_VALUES.has(value.trim().toLowerCase());
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { createMcpFetchHandler } from './packem_shared/createMcpFetchHandler-CGqlLHxj.mjs';
2
- export { createPaidMcpServer } from './packem_shared/createPaidMcpServer-S7RdldZo.mjs';
3
- export { connectStdio, createLunoraMcpServer } from './packem_shared/connectStdio-mHv2dT3u.mjs';
4
- export { READ_ONLY_TOOL_DEFINITIONS, WRITE_TOOL_DEFINITIONS, callTool, toolDefinitions } from './packem_shared/READ_ONLY_TOOL_DEFINITIONS-B5x61zt4.mjs';
1
+ export { createMcpFetchHandler } from './packem_shared/createMcpFetchHandler-D8HWylar.mjs';
2
+ export { createPaidMcpServer } from './packem_shared/createPaidMcpServer-D0vrMTDp.mjs';
3
+ export { connectStdio, createLunoraMcpServer } from './packem_shared/connectStdio-CeI3w0q7.mjs';
4
+ export { READ_ONLY_TOOL_DEFINITIONS, WRITE_TOOL_DEFINITIONS, callTool, toolDefinitions } from './packem_shared/READ_ONLY_TOOL_DEFINITIONS-CWb_wFd5.mjs';
@@ -66,23 +66,82 @@ const readFunctionPath = (input) => {
66
66
  }
67
67
  return functionPath;
68
68
  };
69
+ const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
70
+ const describeArgs = (value) => Array.isArray(value) ? "an array" : `a ${typeof value}`;
71
+ const readArgumentsBag = (raw) => {
72
+ if (raw === void 0 || raw === null) {
73
+ return {};
74
+ }
75
+ if (typeof raw === "string") {
76
+ let parsed;
77
+ try {
78
+ parsed = JSON.parse(raw);
79
+ } catch {
80
+ throw new LunoraError("BAD_REQUEST", `"args" must be a JSON object; received a string that is not valid JSON`);
81
+ }
82
+ if (!isPlainObject(parsed)) {
83
+ throw new LunoraError("BAD_REQUEST", `"args" must be a JSON object; the provided string decoded to ${describeArgs(parsed)}`);
84
+ }
85
+ return parsed;
86
+ }
87
+ if (!isPlainObject(raw)) {
88
+ throw new LunoraError("BAD_REQUEST", `"args" must be a JSON object, got ${describeArgs(raw)}`);
89
+ }
90
+ return raw;
91
+ };
69
92
  const readRunArguments = (input) => {
70
93
  const functionPath = readFunctionPath(input);
71
- const rawArguments = input.args;
72
- const isPlainObject = typeof rawArguments === "object" && rawArguments !== null && !Array.isArray(rawArguments);
73
- const args = isPlainObject ? rawArguments : {};
94
+ const args = readArgumentsBag(input.args);
74
95
  const shardKey = typeof input.shardKey === "string" && input.shardKey.length > 0 ? input.shardKey : void 0;
75
96
  return { args, functionPath, shardKey };
76
97
  };
77
98
  const reference = (functionPath) => {
78
99
  return { __lunoraRef: functionPath };
79
100
  };
101
+ const bytesToBase64 = (bytes) => {
102
+ let binary = "";
103
+ const chunk = 32768;
104
+ for (let index = 0; index < bytes.length; index += chunk) {
105
+ binary += String.fromCharCode(...bytes.subarray(index, index + chunk));
106
+ }
107
+ return btoa(binary);
108
+ };
109
+ const jsonResultReplacer = (_key, value) => {
110
+ if (typeof value === "bigint") {
111
+ return value.toString();
112
+ }
113
+ if (value instanceof ArrayBuffer) {
114
+ return bytesToBase64(new Uint8Array(value));
115
+ }
116
+ if (ArrayBuffer.isView(value)) {
117
+ const view = value;
118
+ return bytesToBase64(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
119
+ }
120
+ return value;
121
+ };
80
122
  const ok = (value) => {
81
- const text = value === void 0 ? "null" : JSON.stringify(value, void 0, 2);
123
+ const text = value === void 0 ? "null" : JSON.stringify(value, jsonResultReplacer, 2);
82
124
  return { content: [{ text, type: "text" }] };
83
125
  };
126
+ const FUNCTIONS_CACHE_TTL_MS = 3e4;
127
+ const functionsCache = /* @__PURE__ */ new WeakMap();
128
+ const listFunctionsCached = (client) => {
129
+ const now = Date.now();
130
+ const cached = functionsCache.get(client);
131
+ if (cached !== void 0 && cached.expiresAt > now) {
132
+ return cached.promise;
133
+ }
134
+ const promise = client.listFunctions().catch((error) => {
135
+ if (functionsCache.get(client)?.promise === promise) {
136
+ functionsCache.delete(client);
137
+ }
138
+ throw error;
139
+ });
140
+ functionsCache.set(client, { expiresAt: now + FUNCTIONS_CACHE_TTL_MS, promise });
141
+ return promise;
142
+ };
84
143
  const assertRunnable = async (client, functionPath, expectedKind) => {
85
- const functions = await client.listFunctions();
144
+ const functions = await listFunctionsCached(client);
86
145
  const descriptor = functions.find((function_) => function_.path === functionPath);
87
146
  if (descriptor === void 0) {
88
147
  throw new LunoraError("NOT_FOUND", `function not found or not public: ${functionPath}`);
@@ -104,7 +163,7 @@ const callTool = async (client, name, input, allowWrites = false) => {
104
163
  switch (name) {
105
164
  case "lunora_get_function_schema": {
106
165
  const functionPath = readFunctionPath(input);
107
- const functions = await client.listFunctions();
166
+ const functions = await listFunctionsCached(client);
108
167
  const descriptor = functions.find((function_) => function_.path === functionPath);
109
168
  if (descriptor === void 0) {
110
169
  return { content: [{ text: `function not found: ${functionPath}`, type: "text" }], isError: true };
@@ -112,7 +171,7 @@ const callTool = async (client, name, input, allowWrites = false) => {
112
171
  return ok({ args: descriptor.args ?? [], kind: descriptor.kind, path: descriptor.path });
113
172
  }
114
173
  case "lunora_list_functions": {
115
- return ok(await client.listFunctions());
174
+ return ok(await listFunctionsCached(client));
116
175
  }
117
176
  case "lunora_list_tables": {
118
177
  return ok(await client.listGlobalTables());
@@ -6,7 +6,7 @@ import { LunoraError } from '@lunora/errors';
6
6
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
7
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
8
  import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
9
- import { toolDefinitions, callTool } from './READ_ONLY_TOOL_DEFINITIONS-B5x61zt4.mjs';
9
+ import { toolDefinitions, callTool } from './READ_ONLY_TOOL_DEFINITIONS-CWb_wFd5.mjs';
10
10
 
11
11
  const resolveVersion = () => {
12
12
  try {
@@ -1,5 +1,5 @@
1
1
  import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
2
- import { createLunoraMcpServer } from './connectStdio-mHv2dT3u.mjs';
2
+ import { createLunoraMcpServer } from './connectStdio-CeI3w0q7.mjs';
3
3
 
4
4
  const serveStateless = async (server, request, options) => {
5
5
  const transport = new WebStandardStreamableHTTPServerTransport({ enableJsonResponse: true, sessionIdGenerator: void 0 });
@@ -2,7 +2,7 @@ import { LunoraError } from '@lunora/errors';
2
2
  import { createChargeMiddleware } from '@lunora/x402/charge';
3
3
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
4
  import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
5
- import { serveStateless } from './createMcpFetchHandler-CGqlLHxj.mjs';
5
+ import { serveStateless } from './createMcpFetchHandler-D8HWylar.mjs';
6
6
 
7
7
  const DEFAULT_SERVER_INFO = { name: "lunora-paid-mcp", version: "0.0.0" };
8
8
  const CALL_TOOL_METHOD = "tools/call";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/mcp",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.22",
4
4
  "description": "Model Context Protocol server exposing a Lunora deployment to AI agents",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -49,9 +49,9 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@lunora/client": "1.0.0-alpha.20",
53
- "@lunora/errors": "1.0.0-alpha.3",
54
- "@lunora/x402": "1.0.0-alpha.1",
52
+ "@lunora/client": "1.0.0-alpha.21",
53
+ "@lunora/errors": "1.0.0-alpha.4",
54
+ "@lunora/x402": "1.0.0-alpha.2",
55
55
  "@modelcontextprotocol/sdk": "^1.29.0"
56
56
  },
57
57
  "engines": {