@lunora/mcp 1.0.0-alpha.1 → 1.0.0-alpha.100

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 (31) hide show
  1. package/LICENSE.md +126 -0
  2. package/README.md +139 -9
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/bin.mjs +3 -35
  5. package/dist/docs/index.d.mts +253 -0
  6. package/dist/docs/index.d.ts +253 -0
  7. package/dist/docs/index.mjs +1 -0
  8. package/dist/index.d.mts +434 -14
  9. package/dist/index.d.ts +434 -14
  10. package/dist/index.mjs +1 -2
  11. package/dist/packem_shared/AGENT_RUN_INPUT_SCHEMA-DRSY74ed.mjs +1 -0
  12. package/dist/packem_shared/DEFAULT_DOCS_BASE_URL-CZ3fVsSc.mjs +4 -0
  13. package/dist/packem_shared/DEFAULT_SEARCH_LIMIT-V7pCZ1wt.mjs +3 -0
  14. package/dist/packem_shared/DOCS_SERVER_NAME-BNYVF715.mjs +1 -0
  15. package/dist/packem_shared/DOCS_URI_SCHEME-CFANc3vr.mjs +3 -0
  16. package/dist/packem_shared/LOCAL_SERVER_NAME-CisKTqzv.mjs +1 -0
  17. package/dist/packem_shared/OBSERVABILITY_TOOL_DEFINITIONS-KrCukPbu.mjs +1 -0
  18. package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-DGexf3Tn.mjs +1 -0
  19. package/dist/packem_shared/connectStdio-BCeI0Wqu.mjs +1 -0
  20. package/dist/packem_shared/createAuthedMcpFetchHandler-BUoCjrxu.mjs +1 -0
  21. package/dist/packem_shared/createMcpFetchHandler-TKDnZTGs.mjs +1 -0
  22. package/dist/packem_shared/createPaidMcpServer-DyNwdCq2.mjs +1 -0
  23. package/dist/packem_shared/createToolServer-BtGuPyMU.mjs +1 -0
  24. package/dist/packem_shared/observability-tools-Ce0YK58T.mjs +1 -0
  25. package/dist/packem_shared/serve-stateless.d-B_q8q39X.d.mts +133 -0
  26. package/dist/packem_shared/serve-stateless.d-B_q8q39X.d.ts +133 -0
  27. package/dist/packem_shared/serveStateless-Db7J3pAO.mjs +1 -0
  28. package/dist/packem_shared/toDocsSearchHits-CBLmtWXt.mjs +1 -0
  29. package/package.json +18 -4
  30. package/dist/packem_shared/callTool-Dpiu38ji.mjs +0 -112
  31. package/dist/packem_shared/connectStdio-DBzX8tcZ.mjs +0 -64
