@lunora/mcp 1.0.0-alpha.240 → 1.0.0-alpha.242

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.
Files changed (33) hide show
  1. package/dist/bin.mjs +1 -1
  2. package/dist/docs/index.d.mts +4 -3
  3. package/dist/docs/index.d.ts +4 -3
  4. package/dist/index.d.mts +11 -473
  5. package/dist/index.d.ts +11 -473
  6. package/dist/index.mjs +1 -1
  7. package/dist/node/index.d.mts +90 -0
  8. package/dist/node/index.d.ts +90 -0
  9. package/dist/node/index.mjs +1 -0
  10. package/dist/packem_shared/{LOCAL_SERVER_NAME-DM_NJ-eY.mjs → LOCAL_SERVER_NAME-Ci-W2me-.mjs} +1 -1
  11. package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-DT0XSV-2.mjs +1 -0
  12. package/dist/packem_shared/{serve-stateless.d-CKsbI0fP.d.mts → compose.d-BVnP3uAy.d.mts} +1 -44
  13. package/dist/packem_shared/{serve-stateless.d-CKsbI0fP.d.ts → compose.d-BVnP3uAy.d.ts} +1 -44
  14. package/dist/packem_shared/connectStdio-DHQHl6rX.mjs +1 -0
  15. package/dist/packem_shared/createAuthedMcpFetchHandler-BXBFeTtN.mjs +1 -0
  16. package/dist/packem_shared/createLunoraMcpServer-CuxvnEnG.mjs +1 -0
  17. package/dist/packem_shared/createMcpFetchHandler-DKTmo27x.mjs +1 -0
  18. package/dist/packem_shared/createPaidMcpServer-BH_mly77.mjs +1 -0
  19. package/dist/packem_shared/serve-stateless.d-DD5arqFx.d.mts +45 -0
  20. package/dist/packem_shared/serve-stateless.d-DD5arqFx.d.ts +45 -0
  21. package/dist/packem_shared/server.d-D3rejkVc.d.mts +152 -0
  22. package/dist/packem_shared/server.d-DQgZyRkG.d.ts +152 -0
  23. package/dist/packem_shared/tools-DSqDlu_n.mjs +2 -0
  24. package/dist/worker/index.d.mts +258 -0
  25. package/dist/worker/index.d.ts +258 -0
  26. package/dist/worker/index.mjs +1 -0
  27. package/package.json +12 -3
  28. package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-DA4wD25I.mjs +0 -1
  29. package/dist/packem_shared/connectStdio-n-RHjcwN.mjs +0 -1
  30. package/dist/packem_shared/createAuthedMcpFetchHandler-DSTZ2ftz.mjs +0 -1
  31. package/dist/packem_shared/createMcpFetchHandler-CNEfLA-N.mjs +0 -1
  32. package/dist/packem_shared/createPaidMcpServer-C_V1beyQ.mjs +0 -1
  33. package/dist/packem_shared/tools-Dmnb3M2T.mjs +0 -2
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{parseAgentsEnv as N}from"./packem_shared/AGENT_RUN_INPUT_SCHEMA-hKbpa3Dg.mjs";import{connectStdio as l}from"./packem_shared/connectStdio-n-RHjcwN.mjs";const E=new Set(["1","on","true","yes"]),o=r=>r!==void 0&&E.has(r.trim().toLowerCase());class s extends Error{code;constructor(e,a){super(e),this.name="BinError",this.code=a}}const O=async(r,e={})=>{const a=e.connect??l,i=e.writeError??(t=>{process.stderr.write(t)}),n=r.LUNORA_URL;if(n===void 0||n.length===0)throw i(`lunora-mcp: LUNORA_URL environment variable is required
2
+ import{parseAgentsEnv as N}from"./packem_shared/AGENT_RUN_INPUT_SCHEMA-hKbpa3Dg.mjs";import l from"./packem_shared/connectStdio-DHQHl6rX.mjs";const E=new Set(["1","on","true","yes"]),o=r=>r!==void 0&&E.has(r.trim().toLowerCase());class s extends Error{code;constructor(e,a){super(e),this.name="BinError",this.code=a}}const O=async(r,e={})=>{const a=e.connect??l,i=e.writeError??(t=>{process.stderr.write(t)}),n=r.LUNORA_URL;if(n===void 0||n.length===0)throw i(`lunora-mcp: LUNORA_URL environment variable is required
3
3
  `),new s("LUNORA_URL environment variable is required",1);const c=r.LUNORA_ADMIN_TOKEN;if(c===void 0||c.length===0)throw i(`lunora-mcp: LUNORA_ADMIN_TOKEN environment variable is required (every tool reads admin-gated routes)
4
4
  `),new s("LUNORA_ADMIN_TOKEN environment variable is required",1);const A=Number(r.LUNORA_MCP_AGENT_TIMEOUT_MS),_=Number.isFinite(A)&&A>0?A:void 0;try{await a({agents:N(r.LUNORA_MCP_AGENTS),allowAgents:o(r.LUNORA_MCP_ALLOW_AGENTS),allowDataReads:o(r.LUNORA_MCP_ALLOW_DATA_READS),allowObservability:o(r.LUNORA_MCP_ALLOW_OBSERVABILITY),allowWrites:o(r.LUNORA_MCP_ALLOW_WRITES),token:c,url:n,..._===void 0?{}:{agentMaxWaitMs:_}})}catch(t){const L=t instanceof Error?t.message:String(t);throw i(`lunora-mcp: failed to start — ${L}
5
5
  `),new s(`failed to start — ${L}`,1)}};try{await O(process.env)}catch(r){process.exit(r instanceof s?r.code:1)}
@@ -1,4 +1,4 @@
1
- import { M as McpResourceProvider, a as McpFetchHandler, T as ToolDefinition, b as McpTool } from "../packem_shared/serve-stateless.d-CKsbI0fP.mjs";
1
+ import { e as McpResourceProvider, T as ToolDefinition, a as McpTool } from "../packem_shared/compose.d-BVnP3uAy.mjs";
2
2
  export type {
3
3
  /**
4
4
  * `@lunora/mcp/docs` — the documentation tool surface: `lunora_search_docs`,
@@ -24,7 +24,7 @@ export type {
24
24
  * (`createToolServer`) is exported from the package root, so a consumer using
25
25
  * both entries gets one implementation rather than two copies.
26
26
  */
27
- c as McpResourceSummary,
27
+ f as McpResourceSummary,
28
28
  /**
29
29
  * `@lunora/mcp/docs` — the documentation tool surface: `lunora_search_docs`,
30
30
  * `lunora_get_doc`, and `lunora_list_docs`.
@@ -49,7 +49,8 @@ c as McpResourceSummary,
49
49
  * (`createToolServer`) is exported from the package root, so a consumer using
50
50
  * both entries gets one implementation rather than two copies.
51
51
  */
52
- d as McpServerInfo, e as ToolInputSchema, f as ToolResult } from "../packem_shared/serve-stateless.d-CKsbI0fP.mjs";
52
+ M as McpServerInfo, b as ToolInputSchema, c as ToolResult } from "../packem_shared/compose.d-BVnP3uAy.mjs";
53
+ import { M as McpFetchHandler } from "../packem_shared/serve-stateless.d-DD5arqFx.mjs";
53
54
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
54
55
  import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
55
56
  /**
@@ -1,4 +1,4 @@
1
- import { M as McpResourceProvider, a as McpFetchHandler, T as ToolDefinition, b as McpTool } from "../packem_shared/serve-stateless.d-CKsbI0fP.js";
1
+ import { e as McpResourceProvider, T as ToolDefinition, a as McpTool } from "../packem_shared/compose.d-BVnP3uAy.js";
2
2
  export type {
3
3
  /**
4
4
  * `@lunora/mcp/docs` — the documentation tool surface: `lunora_search_docs`,
@@ -24,7 +24,7 @@ export type {
24
24
  * (`createToolServer`) is exported from the package root, so a consumer using
25
25
  * both entries gets one implementation rather than two copies.
26
26
  */
27
- c as McpResourceSummary,
27
+ f as McpResourceSummary,
28
28
  /**
29
29
  * `@lunora/mcp/docs` — the documentation tool surface: `lunora_search_docs`,
30
30
  * `lunora_get_doc`, and `lunora_list_docs`.
@@ -49,7 +49,8 @@ c as McpResourceSummary,
49
49
  * (`createToolServer`) is exported from the package root, so a consumer using
50
50
  * both entries gets one implementation rather than two copies.
51
51
  */
52
- d as McpServerInfo, e as ToolInputSchema, f as ToolResult } from "../packem_shared/serve-stateless.d-CKsbI0fP.js";
52
+ M as McpServerInfo, b as ToolInputSchema, c as ToolResult } from "../packem_shared/compose.d-BVnP3uAy.js";
53
+ import { M as McpFetchHandler } from "../packem_shared/serve-stateless.d-DD5arqFx.js";
53
54
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
54
55
  import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
55
56
  /**
package/dist/index.d.mts CHANGED
@@ -1,474 +1,4 @@
1
- import { LunoraClient } from '@lunora/client';
2
- import { T as ToolDefinition, f as ToolResult, e as ToolInputSchema, a as McpFetchHandler, b as McpTool } from "./packem_shared/serve-stateless.d-CKsbI0fP.mjs";
3
- export { D as DEFAULT_MAX_REQUEST_BYTES, type d as McpServerInfo, type S as ServeStatelessOptions, g as createToolServer, s as serveStateless } from "./packem_shared/serve-stateless.d-CKsbI0fP.mjs";
4
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
- import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
- import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
7
- /**
8
- * The observability tools. Descriptions say WHEN to call the tool, not just
9
- * what it returns — an agent picking between five similar reads needs the
10
- * trigger, and it pays for these strings on every turn.
11
- */
12
- declare const OBSERVABILITY_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
13
- /** The read-only tool surface: introspection + query. Always exposed. */
14
- declare const READ_ONLY_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
15
- /** The write tool surface (mutations + actions). Exposed ONLY when writes are enabled. */
16
- declare const WRITE_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
17
- /**
18
- * The tools this server advertises: every family whose gate is open, in table
19
- * order. A gated family is OMITTED rather than refused — an AI agent can't
20
- * invoke what it can't see — and {@link callTool} re-checks the same gate at
21
- * dispatch, so the guarantee does not depend on a client honouring this list.
22
- */
23
- declare const toolDefinitions: (allowWrites: boolean, allowObservability?: boolean, allowDataReads?: boolean) => ReadonlyArray<ToolDefinition>;
24
- /**
25
- * Dispatch a tool call against `client`: find the family that owns `name`, check
26
- * its gate, hand off. Unknown tools and thrown errors are returned as `isError`
27
- * results (rather than rejections) so the calling model sees the failure as tool
28
- * output, per the MCP convention.
29
- *
30
- * Each gate is enforced HERE as well as in {@link toolDefinitions}, so a call to
31
- * a gated tool is refused even if the client somehow names one it was never
32
- * shown.
33
- */
34
- declare const callTool: (client: LunoraClient, name: string, input: Record<string, unknown>, allowWrites?: boolean, allowObservability?: boolean, allowDataReads?: boolean) => Promise<ToolResult>;
35
- /**
36
- * Agent exposure for the MCP server: a durable `@lunora/agent` run fronted as an
37
- * MCP tool an external agent can call. The capability boundary is the MCP-server
38
- * process + its token, so WHICH agents are exposed is config on the server (like
39
- * `allowWrites`), not on `defineAgent` — keeping `@lunora/agent` codegen
40
- * byte-identical.
41
- */
42
- interface McpAgentExposure {
43
- /** What the agent does — shown to the calling model, which decides from it. */
44
- description: string;
45
- /** The agent's export name (its `ctx.agents.<name>` / `AGENT_<NAME>` binding). */
46
- name: string;
47
- /** Override the model-facing tool name (default `agent_<name>`). */
48
- toolName?: string;
49
- }
50
- /** The generic status/poll tool advertised alongside the per-agent tools. */
51
- declare const AGENT_STATUS_TOOL_NAME = "lunora_agent_status";
52
- /**
53
- * The uniform input schema every agent tool advertises. Agents share ONE run
54
- * input (`@lunora/agent` has no per-agent validator), so there is nothing to
55
- * derive per agent — a single static schema is reused for every agent tool.
56
- */
57
- declare const AGENT_RUN_INPUT_SCHEMA: ToolInputSchema;
58
- /**
59
- * Parse `LUNORA_MCP_AGENTS` — a `;`-separated list of `name:description` pairs,
60
- * e.g. `"support:Handles support questions;billing:Billing help"`. The
61
- * description may itself contain colons (only the FIRST colon splits). Blank
62
- * entries and entries with an empty name/description are skipped.
63
- */
64
- declare const parseAgentsEnv: (raw: string | undefined) => McpAgentExposure[];
65
- /**
66
- * The tools this module advertises. Fail-closed: only the boolean `true` opts
67
- * in (an env-plumbed caller could pass a truthy string), and the tools appear
68
- * ONLY when at least one agent is exposed — so an agent-free or non-opted-in
69
- * server never lists them.
70
- */
71
- declare const agentToolDefinitions: (exposures: ReadonlyArray<McpAgentExposure>, allowAgents: boolean) => ReadonlyArray<ToolDefinition>;
72
- /** Options threaded into a single agent tool dispatch. */
73
- interface CallAgentToolOptions {
74
- /** Opt-in gate — must be exactly `true` or the call is refused fail-closed. */
75
- allowAgents: boolean;
76
- /** The exposures advertised by this server. */
77
- exposures: ReadonlyArray<McpAgentExposure>;
78
- /** Wall-clock budget a single call awaits before returning a pending result. */
79
- maxWaitMs?: number;
80
- /** Delay between thread-status polls. */
81
- pollIntervalMs?: number;
82
- /** Test seam replacing the between-poll wait; production uses a real timer. */
83
- wait?: (ms: number) => Promise<void>;
84
- }
85
- /**
86
- * Dispatch an agent tool call: start a durable run via `agents:agentRun`, then
87
- * await-with-timeout — poll `agents:agentThread` until terminal (returning the
88
- * final answer from `agents:agentMessages`) or, on budget exhaustion, return a
89
- * NON-error pending payload the caller resumes with `lunora_agent_status`.
90
- *
91
- * Fail-closed: refused at dispatch unless `allowAgents === true`, mirroring the
92
- * `allowWrites` guard — starting a run is a side effect and must not ride the
93
- * read-only default.
94
- */
95
- declare const callAgentTool: (client: LunoraClient, name: string, input: Record<string, unknown>, options: CallAgentToolOptions) => Promise<ToolResult>;
96
- interface LunoraMcpServerOptions {
97
- /** Wall-clock budget a single agent tool call awaits before returning a pending result. */
98
- agentMaxWaitMs?: number;
99
- /** Delay between agent thread-status polls. */
100
- agentPollIntervalMs?: number;
101
- /** The agents this server fronts as MCP tools (see `allowAgents`). */
102
- agents?: ReadonlyArray<McpAgentExposure>;
103
- /**
104
- * Expose the per-agent tools (`agent_<name>` + the generic
105
- * `lunora_agent_status`). Defaults to `false`, mirroring `allowWrites`:
106
- * starting a durable agent run is a side effect, so the agent tools are
107
- * omitted from the advertised list AND refused at dispatch unless explicitly
108
- * opted in. Only takes effect together with a non-empty `agents` list.
109
- */
110
- allowAgents?: boolean;
111
- /**
112
- * Expose `lunora_find_related`, which returns raw table rows read through the
113
- * admin writer, so RLS policies and column masks do not apply. Defaults to
114
- * `false`, for the same reason as `allowObservability`. Only takes effect
115
- * when a `token` resolved. On the OAuth-protected path the verified token must
116
- * also carry the data-read scope (see `DATA_READ_SCOPE` in `./tools`).
117
- */
118
- allowDataReads?: boolean;
119
- /**
120
- * Expose the observability tools (`lunora_get_logs`, `lunora_get_issues`,
121
- * `lunora_get_advisories`, `lunora_get_query_insights`,
122
- * `lunora_get_migration_status`). Defaults to `false`, mirroring
123
- * `allowWrites`: they are read-only, but every row they return — log lines,
124
- * request metadata, grouped error messages — is production user data that
125
- * lands in the model's context and therefore at its provider. Holding the
126
- * admin bearer is not consent to ship that, so it is a separate opt-in;
127
- * without it the tools are omitted from the advertised list AND refused at
128
- * dispatch. Only takes effect when a `token` resolved. On the OAuth-protected
129
- * path the verified token must also carry the observability scope (see
130
- * `OBSERVABILITY_SCOPE` in `./tools`); this option stays the outer gate.
131
- */
132
- allowObservability?: boolean;
133
- /**
134
- * Expose the write tools (`lunora_run_mutation` / `lunora_run_action`).
135
- * Defaults to `false`: the server is READ-ONLY unless explicitly opted in,
136
- * so a prompt-injected or misaligned agent can't mutate the deployment with
137
- * the configured token. When false the write tools are omitted from the
138
- * advertised tool list AND refused at dispatch.
139
- */
140
- allowWrites?: boolean;
141
- /**
142
- * Pre-built client (test injection). When omitted a `LunoraClient` is
143
- * created from `url`/`token`/`fetch`.
144
- */
145
- client?: LunoraClient;
146
- /** `fetch` implementation; defaults to the ambient global. */
147
- fetch?: typeof fetch;
148
- /**
149
- * Bearer token sent on every RPC. **Required** alongside `url`, and it must
150
- * be the deployment's **admin bearer**: the introspection/allowlist path
151
- * every tool depends on (`lunora_list_functions`, `lunora_list_tables`, and
152
- * the `assertRunnable` precheck that runs before every `run` tool) hits
153
- * admin-gated `/_lunora/admin/*` routes, so no scoped/app token works
154
- * today — it would 403 (`ADMIN_FORBIDDEN`) on the first tool call. The
155
- * read-only guarantee is therefore NOT enforced by the token's scope; it is
156
- * enforced in-process via `allowWrites: false` (the default), which omits
157
- * the write tools from the advertised list and refuses them at dispatch.
158
- *
159
- * Because EVERY tool needs it, omitting it is a misconfiguration rather than
160
- * a reduced-capability mode, and `createLunoraMcpServer` says so at
161
- * construction instead of advertising a surface that 403s on first use. The
162
- * one exception is the `client` injection seam (tests / a pre-authenticated
163
- * client), where this server cannot know what the client can reach and so
164
- * reads "unknown" fail-closed: the privileged observability tools stay
165
- * unadvertised and are refused at dispatch.
166
- */
167
- token?: string;
168
- /** Base URL of the deployed Lunora Worker. Required unless `client` is given. */
169
- url?: string;
170
- }
171
- /**
172
- * Build an MCP `Server` whose tools talk to a Lunora deployment. The server is
173
- * transport-agnostic — call `.connect(transport)` yourself, or use
174
- * `connectStdio` for the common stdio case.
175
- *
176
- * Tool calls are dispatched through `callTool`, which the deployment reaches
177
- * over HTTP RPC. No WebSocket is opened (the tools never subscribe), so this is
178
- * safe to run as a short-lived stdio process.
179
- */
180
- declare const createLunoraMcpServer: (options: LunoraMcpServerOptions) => Server;
181
- /**
182
- * Build the server and connect it over stdio — the transport MCP clients use
183
- * when they spawn the `lunora-mcp` binary. Resolves once the transport is
184
- * connected; the process then stays alive serving requests.
185
- */
186
- declare const connectStdio: (options: LunoraMcpServerOptions) => Promise<Server>;
187
- /**
188
- * The verified access-token payload better-auth hands a protected handler.
189
- *
190
- * A JWT payload is an open bag of claims, so this is deliberately an index
191
- * signature with the two entries this module reads named. It is structurally
192
- * satisfied by `jose`'s `JWTPayload`, which is what better-auth passes.
193
- */
194
- interface McpAccessTokenClaims {
195
- readonly [claim: string]: unknown;
196
- /** Space-delimited granted scopes (RFC 6749 §3.3). */
197
- readonly scope?: unknown;
198
- /** Subject — the user the token was issued for. */
199
- readonly sub?: string;
200
- }
201
- /**
202
- * The MCP auth gate: wraps a claims-aware handler into a plain fetch handler.
203
- *
204
- * Declared structurally here rather than imported from `@better-auth/mcp`,
205
- * following the same rule `./paid` follows for `@lunora/x402`: a type import
206
- * from a package this one does not depend on puts that package's `.d.ts` into
207
- * the build graph, and a consumer that never installs it never builds it
208
- * either — so the dts bundler looks for a `dist/` that does not exist and fails
209
- * the build. Structural typing costs nothing here because this module never
210
- * inspects the gate; it only applies it.
211
- *
212
- * Both better-auth entry points partially apply to this shape:
213
- * `(handler) => requireMcpAuth(auth, handler, opts)` and
214
- * `(handler) => createMcpProtectedRequestHandler(options, handler)`.
215
- */
216
- type McpAuthProtect = (handler: (request: Request, claims: McpAccessTokenClaims) => Promise<Response>) => McpFetchHandler;
217
- /** Server options, or a function deriving them from the request's verified claims. */
218
- type AuthedMcpServerOptions = ((claims: McpAccessTokenClaims) => LunoraMcpServerOptions | Promise<LunoraMcpServerOptions>) | LunoraMcpServerOptions;
219
- interface AuthedMcpFetchHandlerOptions {
220
- /**
221
- * Largest accepted request body, in bytes — enforced while the body streams
222
- * in, not after it is buffered. Defaults to `DEFAULT_MAX_REQUEST_BYTES`
223
- * (128 KiB), which a value that is not a non-negative safe integer also
224
- * falls back to.
225
- */
226
- maxRequestBytes?: number;
227
- /**
228
- * The OAuth gate to mount the MCP server behind. Pass
229
- * `(handler) => requireMcpAuth(auth, handler, opts)` from
230
- * `@lunora/auth/plugins`.
231
- */
232
- protect: McpAuthProtect;
233
- /**
234
- * The Lunora MCP server to serve once a request is authorized — either a
235
- * fixed options object, or a function of the verified token claims so tool
236
- * exposure can follow the scopes the token actually carries.
237
- */
238
- server: AuthedMcpServerOptions;
239
- /**
240
- * Step-up for the side-effecting tools: the write tools
241
- * (`lunora_run_mutation` / `lunora_run_action`) and the agent tools (each
242
- * `agent_<name>` and `lunora_agent_status`, since starting a durable run is a
243
- * side effect). A token without `scope` still sees them in `tools/list`, and
244
- * a `tools/call` to one throws `challenge([scope])` instead of running, so the
245
- * client can re-authorize for the scope and retry. Unset, tools follow
246
- * `allowWrites` / `allowAgents` alone. The raw-row and observability families
247
- * need their own token scopes with or without `stepUp`; without it a call
248
- * without the scope is refused as a tool error, not challenged.
249
- */
250
- stepUp?: {
251
- /**
252
- * Build the error that makes the gate answer 403 `insufficient_scope`
253
- * naming `scopes`. Pass `createInsufficientScopeError` from
254
- * `@lunora/auth/plugins`: better-auth only turns an error that factory
255
- * created into the challenge.
256
- */
257
- challenge: (scopes: string[]) => unknown;
258
- /** The scope a call to a side-effecting tool needs, e.g. `"lunora:write"`. */
259
- scope: string;
260
- };
261
- }
262
- /**
263
- * Parse an access token's `scope` claim into a set.
264
- *
265
- * RFC 6749 §3.3 makes `scope` a space-delimited string, and better-auth issues
266
- * it that way; anything else (absent, or a non-string an extension wrote)
267
- * yields an empty set rather than throwing, so a scope check on a malformed
268
- * token denies instead of crashing the tool call.
269
- */
270
- declare const mcpTokenScopes: (claims: McpAccessTokenClaims) => ReadonlySet<string>;
271
- declare const createAuthedMcpFetchHandler: (options: AuthedMcpFetchHandlerOptions) => McpFetchHandler;
272
- /** {@link createMcpFetchHandler} options: the server's, plus this transport's body limit. */
273
- interface McpFetchHandlerOptions extends LunoraMcpServerOptions {
274
- /**
275
- * Largest accepted request body, in bytes — enforced while the body streams
276
- * in, not after it is buffered. Defaults to `DEFAULT_MAX_REQUEST_BYTES`
277
- * (128 KiB), which a value that is not a non-negative safe integer also
278
- * falls back to.
279
- */
280
- maxRequestBytes?: number;
281
- }
282
- /**
283
- * Build a stateless Streamable-HTTP fetch handler for a Lunora MCP server. Each
284
- * invocation constructs a fresh proxy server and serves the request through
285
- * {@link serveStateless}.
286
- *
287
- * The `LunoraClient` is resolved ONCE, here, and shared by every request: it is
288
- * the same deployment on each one, and the public-function registry memo in
289
- * `./tools` is keyed by client identity, so a per-request client would re-fetch
290
- * that registry on every tool call. A misconfiguration (`url` without `token`)
291
- * therefore throws when the handler is built rather than on first request,
292
- * which is where `createLunoraMcpServer` already documents reporting it.
293
- */
294
- declare const createMcpFetchHandler: (options: McpFetchHandlerOptions) => McpFetchHandler;
295
- /** A Lunora deployment the tools dispatch against. */
296
- interface LocalDeployment {
297
- token?: string;
298
- url: string;
299
- }
300
- /**
301
- * Where the deployment comes from: a fixed value, or a function consulted on
302
- * every tool call.
303
- *
304
- * The resolver form exists because an editor spawns this server when the
305
- * project opens — routinely *before* `lunora dev` is running, and it keeps the
306
- * process alive across every restart afterwards. A URL captured once at startup
307
- * would therefore be absent for the entire first session and stale after the
308
- * first restart.
309
- */
310
- type LocalDeploymentSource = (() => LocalDeployment | undefined) | LocalDeployment;
311
- interface LocalMcpServerOptions {
312
- /**
313
- * Expose the deployment write tools (`lunora_run_mutation` /
314
- * `lunora_run_action`). Defaults to `false` — the same fail-closed default
315
- * as the remote server. Locally the blast radius is dev data rather than
316
- * production, but a mutation is still a side effect an agent should be
317
- * granted deliberately.
318
- */
319
- allowWrites?: boolean;
320
- /**
321
- * The Lunora deployment (usually the running dev server) to expose. Omit to
322
- * leave the deployment tools out entirely.
323
- */
324
- deployment?: LocalDeploymentSource;
325
- /** Docs site origin backing the documentation tools; `false` omits them. */
326
- docs?: false | {
327
- baseUrl?: string;
328
- };
329
- /** Extra tools to compose in, e.g. the CLI's local dev-server tools. */
330
- extraTools?: ReadonlyArray<McpTool>;
331
- /** `fetch` implementation; defaults to the ambient global. */
332
- fetch?: typeof fetch;
333
- /** Version reported in the MCP handshake — the host CLI's, not this package's. */
334
- version?: string;
335
- }
336
- /** Server identity advertised in the MCP `initialize` handshake. */
337
- declare const LOCAL_SERVER_NAME = "lunora";
338
- /** Shown when a deployment tool is called and no dev server can be found. */
339
- declare const NO_DEPLOYMENT_MESSAGE = "no Lunora dev server is running for this project — start one with `lunora dev`, then call this tool again (call lunora_dev_status to check).";
340
- /**
341
- * Assemble the tool list, in the order it is advertised: docs first (the
342
- * surface that always works), then the caller's extras, then the error catalog
343
- * (compiled in, so it needs no deployment either), then the deployment tools.
344
- * Order also decides precedence — `createToolServer` keeps the first
345
- * registration of a duplicated name.
346
- *
347
- * `clientFor` is the shared client cache built once by
348
- * {@link createLocalMcpServer} and threaded into both the tool and resource
349
- * surfaces. Exported (and called directly by tests) without going through
350
- * `createLocalMcpServer`, so a caller that omits it gets a private,
351
- * call-scoped cache — same shape as before this surface was shared, just
352
- * without the cross-surface sharing that only matters once a resource
353
- * surface exists alongside it.
354
- */
355
- declare const localTools: (options: LocalMcpServerOptions, clientFor?: (deployment: LocalDeployment) => LunoraClient) => ReadonlyArray<McpTool>;
356
- /** Build the composed local server without connecting a transport. */
357
- declare const createLocalMcpServer: (options?: LocalMcpServerOptions) => Server;
358
- /**
359
- * Build the composed local server and connect it over stdio — the transport an
360
- * MCP client uses when it spawns `lunora mcp serve`. Resolves once connected;
361
- * the process then stays alive serving requests.
362
- */
363
- declare const connectLocalStdio: (options?: LocalMcpServerOptions) => Promise<Server>;
364
- /** A tool handler: receives the call's `arguments` bag, returns an MCP tool result. */
365
- /**
366
- * The x402 vocabulary this module needs, declared here rather than imported.
367
- *
368
- * The x402 package is an optional peer, and a type import from its `charge`
369
- * entry puts its `.d.ts` back into this package's build graph:
370
- * a consumer that never installs x402 never builds it either, so the dts bundler
371
- * looks for a `dist/` that does not exist and fails. That is not hypothetical —
372
- * it broke the docs site build, which runs a filtered build over the docs app and its dependency closure
373
- * and therefore never builds x402.
374
- *
375
- * Declaring them locally is safe because this module never *inspects* a charge
376
- * config; it forwards it whole to `createChargeMiddleware`. The index signature
377
- * keeps a real charge config assignable as x402 grows fields.
378
- */
379
- /** Mirrors x402's `X402Price` — a decimal string like `"$0.05"`, or a number. */
380
- type X402Price = number | string;
381
- /** Mirrors x402's charge config with the per-tool price omitted. */
382
- interface X402ChargeSettings {
383
- /** Network this resource settles on. */
384
- readonly network: string;
385
- /** Everything else x402 accepts, forwarded untouched. */
386
- readonly [key: string]: unknown;
387
- /** Payout wallet(s), per network family. */
388
- readonly recipient: {
389
- readonly evm?: string;
390
- readonly svm?: string;
391
- };
392
- }
393
- type ToolHandler = (arguments_: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
394
- /** Registration shape for a free tool. */
395
- interface RegisterToolOptions {
396
- /** Optional MCP tool annotations (`readOnlyHint`, `title`, …). */
397
- annotations?: Tool["annotations"];
398
- /** Human/model-facing description of what the tool does. */
399
- description: string;
400
- /** JSON-Schema object describing the tool's arguments. */
401
- inputSchema: ToolInputSchema;
402
- /** Unique tool name (the MCP `tools/call` `name`). */
403
- name: string;
404
- }
405
- /** Registration shape for a paid tool: a {@link RegisterToolOptions} plus its USD price. */
406
- interface RegisterPaidToolOptions extends RegisterToolOptions {
407
- /** USD price per call (e.g. `"$0.05"`), charged via x402 before dispatch. */
408
- price: X402Price;
409
- }
410
- /** x402 settlement vocabulary shared by every paid tool (network, recipient, facilitator); price is per-tool. */
411
- type PaidMcpChargeConfig = X402ChargeSettings;
412
- /** Config for `createPaidMcpServer`. */
413
- interface PaidMcpServerConfig {
414
- /** The worker-level x402 charge config; each paid tool supplies only its own `price`. */
415
- charge: PaidMcpChargeConfig;
416
- /**
417
- * Largest accepted request body, in bytes — enforced while the body streams
418
- * in, not after it is buffered. Defaults to `DEFAULT_MAX_REQUEST_BYTES`
419
- * (128 KiB), which a value that is not a non-negative safe integer also
420
- * falls back to.
421
- */
422
- maxRequestBytes?: number;
423
- /** Name/version advertised in the MCP `initialize` handshake. Defaults to `lunora-paid-mcp`. */
424
- serverInfo?: {
425
- name: string;
426
- version: string;
427
- };
428
- }
429
- /**
430
- * The Worker execution context, as this module reads it: only `waitUntil`, and
431
- * structurally, so the package takes no `@cloudflare/workers-types` dependency.
432
- */
433
- interface PaidMcpExecutionContext {
434
- waitUntil?: (promise: Promise<unknown>) => void;
435
- }
436
- /**
437
- * The paid server's fetch handler.
438
- *
439
- * Unlike the free `McpFetchHandler` it takes the Worker's full
440
- * `(request, env, ctx)` triple — the shape `export default { fetch }` is called
441
- * with — because the x402 receipt sink NEEDS `ctx.waitUntil`: work that is
442
- * neither awaited into the response nor registered with it is cancelled when the
443
- * request ends, so an async `onReceipt` (inserting the settled payment into a
444
- * durable table) frequently never runs while the money has already moved
445
- * on-chain. `env` is accepted and ignored so the handler drops straight into the
446
- * default export; both are optional, so a non-Workers caller may still invoke it
447
- * with a bare `Request` (the middleware then simply sees no `waitUntil`).
448
- */
449
- type PaidMcpFetchHandler = (request: Request, env?: unknown, context?: PaidMcpExecutionContext) => Promise<Response>;
450
- /** A paid MCP server: register free/paid tools, then serve over Streamable HTTP. */
451
- interface PaidMcpServer {
452
- /** The Streamable-HTTP fetch handler; gates each paid `tools/call` behind x402. */
453
- readonly fetchHandler: PaidMcpFetchHandler;
454
- /** Register a **paid** tool: its dispatch runs the x402 charge middleware first. */
455
- paidTool: (options: RegisterPaidToolOptions, handler: ToolHandler) => void;
456
- /** Register a **free** tool (coexists with paid tools on the same server). */
457
- tool: (options: RegisterToolOptions, handler: ToolHandler) => void;
458
- }
459
- /**
460
- * Create a paid MCP server. Register free tools with `tool()` and priced tools
461
- * with `paidTool()` (they coexist), then serve `fetchHandler` over HTTP.
462
- *
463
- * The server is **stateless**: `fetchHandler` builds a fresh `Server` per
464
- * request (reading the live tool registry), so tools registered before the
465
- * first request are all visible. Each priced tool memoises one initialised
466
- * `ChargeMiddleware` (keyed by tool name, baking that tool's price and naming
467
- * the tool as the challenge `resource`); a failed init is not cached, so a
468
- * transient facilitator outage retries on the next call.
469
- */
470
- declare const createPaidMcpServer: (config: PaidMcpServerConfig) => PaidMcpServer;
471
- export { AGENT_RUN_INPUT_SCHEMA, AGENT_STATUS_TOOL_NAME, type AuthedMcpFetchHandlerOptions, type AuthedMcpServerOptions,
1
+ export { A as AGENT_RUN_INPUT_SCHEMA, a as AGENT_STATUS_TOOL_NAME,
472
2
  /**
473
3
  * `@lunora/mcp` — Model Context Protocol servers for Lunora. This entry exposes
474
4
  * a *deployment* to AI agents; the `@lunora/mcp/docs` subpath exposes the
@@ -506,7 +36,7 @@ export { AGENT_RUN_INPUT_SCHEMA, AGENT_STATUS_TOOL_NAME, type AuthedMcpFetchHand
506
36
  * better-auth's MCP OAuth gate (`requireMcpAuth` from `@lunora/auth/plugins`)
507
37
  * and can scope tool exposure to the access token's own scopes.
508
38
  */
509
- type CallAgentToolOptions, LOCAL_SERVER_NAME, type LocalDeployment, type LocalDeploymentSource, type LocalMcpServerOptions, type LunoraMcpServerOptions, type McpAccessTokenClaims,
39
+ type C as CallAgentToolOptions, type L as LunoraMcpServerOptions,
510
40
  /**
511
41
  * `@lunora/mcp` — Model Context Protocol servers for Lunora. This entry exposes
512
42
  * a *deployment* to AI agents; the `@lunora/mcp/docs` subpath exposes the
@@ -544,4 +74,12 @@ type CallAgentToolOptions, LOCAL_SERVER_NAME, type LocalDeployment, type LocalDe
544
74
  * better-auth's MCP OAuth gate (`requireMcpAuth` from `@lunora/auth/plugins`)
545
75
  * and can scope tool exposure to the access token's own scopes.
546
76
  */
547
- type McpAgentExposure, type McpAuthProtect, type McpFetchHandler, type McpFetchHandlerOptions, type McpTool, NO_DEPLOYMENT_MESSAGE, OBSERVABILITY_TOOL_DEFINITIONS, type PaidMcpChargeConfig, type PaidMcpExecutionContext, type PaidMcpFetchHandler, type PaidMcpServer, type PaidMcpServerConfig, READ_ONLY_TOOL_DEFINITIONS, type RegisterPaidToolOptions, type RegisterToolOptions, type ToolDefinition, type ToolHandler, type ToolInputSchema, type ToolResult, WRITE_TOOL_DEFINITIONS, agentToolDefinitions, callAgentTool, callTool, connectLocalStdio, connectStdio, createAuthedMcpFetchHandler, createLocalMcpServer, createLunoraMcpServer, createMcpFetchHandler, createPaidMcpServer, localTools, mcpTokenScopes, parseAgentsEnv, toolDefinitions };
77
+ type M as McpAgentExposure, b as agentToolDefinitions, c as callAgentTool, d as createLunoraMcpServer, p as parseAgentsEnv } from "./packem_shared/server.d-D3rejkVc.mjs";
78
+ export { type AuthedMcpFetchHandlerOptions, type AuthedMcpServerOptions, type McpAccessTokenClaims, type McpAuthProtect, type McpFetchHandlerOptions, OBSERVABILITY_TOOL_DEFINITIONS, type PaidMcpChargeConfig, type PaidMcpExecutionContext, type PaidMcpFetchHandler, type PaidMcpServer, type PaidMcpServerConfig, READ_ONLY_TOOL_DEFINITIONS, type RegisterPaidToolOptions, type RegisterToolOptions, type ToolHandler, WRITE_TOOL_DEFINITIONS, callTool, createAuthedMcpFetchHandler, createMcpFetchHandler, createPaidMcpServer, mcpTokenScopes, toolDefinitions } from "./worker/index.mjs";
79
+ export { type M as McpServerInfo, type a as McpTool, type T as ToolDefinition, type b as ToolInputSchema, type c as ToolResult, d as createToolServer } from "./packem_shared/compose.d-BVnP3uAy.mjs";
80
+ export { LOCAL_SERVER_NAME, type LocalDeployment, type LocalDeploymentSource, type LocalMcpServerOptions, NO_DEPLOYMENT_MESSAGE, connectLocalStdio, connectStdio, createLocalMcpServer, localTools } from "./node/index.mjs";
81
+ export { D as DEFAULT_MAX_REQUEST_BYTES, type M as McpFetchHandler, type S as ServeStatelessOptions, s as serveStateless } from "./packem_shared/serve-stateless.d-DD5arqFx.mjs";
82
+ import '@lunora/client';
83
+ import '@modelcontextprotocol/sdk/server/index.js';
84
+ import '@modelcontextprotocol/sdk/types.js';
85
+ import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';