package/LICENSE.md CHANGED
@@ -103,3 +103,129 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+
112
+ # Licenses of bundled types
113
+ The published @lunora/mcp artifact additionally contains code with the following licenses:
114
+ FSL-1.1-Apache-2.0
115
+
116
+ # Bundled types:
117
+ ## @lunora/x402
118
+ License: FSL-1.1-Apache-2.0
119
+ By: Daniel Bannert
120
+ Repository: git+https://github.com/anolilab/lunora.git
121
+
122
+ > # Functional Source License, Version 1.1, Apache 2.0 Future License
123
+ >
124
+ > ## Abbreviation
125
+ >
126
+ > FSL-1.1-Apache-2.0
127
+ >
128
+ > ## Notice
129
+ >
130
+ > Copyright 2026 anolilab and contributors
131
+ >
132
+ > ## Terms and Conditions
133
+ >
134
+ > ### Licensor ("We")
135
+ >
136
+ > The party offering the Software under these Terms and Conditions.
137
+ >
138
+ > ### The Software
139
+ >
140
+ > The "Software" is each version of the software that we make available under
141
+ > these Terms and Conditions, as indicated by our inclusion of these Terms and
142
+ > Conditions with the Software.
143
+ >
144
+ > ### License Grant
145
+ >
146
+ > Subject to your compliance with this License Grant and the Patents,
147
+ > Redistribution and Trademark clauses below, we hereby grant you the right to
148
+ > use, copy, modify, create derivative works, publicly perform, publicly display
149
+ > and redistribute the Software for any Permitted Purpose identified below.
150
+ >
151
+ > ### Permitted Purpose
152
+ >
153
+ > A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
154
+ > means making the Software available to others in a commercial product or service
155
+ > that:
156
+ >
157
+ > 1. substitutes for the Software;
158
+ >
159
+ > 2. substitutes for any other product or service we offer using the Software that
160
+ > exists as of the date we make the Software available; or
161
+ >
162
+ > 3. offers the same or substantially similar functionality as the Software.
163
+ >
164
+ > Permitted Purposes specifically include using the Software:
165
+ >
166
+ > 1. for your internal use and access;
167
+ >
168
+ > 2. for non-commercial education;
169
+ >
170
+ > 3. for non-commercial research; and
171
+ >
172
+ > 4. in connection with professional services that you provide to a licensee using
173
+ > the Software in accordance with these Terms and Conditions.
174
+ >
175
+ > ### Patents
176
+ >
177
+ > To the extent your use for a Permitted Purpose would necessarily infringe our
178
+ > patents, the license grant above includes a license under our patents. If you
179
+ > make a claim against any party that the Software infringes or contributes to the
180
+ > infringement of any patent, then your patent license to the Software ends
181
+ > immediately.
182
+ >
183
+ > ### Redistribution
184
+ >
185
+ > The Terms and Conditions apply to all copies, modifications and derivatives of
186
+ > the Software.
187
+ >
188
+ > If you redistribute any copies, modifications or derivatives of the Software,
189
+ > you must include a copy of or a link to these Terms and Conditions and not
190
+ > remove any copyright notices provided in or with the Software.
191
+ >
192
+ > ### Disclaimer
193
+ >
194
+ > THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
195
+ > IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
196
+ > PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
197
+ >
198
+ > IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
199
+ > SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
200
+ > IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
201
+ >
202
+ > ### Trademarks
203
+ >
204
+ > Except for displaying the License Details and identifying us as the origin of
205
+ > the Software, you have no right under these Terms and Conditions to use our
206
+ > trademarks, trade names, service marks or product names.
207
+ >
208
+ > ## Grant of Future License
209
+ >
210
+ > We hereby irrevocably grant you an additional license to use the Software under
211
+ > the Apache License, Version 2.0 that is effective on the second anniversary of
212
+ > the date we make the Software available. On or after that date, you may use the
213
+ > Software under the Apache License, Version 2.0, in which case the following will
214
+ > apply:
215
+ >
216
+ > Licensed under the Apache License, Version 2.0 (the "License"); you may not use
217
+ > this file except in compliance with the License.
218
+ >
219
+ > You may obtain a copy of the License at
220
+ >
221
+ > http://www.apache.org/licenses/LICENSE-2.0
222
+ >
223
+ > Unless required by applicable law or agreed to in writing, software distributed
224
+ > under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
225
+ > CONDITIONS OF ANY KIND, either express or implied. See the License for the
226
+ > specific language governing permissions and limitations under the License.
227
+ >
228
+ > <!-- DEPENDENCIES -->
229
+ > <!-- /DEPENDENCIES -->
230
+
231
+ <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -34,20 +34,32 @@
34
34
 
35
35
  ---
36
36
 
37
- A [Model Context Protocol](https://modelcontextprotocol.io) server that exposes a deployed Lunora app to AI agents. It registers tools for introspecting a deployment (`lunora_list_functions`, `lunora_list_tables`, `lunora_get_function_schema`) and invoking its functions (`lunora_run_query`, `lunora_run_mutation`, `lunora_run_action`), each backed by `@lunora/client` over HTTP RPC.
37
+ [Model Context Protocol](https://modelcontextprotocol.io) servers for Lunora, in two flavours:
38
+
39
+ - **Deployment** (the main entry) — exposes a deployed Lunora app to AI agents: introspection tools (`lunora_list_functions`, `lunora_list_tables`, `lunora_get_function_schema`) and invocation tools (`lunora_run_query`, `lunora_run_mutation`, `lunora_run_action`), each backed by `@lunora/client` over HTTP RPC. Needs an admin token.
40
+ - **Documentation** ([`@lunora/mcp/docs`](#documentation-server)) — exposes the framework's _docs_ so an agent writing Lunora code can look up the real API instead of guessing. Credential-free, and safe to host publicly; Lunora runs it at `https://lunora.sh/mcp`.
41
+
42
+ Most users never install this package directly — `lunora mcp install` wires both servers into their editor. See [`@lunora/cli`](https://www.npmjs.com/package/@lunora/cli).
38
43
 
39
44
  Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-safe, real-time backend on Cloudflare Workers + Durable Objects with a Vite-first DX.
40
45
 
41
46
  ## Tools
42
47
 
43
- | Tool | Description |
44
- | ---------------------------- | -------------------------------------------------------------------------------------------------------------- |
45
- | `lunora_list_functions` | List the deployment's public functions (queries, mutations, actions) with their kinds. |
46
- | `lunora_list_tables` | List the deployment's `.global()` tables with their row counts. |
47
- | `lunora_get_function_schema` | Return a function's argument descriptors and kind by path, so a caller can construct a valid arguments object. |
48
- | `lunora_run_query` | Run a query and return its result. Read-only. |
49
- | `lunora_run_mutation` | Run a mutation and return its result. Writes data — use with care. |
50
- | `lunora_run_action` | Run an action and return its result. May call external services. |
48
+ | Tool | Description |
49
+ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
+ | `lunora_list_functions` | List the deployment's public functions (queries, mutations, actions) with their kinds. |
51
+ | `lunora_list_tables` | List the deployment's `.global()` tables with their row counts. |
52
+ | `lunora_get_function_schema` | Return a function's argument descriptors and kind by path, so a caller can construct a valid arguments object. |
53
+ | `lunora_run_query` | Run a query and return its result. Read-only. |
54
+ | `lunora_run_mutation` | Run a mutation and return its result. Writes data — use with care. |
55
+ | `lunora_run_action` | Run an action and return its result. May call external services. |
56
+ | `lunora_get_logs` | Read the deployment's recent log entries (newest first). Requires an admin token. |
57
+ | `lunora_get_issues` | List errors grouped into Issues by fingerprint, with counts and triage status. Requires an admin token. |
58
+ | `lunora_get_advisories` | List the deployment's schema/query advisories. Requires an admin token. |
59
+ | `lunora_get_query_insights` | Per-statement execution counts and latency over a recent window. Requires an admin token. |
60
+ | `lunora_get_migration_status` | Which migrations are applied and which are pending. Requires an admin token. |
61
+ | `agent_<name>` | Start a durable [`@lunora/agent`](https://www.npmjs.com/package/@lunora/agent) run and await its answer. One tool per exposed agent. Requires agents enabled. |
62
+ | `lunora_agent_status` | Poll a running agent by `threadKey` and return its answer once finished. Requires agents enabled. |
51
63
 
52
64
  ### Recommended agent flow
53
65
 
@@ -58,6 +70,25 @@ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-sa
58
70
  → call the function with a well-formed arguments object
59
71
  ```
60
72
 
73
+ ### Observability tools (privileged)
74
+
75
+ The five `lunora_get_*` observability tools are read-only, but they surface the
76
+ deployment's **operational data** — log lines, request metadata, and grouped
77
+ error messages, all of which may contain user data, and all of which land in the
78
+ model's context (and therefore at its provider). They are exposed **only when an
79
+ admin token resolved**: without one they are omitted from `ListTools` entirely
80
+ and refused at dispatch, the same omit-don't-refuse rule the write tools use.
81
+ They are independent of `--allow-writes`, which is about changing data, not
82
+ reading operational data.
83
+
84
+ They return `structuredContent` alongside the usual text block, described by each
85
+ tool's `outputSchema` (MCP revision `2025-06-18` and later; older clients keep
86
+ reading the text block). All but `lunora_get_migration_status` take a `limit`
87
+ clamped server-side; migration status takes only `shardKey` and returns every
88
+ migration, because truncating that list would hide the pending one. Each also
89
+ takes an optional `shardKey` — on a `.shardBy()`-partitioned deployment these
90
+ reads are **per-shard**, not deployment-wide.
91
+
61
92
  `lunora_get_function_schema` returns a JSON object with three fields:
62
93
 
63
94
  - `path` — the function path (e.g. `"messages:send"`)
@@ -70,6 +101,8 @@ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-sa
70
101
  npm install @lunora/mcp
71
102
  ```
72
103
 
104
+ Paid MCP tools (`createPaidMcpServer`) additionally need the optional peer [`@lunora/x402`](https://www.npmjs.com/package/@lunora/x402); it is loaded lazily, so installs that never charge for a tool don't pay for its dependency tree.
105
+
73
106
  ```sh
74
107
  yarn add @lunora/mcp
75
108
  ```
@@ -105,6 +138,102 @@ const server = createLunoraMcpServer({ url: "https://app.example.workers.dev", t
105
138
  await server.connect(myTransport);
106
139
  ```
107
140
 
141
+ ## Expose an agent
142
+
143
+ A deployment's durable [`@lunora/agent`](https://www.npmjs.com/package/@lunora/agent) agents can be fronted as MCP tools. This is **opt-in and fail-closed**, mirroring `allowWrites`: starting an agent run is a side effect, so the agent tools are omitted from the advertised list _and_ refused at dispatch unless you explicitly enable them. `@lunora/mcp` takes no dependency on `@lunora/agent` — it reaches the agent's public `agents:agentRun` mutation over RPC like any other function.
144
+
145
+ Enable it with two env vars (or the matching `createLunoraMcpServer` options):
146
+
147
+ - `LUNORA_MCP_ALLOW_AGENTS` — set to `1`/`true`/`yes`/`on` to expose the agent tools. Default: agents disabled.
148
+ - `LUNORA_MCP_AGENTS` — a `;`-separated list of `name:description` pairs selecting which agents to expose, e.g. `"support:Support questions;billing:Billing help"`.
149
+ - `LUNORA_MCP_AGENT_TIMEOUT_MS` (optional) — wall-clock budget a single `agent_<name>` call awaits before returning a pending result to poll.
150
+
151
+ ```jsonc
152
+ {
153
+ "mcpServers": {
154
+ "lunora": {
155
+ "command": "lunora-mcp",
156
+ "env": {
157
+ "LUNORA_URL": "https://app.example.workers.dev",
158
+ "LUNORA_ADMIN_TOKEN": "...",
159
+ "LUNORA_MCP_ALLOW_AGENTS": "1",
160
+ "LUNORA_MCP_AGENTS": "support:Support questions;billing:Billing help",
161
+ },
162
+ },
163
+ },
164
+ }
165
+ ```
166
+
167
+ Each exposed agent gets an `agent_<name>` tool taking `prompt` (required), an optional `threadKey` (reuse to continue a conversation; omit to start a new thread), and an optional `title`. The tool starts a durable run and awaits it up to the timeout budget; if the run outlasts the budget it returns a pending result whose `threadKey` you feed to the generic `lunora_agent_status` tool to poll for the final answer.
168
+
169
+ Runs are **owner-scoped** to the identity the configured token resolves to. Grant a **least-privilege** token mapped to a bot identity so an agent's threads stay isolated per deployment — never the admin token.
170
+
171
+ ## Resources and annotations
172
+
173
+ Both servers implement MCP **tools**; the documentation server additionally exposes every page as an MCP **resource** (`lunora-docs:/docs/…`, `text/markdown`), so a client can enumerate and attach a page directly instead of the model having to guess a search query first.
174
+
175
+ Every tool carries **annotations** — `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint` and a human-facing `title` — so a client can badge the read-only surface and confirm before a write. They are hints; the actual guarantee is still made at dispatch, where a write tool is refused unless writes are enabled.
176
+
177
+ ## Documentation server
178
+
179
+ `@lunora/mcp/docs` is a second, independent surface: it serves **published documentation**, not a deployment. No credentials, no writes, no `@lunora/client` — and no Node built-ins, so it runs unchanged on Workers, Netlify/Vercel functions, Deno, and Bun.
180
+
181
+ | Tool | Description |
182
+ | -------------------- | --------------------------------------------------------------------- |
183
+ | `lunora_search_docs` | Search the docs; returns matching pages and sections with their URLs. |
184
+ | `lunora_get_doc` | Return one page in full, as Markdown. |
185
+ | `lunora_list_docs` | List every page with its title and description. |
186
+
187
+ The tools read a `DocsIndex`, which has two implementations. A docs site wires up its own in-process index and mounts the server as an HTTP route:
188
+
189
+ ```ts
190
+ import { createDocsMcpFetchHandler } from "@lunora/mcp/docs";
191
+
192
+ const handle = createDocsMcpFetchHandler({ index: myDocsIndex });
193
+
194
+ // e.g. in a Worker: export default { fetch: handle }
195
+ ```
196
+
197
+ Anything else reads a published site over HTTP:
198
+
199
+ ```ts
200
+ import { createDocsMcpServer, createRemoteDocsIndex } from "@lunora/mcp/docs";
201
+
202
+ const server = createDocsMcpServer({ index: createRemoteDocsIndex({ baseUrl: "https://lunora.sh" }) });
203
+ ```
204
+
205
+ Point a client at the hosted endpoint with no install at all:
206
+
207
+ ```sh
208
+ claude mcp add --transport http lunora-docs https://lunora.sh/mcp
209
+ ```
210
+
211
+ ### Hosting it safely
212
+
213
+ `createDocsMcpFetchHandler` screens each request before the transport sees it, because this surface is meant to be public and unauthenticated:
214
+
215
+ - **Bodies are capped** (128 KiB by default; override with `maxRequestBytes`).
216
+ - **JSON-RPC batches are refused.** The stateless transport buffers a whole batch's replies into one response, so a single small request carrying thousands of `tools/call` messages would amplify into hundreds of megabytes out, with no session to rate-limit against. A docs client gains nothing from batching.
217
+ - `lunora_search_docs` bounds its `query`, and `lunora_list_docs` caps how many pages it serialises.
218
+
219
+ ## Local development server
220
+
221
+ `createLocalMcpServer` / `connectLocalStdio` compose the docs tools, the deployment tools, and any extra tools a host supplies into one stdio server — this is what `lunora mcp serve` runs.
222
+
223
+ ```ts
224
+ import { connectLocalStdio } from "@lunora/mcp";
225
+
226
+ await connectLocalStdio({
227
+ // Consulted per tool call, so a dev server started later is picked up
228
+ // without reconnecting.
229
+ deployment: () => readMyDevServer(),
230
+ docs: { baseUrl: "https://lunora.sh" },
231
+ extraTools: myLocalTools,
232
+ });
233
+ ```
234
+
235
+ The deployment tools are advertised even when the resolver currently returns nothing — MCP clients cache the tool list, so a surface that appeared only when the dev server happened to be up would stay invisible for the rest of the session. Calling one with nothing running returns an actionable error instead.
236
+
108
237
  > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs)**.
109
238
 
110
239
  ## Related
@@ -112,6 +241,7 @@ await server.connect(myTransport);
112
241
  - [`@lunora/client`](https://www.npmjs.com/package/@lunora/client) — the HTTP RPC client backing every tool.
113
242
  - [`@lunora/cli`](https://www.npmjs.com/package/@lunora/cli) — deploy the app the server introspects and invokes.
114
243
  - [`@lunora/server`](https://www.npmjs.com/package/@lunora/server) — defines the queries, mutations, and actions the tools call.
244
+ - [`@lunora/agent`](https://www.npmjs.com/package/@lunora/agent) — the durable agents the `agent_<name>` tools front over RPC.
115
245
 
116
246
  ## Supported Node.js Versions
117
247