@lunora/mcp 1.0.0-alpha.4 → 1.0.0-alpha.41
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.md +6 -0
- package/README.md +41 -8
- package/dist/bin.mjs +3 -35
- package/dist/index.d.mts +215 -11
- package/dist/index.d.ts +215 -11
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/AGENT_RUN_INPUT_SCHEMA-ihZg6vIZ.mjs +1 -0
- package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-J_O1zHbG.mjs +1 -0
- package/dist/packem_shared/connectStdio-Dtos_i1h.mjs +1 -0
- package/dist/packem_shared/createMcpFetchHandler-CHssdLE-.mjs +1 -0
- package/dist/packem_shared/createPaidMcpServer-CQP3p1-0.mjs +1 -0
- package/package.json +4 -2
- package/dist/packem_shared/TOOL_DEFINITIONS-Dpiu38ji.mjs +0 -112
- package/dist/packem_shared/connectStdio-C_mvQBs2.mjs +0 -64
package/LICENSE.md
CHANGED
|
@@ -103,3 +103,9 @@ 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
|
+
<!-- /TYPE_DEPENDENCIES -->
|
package/README.md
CHANGED
|
@@ -40,14 +40,16 @@ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-sa
|
|
|
40
40
|
|
|
41
41
|
## Tools
|
|
42
42
|
|
|
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.
|
|
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. |
|
|
51
|
+
| `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. |
|
|
52
|
+
| `lunora_agent_status` | Poll a running agent by `threadKey` and return its answer once finished. Requires agents enabled. |
|
|
51
53
|
|
|
52
54
|
### Recommended agent flow
|
|
53
55
|
|
|
@@ -105,6 +107,36 @@ const server = createLunoraMcpServer({ url: "https://app.example.workers.dev", t
|
|
|
105
107
|
await server.connect(myTransport);
|
|
106
108
|
```
|
|
107
109
|
|
|
110
|
+
## Expose an agent
|
|
111
|
+
|
|
112
|
+
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.
|
|
113
|
+
|
|
114
|
+
Enable it with two env vars (or the matching `createLunoraMcpServer` options):
|
|
115
|
+
|
|
116
|
+
- `LUNORA_MCP_ALLOW_AGENTS` — set to `1`/`true`/`yes`/`on` to expose the agent tools. Default: agents disabled.
|
|
117
|
+
- `LUNORA_MCP_AGENTS` — a `;`-separated list of `name:description` pairs selecting which agents to expose, e.g. `"support:Support questions;billing:Billing help"`.
|
|
118
|
+
- `LUNORA_MCP_AGENT_TIMEOUT_MS` (optional) — wall-clock budget a single `agent_<name>` call awaits before returning a pending result to poll.
|
|
119
|
+
|
|
120
|
+
```jsonc
|
|
121
|
+
{
|
|
122
|
+
"mcpServers": {
|
|
123
|
+
"lunora": {
|
|
124
|
+
"command": "lunora-mcp",
|
|
125
|
+
"env": {
|
|
126
|
+
"LUNORA_URL": "https://app.example.workers.dev",
|
|
127
|
+
"LUNORA_ADMIN_TOKEN": "...",
|
|
128
|
+
"LUNORA_MCP_ALLOW_AGENTS": "1",
|
|
129
|
+
"LUNORA_MCP_AGENTS": "support:Support questions;billing:Billing help",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
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.
|
|
137
|
+
|
|
138
|
+
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.
|
|
139
|
+
|
|
108
140
|
> This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs)**.
|
|
109
141
|
|
|
110
142
|
## Related
|
|
@@ -112,6 +144,7 @@ await server.connect(myTransport);
|
|
|
112
144
|
- [`@lunora/client`](https://www.npmjs.com/package/@lunora/client) — the HTTP RPC client backing every tool.
|
|
113
145
|
- [`@lunora/cli`](https://www.npmjs.com/package/@lunora/cli) — deploy the app the server introspects and invokes.
|
|
114
146
|
- [`@lunora/server`](https://www.npmjs.com/package/@lunora/server) — defines the queries, mutations, and actions the tools call.
|
|
147
|
+
- [`@lunora/agent`](https://www.npmjs.com/package/@lunora/agent) — the durable agents the `agent_<name>` tools front over RPC.
|
|
115
148
|
|
|
116
149
|
## Supported Node.js Versions
|
|
117
150
|
|
package/dist/bin.mjs
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
code;
|
|
6
|
-
constructor(message, code) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "BinError";
|
|
9
|
-
this.code = code;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
const runBin = async (environment, dependencies = {}) => {
|
|
13
|
-
const connect = dependencies.connect ?? connectStdio;
|
|
14
|
-
const writeError = dependencies.writeError ?? ((message) => {
|
|
15
|
-
process.stderr.write(message);
|
|
16
|
-
});
|
|
17
|
-
const url = environment.LUNORA_URL;
|
|
18
|
-
if (url === void 0 || url.length === 0) {
|
|
19
|
-
writeError("lunora-mcp: LUNORA_URL environment variable is required\n");
|
|
20
|
-
throw new BinError("LUNORA_URL environment variable is required", 1);
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
await connect({ token: environment.LUNORA_ADMIN_TOKEN, url });
|
|
24
|
-
} catch (error) {
|
|
25
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
-
writeError(`lunora-mcp: failed to start — ${message}
|
|
27
|
-
`);
|
|
28
|
-
throw new BinError(`failed to start — ${message}`, 1);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
await runBin(process.env);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
process.exit(error instanceof BinError ? error.code : 1);
|
|
36
|
-
}
|
|
2
|
+
import{parseAgentsEnv as A}from"./packem_shared/AGENT_RUN_INPUT_SCHEMA-ihZg6vIZ.mjs";import{connectStdio as N}from"./packem_shared/connectStdio-Dtos_i1h.mjs";const d=new Set(["1","on","true","yes"]),L=r=>r!==void 0&&d.has(r.trim().toLowerCase());class a extends Error{code;constructor(e,o){super(e),this.name="BinError",this.code=o}}const l=async(r,e={})=>{const o=e.connect??N,n=e.writeError??(t=>{process.stderr.write(t)}),s=r.LUNORA_URL;if(s===void 0||s.length===0)throw n(`lunora-mcp: LUNORA_URL environment variable is required
|
|
3
|
+
`),new a("LUNORA_URL environment variable is required",1);const i=Number(r.LUNORA_MCP_AGENT_TIMEOUT_MS),c=Number.isFinite(i)&&i>0?i:void 0;try{await o({agents:A(r.LUNORA_MCP_AGENTS),allowAgents:L(r.LUNORA_MCP_ALLOW_AGENTS),allowWrites:L(r.LUNORA_MCP_ALLOW_WRITES),token:r.LUNORA_ADMIN_TOKEN,url:s,...c===void 0?{}:{agentMaxWaitMs:c}})}catch(t){const _=t instanceof Error?t.message:String(t);throw n(`lunora-mcp: failed to start — ${_}
|
|
4
|
+
`),new a(`failed to start — ${_}`,1)}};try{await l(process.env)}catch(r){process.exit(r instanceof a?r.code:1)}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { LunoraClient } from '@lunora/client';
|
|
2
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
4
|
+
import { X402ChargeConfig, X402Price } from '@lunora/x402/charge';
|
|
5
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The tool surface this MCP server exposes. Each tool maps onto a method the
|
|
8
|
+
* `LunoraClient` already provides, so an AI agent can introspect a deployment
|
|
9
|
+
* (functions, global tables) and invoke its functions over HTTP RPC.
|
|
10
|
+
*
|
|
11
|
+
* Definitions and dispatch live here — separate from the server wiring — so the
|
|
12
|
+
* behaviour is unit-testable against a mock client without driving a transport.
|
|
13
|
+
*/
|
|
14
|
+
/** A JSON-Schema object describing a tool's arguments, per the MCP spec. */
|
|
11
15
|
interface ToolInputSchema {
|
|
12
16
|
properties: Record<string, unknown>;
|
|
13
17
|
required?: ReadonlyArray<string>;
|
|
@@ -18,6 +22,7 @@ interface ToolDefinition {
|
|
|
18
22
|
inputSchema: ToolInputSchema;
|
|
19
23
|
name: string;
|
|
20
24
|
}
|
|
25
|
+
/** The MCP `CallToolResult` shape this server returns. */
|
|
21
26
|
interface ToolResult {
|
|
22
27
|
content: {
|
|
23
28
|
text: string;
|
|
@@ -25,6 +30,205 @@ interface ToolResult {
|
|
|
25
30
|
}[];
|
|
26
31
|
isError?: boolean;
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
declare const
|
|
30
|
-
|
|
33
|
+
/** The read-only tool surface: introspection + query. Always exposed. */
|
|
34
|
+
declare const READ_ONLY_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
|
|
35
|
+
/** The write tool surface (mutations + actions). Exposed ONLY when writes are enabled. */
|
|
36
|
+
declare const WRITE_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
|
|
37
|
+
/**
|
|
38
|
+
* The tools this server advertises. When `allowWrites` is false (the default),
|
|
39
|
+
* only the read-only surface is exposed — the mutation/action tools are omitted
|
|
40
|
+
* from `ListTools` entirely, so an AI agent can't invoke a write it can't see.
|
|
41
|
+
*/
|
|
42
|
+
declare const toolDefinitions: (allowWrites: boolean) => ReadonlyArray<ToolDefinition>;
|
|
43
|
+
/**
|
|
44
|
+
* Dispatch a tool call against `client`. Unknown tools and thrown errors are
|
|
45
|
+
* returned as `isError` results (rather than rejections) so the calling model
|
|
46
|
+
* sees the failure as tool output, per the MCP convention.
|
|
47
|
+
*
|
|
48
|
+
* `allowWrites` gates the mutation/action tools: when false (the default) a call
|
|
49
|
+
* to a write tool is refused even if the client somehow names it, so the
|
|
50
|
+
* read-only guarantee holds at dispatch, not just in the advertised tool list.
|
|
51
|
+
*/
|
|
52
|
+
declare const callTool: (client: LunoraClient, name: string, input: Record<string, unknown>, allowWrites?: boolean) => Promise<ToolResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Agent exposure for the MCP server: a durable `@lunora/agent` run fronted as an
|
|
55
|
+
* MCP tool an external agent can call. The capability boundary is the MCP-server
|
|
56
|
+
* process + its token, so WHICH agents are exposed is config on the server (like
|
|
57
|
+
* `allowWrites`), not on `defineAgent` — keeping `@lunora/agent` codegen
|
|
58
|
+
* byte-identical.
|
|
59
|
+
*/
|
|
60
|
+
interface McpAgentExposure {
|
|
61
|
+
/** What the agent does — shown to the calling model, which decides from it. */
|
|
62
|
+
description: string;
|
|
63
|
+
/** The agent's export name (its `ctx.agents.<name>` / `AGENT_<NAME>` binding). */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Override the model-facing tool name (default `agent_<name>`). */
|
|
66
|
+
toolName?: string;
|
|
67
|
+
}
|
|
68
|
+
/** The generic status/poll tool advertised alongside the per-agent tools. */
|
|
69
|
+
declare const AGENT_STATUS_TOOL_NAME = "lunora_agent_status";
|
|
70
|
+
/**
|
|
71
|
+
* The uniform input schema every agent tool advertises. Agents share ONE run
|
|
72
|
+
* input (`@lunora/agent` has no per-agent validator), so there is nothing to
|
|
73
|
+
* derive per agent — a single static schema is reused for every agent tool.
|
|
74
|
+
*/
|
|
75
|
+
declare const AGENT_RUN_INPUT_SCHEMA: ToolInputSchema;
|
|
76
|
+
/**
|
|
77
|
+
* Parse `LUNORA_MCP_AGENTS` — a `;`-separated list of `name:description` pairs,
|
|
78
|
+
* e.g. `"support:Handles support questions;billing:Billing help"`. The
|
|
79
|
+
* description may itself contain colons (only the FIRST colon splits). Blank
|
|
80
|
+
* entries and entries with an empty name/description are skipped.
|
|
81
|
+
*/
|
|
82
|
+
declare const parseAgentsEnv: (raw: string | undefined) => McpAgentExposure[];
|
|
83
|
+
/**
|
|
84
|
+
* The tools this module advertises. Fail-closed: only the boolean `true` opts
|
|
85
|
+
* in (an env-plumbed caller could pass a truthy string), and the tools appear
|
|
86
|
+
* ONLY when at least one agent is exposed — so an agent-free or non-opted-in
|
|
87
|
+
* server never lists them.
|
|
88
|
+
*/
|
|
89
|
+
declare const agentToolDefinitions: (exposures: ReadonlyArray<McpAgentExposure>, allowAgents: boolean) => ReadonlyArray<ToolDefinition>;
|
|
90
|
+
/** Options threaded into a single agent tool dispatch. */
|
|
91
|
+
interface CallAgentToolOptions {
|
|
92
|
+
/** Opt-in gate — must be exactly `true` or the call is refused fail-closed. */
|
|
93
|
+
allowAgents: boolean;
|
|
94
|
+
/** The exposures advertised by this server. */
|
|
95
|
+
exposures: ReadonlyArray<McpAgentExposure>;
|
|
96
|
+
/** Wall-clock budget a single call awaits before returning a pending result. */
|
|
97
|
+
maxWaitMs?: number;
|
|
98
|
+
/** Delay between thread-status polls. */
|
|
99
|
+
pollIntervalMs?: number;
|
|
100
|
+
/** Test seam replacing the between-poll wait; production uses a real timer. */
|
|
101
|
+
wait?: (ms: number) => Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Dispatch an agent tool call: start a durable run via `agents:agentRun`, then
|
|
105
|
+
* await-with-timeout — poll `agents:agentThread` until terminal (returning the
|
|
106
|
+
* final answer from `agents:agentMessages`) or, on budget exhaustion, return a
|
|
107
|
+
* NON-error pending payload the caller resumes with `lunora_agent_status`.
|
|
108
|
+
*
|
|
109
|
+
* Fail-closed: refused at dispatch unless `allowAgents === true`, mirroring the
|
|
110
|
+
* `allowWrites` guard — starting a run is a side effect and must not ride the
|
|
111
|
+
* read-only default.
|
|
112
|
+
*/
|
|
113
|
+
declare const callAgentTool: (client: LunoraClient, name: string, input: Record<string, unknown>, options: CallAgentToolOptions) => Promise<ToolResult>;
|
|
114
|
+
interface LunoraMcpServerOptions {
|
|
115
|
+
/** Wall-clock budget a single agent tool call awaits before returning a pending result. */
|
|
116
|
+
agentMaxWaitMs?: number;
|
|
117
|
+
/** Delay between agent thread-status polls. */
|
|
118
|
+
agentPollIntervalMs?: number;
|
|
119
|
+
/** The agents this server fronts as MCP tools (see `allowAgents`). */
|
|
120
|
+
agents?: ReadonlyArray<McpAgentExposure>;
|
|
121
|
+
/**
|
|
122
|
+
* Expose the per-agent tools (`agent_<name>` + the generic
|
|
123
|
+
* `lunora_agent_status`). Defaults to `false`, mirroring `allowWrites`:
|
|
124
|
+
* starting a durable agent run is a side effect, so the agent tools are
|
|
125
|
+
* omitted from the advertised list AND refused at dispatch unless explicitly
|
|
126
|
+
* opted in. Only takes effect together with a non-empty `agents` list.
|
|
127
|
+
*/
|
|
128
|
+
allowAgents?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Expose the write tools (`lunora_run_mutation` / `lunora_run_action`).
|
|
131
|
+
* Defaults to `false`: the server is READ-ONLY unless explicitly opted in,
|
|
132
|
+
* so a prompt-injected or misaligned agent can't mutate the deployment with
|
|
133
|
+
* the configured token. When false the write tools are omitted from the
|
|
134
|
+
* advertised tool list AND refused at dispatch.
|
|
135
|
+
*/
|
|
136
|
+
allowWrites?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Pre-built client (test injection). When omitted a `LunoraClient` is
|
|
139
|
+
* created from `url`/`token`/`fetch`.
|
|
140
|
+
*/
|
|
141
|
+
client?: LunoraClient;
|
|
142
|
+
/** `fetch` implementation; defaults to the ambient global. */
|
|
143
|
+
fetch?: typeof fetch;
|
|
144
|
+
/**
|
|
145
|
+
* Bearer token sent on every RPC. This must be the deployment's **admin
|
|
146
|
+
* bearer**: the introspection/allowlist path every tool depends on
|
|
147
|
+
* (`lunora_list_functions`, `lunora_list_tables`, and the `assertRunnable`
|
|
148
|
+
* precheck that runs before every `run` tool) hits admin-gated
|
|
149
|
+
* `/_lunora/admin/*` routes, so no scoped/app token works today — it would
|
|
150
|
+
* 403 (`ADMIN_FORBIDDEN`) on the first tool call. The read-only guarantee is
|
|
151
|
+
* therefore NOT enforced by the token's scope; it is enforced in-process via
|
|
152
|
+
* `allowWrites: false` (the default), which omits the write tools from the
|
|
153
|
+
* advertised list and refuses them at dispatch.
|
|
154
|
+
*/
|
|
155
|
+
token?: string;
|
|
156
|
+
/** Base URL of the deployed Lunora Worker. Required unless `client` is given. */
|
|
157
|
+
url?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Build an MCP `Server` whose tools talk to a Lunora deployment. The server is
|
|
161
|
+
* transport-agnostic — call `.connect(transport)` yourself, or use
|
|
162
|
+
* `connectStdio` for the common stdio case.
|
|
163
|
+
*
|
|
164
|
+
* Tool calls are dispatched through `callTool`, which the deployment reaches
|
|
165
|
+
* over HTTP RPC. No WebSocket is opened (the tools never subscribe), so this is
|
|
166
|
+
* safe to run as a short-lived stdio process.
|
|
167
|
+
*/
|
|
168
|
+
declare const createLunoraMcpServer: (options: LunoraMcpServerOptions) => Server;
|
|
169
|
+
/**
|
|
170
|
+
* Build the server and connect it over stdio — the transport MCP clients use
|
|
171
|
+
* when they spawn the `lunora-mcp` binary. Resolves once the transport is
|
|
172
|
+
* connected; the process then stays alive serving requests.
|
|
173
|
+
*/
|
|
174
|
+
declare const connectStdio: (options: LunoraMcpServerOptions) => Promise<Server>;
|
|
175
|
+
/** A Web-Standard fetch handler: takes a `Request`, returns the MCP `Response`. */
|
|
176
|
+
type McpFetchHandler = (request: Request) => Promise<Response>;
|
|
177
|
+
/**
|
|
178
|
+
* Build a stateless Streamable-HTTP fetch handler for a Lunora MCP server. Each
|
|
179
|
+
* invocation constructs a fresh proxy server and serves the request through
|
|
180
|
+
* {@link serveStateless}.
|
|
181
|
+
*/
|
|
182
|
+
declare const createMcpFetchHandler: (options: LunoraMcpServerOptions) => McpFetchHandler;
|
|
183
|
+
/** A tool handler: receives the call's `arguments` bag, returns an MCP tool result. */
|
|
184
|
+
type ToolHandler = (arguments_: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
|
|
185
|
+
/** Registration shape for a free tool. */
|
|
186
|
+
interface RegisterToolOptions {
|
|
187
|
+
/** Optional MCP tool annotations (`readOnlyHint`, `title`, …). */
|
|
188
|
+
annotations?: Tool["annotations"];
|
|
189
|
+
/** Human/model-facing description of what the tool does. */
|
|
190
|
+
description: string;
|
|
191
|
+
/** JSON-Schema object describing the tool's arguments. */
|
|
192
|
+
inputSchema: ToolInputSchema;
|
|
193
|
+
/** Unique tool name (the MCP `tools/call` `name`). */
|
|
194
|
+
name: string;
|
|
195
|
+
}
|
|
196
|
+
/** Registration shape for a paid tool: a {@link RegisterToolOptions} plus its USD price. */
|
|
197
|
+
interface RegisterPaidToolOptions extends RegisterToolOptions {
|
|
198
|
+
/** USD price per call (e.g. `"$0.05"`), charged via x402 before dispatch. */
|
|
199
|
+
price: X402Price;
|
|
200
|
+
}
|
|
201
|
+
/** x402 settlement vocabulary shared by every paid tool (network, recipient, facilitator); price is per-tool. */
|
|
202
|
+
type PaidMcpChargeConfig = Omit<X402ChargeConfig, "price">;
|
|
203
|
+
/** Config for `createPaidMcpServer`. */
|
|
204
|
+
interface PaidMcpServerConfig {
|
|
205
|
+
/** The worker-level x402 charge config; each paid tool supplies only its own `price`. */
|
|
206
|
+
charge: PaidMcpChargeConfig;
|
|
207
|
+
/** Name/version advertised in the MCP `initialize` handshake. Defaults to `lunora-paid-mcp`. */
|
|
208
|
+
serverInfo?: {
|
|
209
|
+
name: string;
|
|
210
|
+
version: string;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** A paid MCP server: register free/paid tools, then serve over Streamable HTTP. */
|
|
214
|
+
interface PaidMcpServer {
|
|
215
|
+
/** The Streamable-HTTP fetch handler; gates each paid `tools/call` behind x402. */
|
|
216
|
+
readonly fetchHandler: McpFetchHandler;
|
|
217
|
+
/** Register a **paid** tool: its dispatch runs the x402 charge middleware first. */
|
|
218
|
+
paidTool: (options: RegisterPaidToolOptions, handler: ToolHandler) => void;
|
|
219
|
+
/** Register a **free** tool (coexists with paid tools on the same server). */
|
|
220
|
+
tool: (options: RegisterToolOptions, handler: ToolHandler) => void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a paid MCP server. Register free tools with `tool()` and priced tools
|
|
224
|
+
* with `paidTool()` (they coexist), then serve `fetchHandler` over HTTP.
|
|
225
|
+
*
|
|
226
|
+
* The server is **stateless**: `fetchHandler` builds a fresh `Server` per
|
|
227
|
+
* request (reading the live tool registry), so tools registered before the
|
|
228
|
+
* first request are all visible. Each priced tool memoises one initialised
|
|
229
|
+
* `ChargeMiddleware` (keyed by tool name, baking that tool's price and naming
|
|
230
|
+
* the tool as the challenge `resource`); a failed init is not cached, so a
|
|
231
|
+
* transient facilitator outage retries on the next call.
|
|
232
|
+
*/
|
|
233
|
+
declare const createPaidMcpServer: (config: PaidMcpServerConfig) => PaidMcpServer;
|
|
234
|
+
export { AGENT_RUN_INPUT_SCHEMA, AGENT_STATUS_TOOL_NAME, type CallAgentToolOptions, type LunoraMcpServerOptions, type McpAgentExposure, type McpFetchHandler, type PaidMcpChargeConfig, 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, connectStdio, createLunoraMcpServer, createMcpFetchHandler, createPaidMcpServer, parseAgentsEnv, toolDefinitions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { LunoraClient } from '@lunora/client';
|
|
2
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
4
|
+
import { X402ChargeConfig, X402Price } from '@lunora/x402/charge';
|
|
5
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The tool surface this MCP server exposes. Each tool maps onto a method the
|
|
8
|
+
* `LunoraClient` already provides, so an AI agent can introspect a deployment
|
|
9
|
+
* (functions, global tables) and invoke its functions over HTTP RPC.
|
|
10
|
+
*
|
|
11
|
+
* Definitions and dispatch live here — separate from the server wiring — so the
|
|
12
|
+
* behaviour is unit-testable against a mock client without driving a transport.
|
|
13
|
+
*/
|
|
14
|
+
/** A JSON-Schema object describing a tool's arguments, per the MCP spec. */
|
|
11
15
|
interface ToolInputSchema {
|
|
12
16
|
properties: Record<string, unknown>;
|
|
13
17
|
required?: ReadonlyArray<string>;
|
|
@@ -18,6 +22,7 @@ interface ToolDefinition {
|
|
|
18
22
|
inputSchema: ToolInputSchema;
|
|
19
23
|
name: string;
|
|
20
24
|
}
|
|
25
|
+
/** The MCP `CallToolResult` shape this server returns. */
|
|
21
26
|
interface ToolResult {
|
|
22
27
|
content: {
|
|
23
28
|
text: string;
|
|
@@ -25,6 +30,205 @@ interface ToolResult {
|
|
|
25
30
|
}[];
|
|
26
31
|
isError?: boolean;
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
declare const
|
|
30
|
-
|
|
33
|
+
/** The read-only tool surface: introspection + query. Always exposed. */
|
|
34
|
+
declare const READ_ONLY_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
|
|
35
|
+
/** The write tool surface (mutations + actions). Exposed ONLY when writes are enabled. */
|
|
36
|
+
declare const WRITE_TOOL_DEFINITIONS: ReadonlyArray<ToolDefinition>;
|
|
37
|
+
/**
|
|
38
|
+
* The tools this server advertises. When `allowWrites` is false (the default),
|
|
39
|
+
* only the read-only surface is exposed — the mutation/action tools are omitted
|
|
40
|
+
* from `ListTools` entirely, so an AI agent can't invoke a write it can't see.
|
|
41
|
+
*/
|
|
42
|
+
declare const toolDefinitions: (allowWrites: boolean) => ReadonlyArray<ToolDefinition>;
|
|
43
|
+
/**
|
|
44
|
+
* Dispatch a tool call against `client`. Unknown tools and thrown errors are
|
|
45
|
+
* returned as `isError` results (rather than rejections) so the calling model
|
|
46
|
+
* sees the failure as tool output, per the MCP convention.
|
|
47
|
+
*
|
|
48
|
+
* `allowWrites` gates the mutation/action tools: when false (the default) a call
|
|
49
|
+
* to a write tool is refused even if the client somehow names it, so the
|
|
50
|
+
* read-only guarantee holds at dispatch, not just in the advertised tool list.
|
|
51
|
+
*/
|
|
52
|
+
declare const callTool: (client: LunoraClient, name: string, input: Record<string, unknown>, allowWrites?: boolean) => Promise<ToolResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Agent exposure for the MCP server: a durable `@lunora/agent` run fronted as an
|
|
55
|
+
* MCP tool an external agent can call. The capability boundary is the MCP-server
|
|
56
|
+
* process + its token, so WHICH agents are exposed is config on the server (like
|
|
57
|
+
* `allowWrites`), not on `defineAgent` — keeping `@lunora/agent` codegen
|
|
58
|
+
* byte-identical.
|
|
59
|
+
*/
|
|
60
|
+
interface McpAgentExposure {
|
|
61
|
+
/** What the agent does — shown to the calling model, which decides from it. */
|
|
62
|
+
description: string;
|
|
63
|
+
/** The agent's export name (its `ctx.agents.<name>` / `AGENT_<NAME>` binding). */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Override the model-facing tool name (default `agent_<name>`). */
|
|
66
|
+
toolName?: string;
|
|
67
|
+
}
|
|
68
|
+
/** The generic status/poll tool advertised alongside the per-agent tools. */
|
|
69
|
+
declare const AGENT_STATUS_TOOL_NAME = "lunora_agent_status";
|
|
70
|
+
/**
|
|
71
|
+
* The uniform input schema every agent tool advertises. Agents share ONE run
|
|
72
|
+
* input (`@lunora/agent` has no per-agent validator), so there is nothing to
|
|
73
|
+
* derive per agent — a single static schema is reused for every agent tool.
|
|
74
|
+
*/
|
|
75
|
+
declare const AGENT_RUN_INPUT_SCHEMA: ToolInputSchema;
|
|
76
|
+
/**
|
|
77
|
+
* Parse `LUNORA_MCP_AGENTS` — a `;`-separated list of `name:description` pairs,
|
|
78
|
+
* e.g. `"support:Handles support questions;billing:Billing help"`. The
|
|
79
|
+
* description may itself contain colons (only the FIRST colon splits). Blank
|
|
80
|
+
* entries and entries with an empty name/description are skipped.
|
|
81
|
+
*/
|
|
82
|
+
declare const parseAgentsEnv: (raw: string | undefined) => McpAgentExposure[];
|
|
83
|
+
/**
|
|
84
|
+
* The tools this module advertises. Fail-closed: only the boolean `true` opts
|
|
85
|
+
* in (an env-plumbed caller could pass a truthy string), and the tools appear
|
|
86
|
+
* ONLY when at least one agent is exposed — so an agent-free or non-opted-in
|
|
87
|
+
* server never lists them.
|
|
88
|
+
*/
|
|
89
|
+
declare const agentToolDefinitions: (exposures: ReadonlyArray<McpAgentExposure>, allowAgents: boolean) => ReadonlyArray<ToolDefinition>;
|
|
90
|
+
/** Options threaded into a single agent tool dispatch. */
|
|
91
|
+
interface CallAgentToolOptions {
|
|
92
|
+
/** Opt-in gate — must be exactly `true` or the call is refused fail-closed. */
|
|
93
|
+
allowAgents: boolean;
|
|
94
|
+
/** The exposures advertised by this server. */
|
|
95
|
+
exposures: ReadonlyArray<McpAgentExposure>;
|
|
96
|
+
/** Wall-clock budget a single call awaits before returning a pending result. */
|
|
97
|
+
maxWaitMs?: number;
|
|
98
|
+
/** Delay between thread-status polls. */
|
|
99
|
+
pollIntervalMs?: number;
|
|
100
|
+
/** Test seam replacing the between-poll wait; production uses a real timer. */
|
|
101
|
+
wait?: (ms: number) => Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Dispatch an agent tool call: start a durable run via `agents:agentRun`, then
|
|
105
|
+
* await-with-timeout — poll `agents:agentThread` until terminal (returning the
|
|
106
|
+
* final answer from `agents:agentMessages`) or, on budget exhaustion, return a
|
|
107
|
+
* NON-error pending payload the caller resumes with `lunora_agent_status`.
|
|
108
|
+
*
|
|
109
|
+
* Fail-closed: refused at dispatch unless `allowAgents === true`, mirroring the
|
|
110
|
+
* `allowWrites` guard — starting a run is a side effect and must not ride the
|
|
111
|
+
* read-only default.
|
|
112
|
+
*/
|
|
113
|
+
declare const callAgentTool: (client: LunoraClient, name: string, input: Record<string, unknown>, options: CallAgentToolOptions) => Promise<ToolResult>;
|
|
114
|
+
interface LunoraMcpServerOptions {
|
|
115
|
+
/** Wall-clock budget a single agent tool call awaits before returning a pending result. */
|
|
116
|
+
agentMaxWaitMs?: number;
|
|
117
|
+
/** Delay between agent thread-status polls. */
|
|
118
|
+
agentPollIntervalMs?: number;
|
|
119
|
+
/** The agents this server fronts as MCP tools (see `allowAgents`). */
|
|
120
|
+
agents?: ReadonlyArray<McpAgentExposure>;
|
|
121
|
+
/**
|
|
122
|
+
* Expose the per-agent tools (`agent_<name>` + the generic
|
|
123
|
+
* `lunora_agent_status`). Defaults to `false`, mirroring `allowWrites`:
|
|
124
|
+
* starting a durable agent run is a side effect, so the agent tools are
|
|
125
|
+
* omitted from the advertised list AND refused at dispatch unless explicitly
|
|
126
|
+
* opted in. Only takes effect together with a non-empty `agents` list.
|
|
127
|
+
*/
|
|
128
|
+
allowAgents?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Expose the write tools (`lunora_run_mutation` / `lunora_run_action`).
|
|
131
|
+
* Defaults to `false`: the server is READ-ONLY unless explicitly opted in,
|
|
132
|
+
* so a prompt-injected or misaligned agent can't mutate the deployment with
|
|
133
|
+
* the configured token. When false the write tools are omitted from the
|
|
134
|
+
* advertised tool list AND refused at dispatch.
|
|
135
|
+
*/
|
|
136
|
+
allowWrites?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Pre-built client (test injection). When omitted a `LunoraClient` is
|
|
139
|
+
* created from `url`/`token`/`fetch`.
|
|
140
|
+
*/
|
|
141
|
+
client?: LunoraClient;
|
|
142
|
+
/** `fetch` implementation; defaults to the ambient global. */
|
|
143
|
+
fetch?: typeof fetch;
|
|
144
|
+
/**
|
|
145
|
+
* Bearer token sent on every RPC. This must be the deployment's **admin
|
|
146
|
+
* bearer**: the introspection/allowlist path every tool depends on
|
|
147
|
+
* (`lunora_list_functions`, `lunora_list_tables`, and the `assertRunnable`
|
|
148
|
+
* precheck that runs before every `run` tool) hits admin-gated
|
|
149
|
+
* `/_lunora/admin/*` routes, so no scoped/app token works today — it would
|
|
150
|
+
* 403 (`ADMIN_FORBIDDEN`) on the first tool call. The read-only guarantee is
|
|
151
|
+
* therefore NOT enforced by the token's scope; it is enforced in-process via
|
|
152
|
+
* `allowWrites: false` (the default), which omits the write tools from the
|
|
153
|
+
* advertised list and refuses them at dispatch.
|
|
154
|
+
*/
|
|
155
|
+
token?: string;
|
|
156
|
+
/** Base URL of the deployed Lunora Worker. Required unless `client` is given. */
|
|
157
|
+
url?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Build an MCP `Server` whose tools talk to a Lunora deployment. The server is
|
|
161
|
+
* transport-agnostic — call `.connect(transport)` yourself, or use
|
|
162
|
+
* `connectStdio` for the common stdio case.
|
|
163
|
+
*
|
|
164
|
+
* Tool calls are dispatched through `callTool`, which the deployment reaches
|
|
165
|
+
* over HTTP RPC. No WebSocket is opened (the tools never subscribe), so this is
|
|
166
|
+
* safe to run as a short-lived stdio process.
|
|
167
|
+
*/
|
|
168
|
+
declare const createLunoraMcpServer: (options: LunoraMcpServerOptions) => Server;
|
|
169
|
+
/**
|
|
170
|
+
* Build the server and connect it over stdio — the transport MCP clients use
|
|
171
|
+
* when they spawn the `lunora-mcp` binary. Resolves once the transport is
|
|
172
|
+
* connected; the process then stays alive serving requests.
|
|
173
|
+
*/
|
|
174
|
+
declare const connectStdio: (options: LunoraMcpServerOptions) => Promise<Server>;
|
|
175
|
+
/** A Web-Standard fetch handler: takes a `Request`, returns the MCP `Response`. */
|
|
176
|
+
type McpFetchHandler = (request: Request) => Promise<Response>;
|
|
177
|
+
/**
|
|
178
|
+
* Build a stateless Streamable-HTTP fetch handler for a Lunora MCP server. Each
|
|
179
|
+
* invocation constructs a fresh proxy server and serves the request through
|
|
180
|
+
* {@link serveStateless}.
|
|
181
|
+
*/
|
|
182
|
+
declare const createMcpFetchHandler: (options: LunoraMcpServerOptions) => McpFetchHandler;
|
|
183
|
+
/** A tool handler: receives the call's `arguments` bag, returns an MCP tool result. */
|
|
184
|
+
type ToolHandler = (arguments_: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
|
|
185
|
+
/** Registration shape for a free tool. */
|
|
186
|
+
interface RegisterToolOptions {
|
|
187
|
+
/** Optional MCP tool annotations (`readOnlyHint`, `title`, …). */
|
|
188
|
+
annotations?: Tool["annotations"];
|
|
189
|
+
/** Human/model-facing description of what the tool does. */
|
|
190
|
+
description: string;
|
|
191
|
+
/** JSON-Schema object describing the tool's arguments. */
|
|
192
|
+
inputSchema: ToolInputSchema;
|
|
193
|
+
/** Unique tool name (the MCP `tools/call` `name`). */
|
|
194
|
+
name: string;
|
|
195
|
+
}
|
|
196
|
+
/** Registration shape for a paid tool: a {@link RegisterToolOptions} plus its USD price. */
|
|
197
|
+
interface RegisterPaidToolOptions extends RegisterToolOptions {
|
|
198
|
+
/** USD price per call (e.g. `"$0.05"`), charged via x402 before dispatch. */
|
|
199
|
+
price: X402Price;
|
|
200
|
+
}
|
|
201
|
+
/** x402 settlement vocabulary shared by every paid tool (network, recipient, facilitator); price is per-tool. */
|
|
202
|
+
type PaidMcpChargeConfig = Omit<X402ChargeConfig, "price">;
|
|
203
|
+
/** Config for `createPaidMcpServer`. */
|
|
204
|
+
interface PaidMcpServerConfig {
|
|
205
|
+
/** The worker-level x402 charge config; each paid tool supplies only its own `price`. */
|
|
206
|
+
charge: PaidMcpChargeConfig;
|
|
207
|
+
/** Name/version advertised in the MCP `initialize` handshake. Defaults to `lunora-paid-mcp`. */
|
|
208
|
+
serverInfo?: {
|
|
209
|
+
name: string;
|
|
210
|
+
version: string;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** A paid MCP server: register free/paid tools, then serve over Streamable HTTP. */
|
|
214
|
+
interface PaidMcpServer {
|
|
215
|
+
/** The Streamable-HTTP fetch handler; gates each paid `tools/call` behind x402. */
|
|
216
|
+
readonly fetchHandler: McpFetchHandler;
|
|
217
|
+
/** Register a **paid** tool: its dispatch runs the x402 charge middleware first. */
|
|
218
|
+
paidTool: (options: RegisterPaidToolOptions, handler: ToolHandler) => void;
|
|
219
|
+
/** Register a **free** tool (coexists with paid tools on the same server). */
|
|
220
|
+
tool: (options: RegisterToolOptions, handler: ToolHandler) => void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a paid MCP server. Register free tools with `tool()` and priced tools
|
|
224
|
+
* with `paidTool()` (they coexist), then serve `fetchHandler` over HTTP.
|
|
225
|
+
*
|
|
226
|
+
* The server is **stateless**: `fetchHandler` builds a fresh `Server` per
|
|
227
|
+
* request (reading the live tool registry), so tools registered before the
|
|
228
|
+
* first request are all visible. Each priced tool memoises one initialised
|
|
229
|
+
* `ChargeMiddleware` (keyed by tool name, baking that tool's price and naming
|
|
230
|
+
* the tool as the challenge `resource`); a failed init is not cached, so a
|
|
231
|
+
* transient facilitator outage retries on the next call.
|
|
232
|
+
*/
|
|
233
|
+
declare const createPaidMcpServer: (config: PaidMcpServerConfig) => PaidMcpServer;
|
|
234
|
+
export { AGENT_RUN_INPUT_SCHEMA, AGENT_STATUS_TOOL_NAME, type CallAgentToolOptions, type LunoraMcpServerOptions, type McpAgentExposure, type McpFetchHandler, type PaidMcpChargeConfig, 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, connectStdio, createLunoraMcpServer, createMcpFetchHandler, createPaidMcpServer, parseAgentsEnv, toolDefinitions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { TOOL_DEFINITIONS, callTool } from './packem_shared/TOOL_DEFINITIONS-Dpiu38ji.mjs';
|
|
1
|
+
import{AGENT_RUN_INPUT_SCHEMA as r,AGENT_STATUS_TOOL_NAME as t,agentToolDefinitions as T,callAgentTool as n,parseAgentsEnv as c}from"./packem_shared/AGENT_RUN_INPUT_SCHEMA-ihZg6vIZ.mjs";import{createMcpFetchHandler as a}from"./packem_shared/createMcpFetchHandler-CHssdLE-.mjs";import{createPaidMcpServer as l}from"./packem_shared/createPaidMcpServer-CQP3p1-0.mjs";import{connectStdio as E,createLunoraMcpServer as O}from"./packem_shared/connectStdio-Dtos_i1h.mjs";import{READ_ONLY_TOOL_DEFINITIONS as A,WRITE_TOOL_DEFINITIONS as I,callTool as S,toolDefinitions as f}from"./packem_shared/READ_ONLY_TOOL_DEFINITIONS-J_O1zHbG.mjs";export{r as AGENT_RUN_INPUT_SCHEMA,t as AGENT_STATUS_TOOL_NAME,A as READ_ONLY_TOOL_DEFINITIONS,I as WRITE_TOOL_DEFINITIONS,T as agentToolDefinitions,n as callAgentTool,S as callTool,E as connectStdio,O as createLunoraMcpServer,a as createMcpFetchHandler,l as createPaidMcpServer,c as parseAgentsEnv,f as toolDefinitions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const N="agents:agentRun",w="agents:agentThread",S="agents:agentMessages",p="lunora_agent_status",_=new Set(["cancelled","error","idle"]),E=6e4,M=600,k={properties:{prompt:{description:"The task or message for the agent.",type:"string"},threadKey:{description:"Reuse to continue a conversation; omit to start a new thread.",type:"string"},title:{description:"Optional thread title (first run only).",type:"string"}},required:["prompt"],type:"object"},O={properties:{threadKey:{description:"The thread key returned by an agent tool call.",type:"string"}},required:["threadKey"],type:"object"},y=t=>t.toolName??`agent_${t.name}`,I=t=>{if(t===void 0)return[];const n=[];for(const e of t.split(";")){const r=e.trim();if(r.length===0)continue;const a=r.indexOf(":");if(a<=0)continue;const s=r.slice(0,a).trim(),o=r.slice(a+1).trim();s.length===0||o.length===0||n.push({description:o,name:s})}return n},L=(t,n)=>n!==!0||t.length===0?[]:[...t.map(e=>({description:`${e.description} Starts a durable agent run and returns its final answer.`,inputSchema:k,name:y(e)})),{description:"Check the status of a durable agent run (and its answer if finished) by its threadKey.",inputSchema:O,name:p}],P=(t,n)=>t===p||n.some(e=>y(e)===t),q=()=>`mcp-${crypto.randomUUID()}`,c=t=>({__lunoraRef:t}),U=async t=>{await new Promise(n=>{setTimeout(n,t)})},d=t=>({content:[{text:JSON.stringify(t,void 0,2),type:"text"}]}),i=t=>({content:[{text:t,type:"text"}],isError:!0}),l=(t,n)=>{const e=t[n];return typeof e=="string"&&e.length>0?e:void 0},C=t=>{for(let n=t.length-1;n>=0;n-=1){const e=t[n],r=e?.toolCalls,a=Array.isArray(r)&&r.length>0;if(e?.role==="assistant"&&!a)return typeof e.content=="string"?e.content:""}return""},A=t=>t!==null&&typeof t=="object"&&typeof t.status=="string"?t.status:"unknown",v=async(t,n,e,r)=>{const a=await t.query(c(S),{key:n});if(e==="error"){const s=r!==null&&typeof r=="object"?r.error:void 0;return d({error:typeof s=="string"?s:"the agent run failed",status:e,threadKey:n})}return d({status:e,text:C(a),threadKey:n})},R=async(t,n)=>{const e=l(n,"threadKey");if(e===void 0)return i('"threadKey" is required and must be a non-empty string');const r=await t.query(c(w),{key:e}),a=A(r);return _.has(a)?v(t,e,a,r):d({status:a==="unknown"?"running":a,threadKey:e})},$=async(t,n,e,r)=>{try{if(r.allowAgents!==!0)return i(`tool "${n}" is disabled: agent tools are off. Enable them with the LUNORA_MCP_ALLOW_AGENTS env var.`);if(n===p)return await R(t,e);const a=r.exposures.find(u=>y(u)===n);if(a===void 0)return i(`agent tool "${n}" is not exposed by this MCP server`);const s=l(e,"prompt");if(s===void 0)return i('"prompt" is required and must be a non-empty string');const o=l(e,"threadKey")??q(),h=l(e,"title"),{id:T}=await t.mutation(c(N),{agent:a.name,input:s,threadKey:o,...h===void 0?{}:{title:h}}),g=r.pollIntervalMs??M,b=r.maxWaitMs??E,K=r.wait??U,x=Math.max(1,Math.ceil(b/g));for(let u=0;u<x;u+=1){const f=await t.query(c(w),{key:o}),m=A(f);if(_.has(m))return await v(t,o,m,f);await K(g)}return d({hint:"call lunora_agent_status with this threadKey to poll for the answer",runId:T,status:"running",threadKey:o})}catch(a){const s=a instanceof Error?a.message:String(a);return i(s)}};export{k as AGENT_RUN_INPUT_SCHEMA,p as AGENT_STATUS_TOOL_NAME,L as agentToolDefinitions,$ as callAgentTool,C as finalAnswer,P as isAgentToolName,I as parseAgentsEnv};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as u}from"@lunora/errors";const f={properties:{args:{description:"Arguments object passed to the function",type:"object"},functionPath:{description:'Function reference, e.g. "messages:send"',type:"string"},shardKey:{description:"Optional shard key when the function is .shardBy()-partitioned",type:"string"}},required:["functionPath"],type:"object"},y={properties:{},type:"object"},E={properties:{functionPath:{description:'Function reference, e.g. "messages:send"',type:"string"}},required:["functionPath"],type:"object"},g=[{description:"List the deployment's public functions (queries, mutations, actions) with their kinds.",inputSchema:y,name:"lunora_list_functions"},{description:"List the deployment's .global() tables and their column shapes.",inputSchema:y,name:"lunora_list_tables"},{description:"Return a function's argument JSON Schema and kind, so a caller can construct a valid arguments object. Call lunora_list_functions first to discover available function paths.",inputSchema:E,name:"lunora_get_function_schema"},{description:"Run a query and return its result. Read-only.",inputSchema:f,name:"lunora_run_query"}],b=[{description:"Run a mutation and return its result. Writes data — use with care.",inputSchema:f,name:"lunora_run_mutation"},{description:"Run an action and return its result. May call external services.",inputSchema:f,name:"lunora_run_action"}],O=new Set(b.map(t=>t.name)),T=t=>t===!0?[...g,...b]:g,S=t=>{const{functionPath:e}=t;if(typeof e!="string"||e.length===0)throw new u("INTERNAL",'"functionPath" is required and must be a non-empty string');return e},m=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),_=t=>Array.isArray(t)?"an array":`a ${typeof t}`,A=t=>{if(t==null)return{};if(typeof t=="string"){let e;try{e=JSON.parse(t)}catch{throw new u("BAD_REQUEST",'"args" must be a JSON object; received a string that is not valid JSON')}if(!m(e))throw new u("BAD_REQUEST",`"args" must be a JSON object; the provided string decoded to ${_(e)}`);return e}if(!m(t))throw new u("BAD_REQUEST",`"args" must be a JSON object, got ${_(t)}`);return t},l=t=>{const e=S(t),r=A(t.args),i=typeof t.shardKey=="string"&&t.shardKey.length>0?t.shardKey:void 0;return{args:r,functionPath:e,shardKey:i}},d=t=>({__lunoraRef:t}),w=t=>{let e="";for(let r=0;r<t.length;r+=32768)e+=String.fromCharCode(...t.subarray(r,r+32768));return btoa(e)},N=(t,e)=>{if(typeof e=="bigint")return e.toString();if(e instanceof ArrayBuffer)return w(new Uint8Array(e));if(ArrayBuffer.isView(e)){const r=e;return w(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}return e},s=t=>({content:[{text:t===void 0?"null":JSON.stringify(t,N,2),type:"text"}]}),v=3e4,c=new WeakMap,p=t=>{const e=Date.now(),r=c.get(t);if(r!==void 0&&r.expiresAt>e)return r.promise;const i=t.listFunctions().catch(n=>{throw c.get(t)?.promise===i&&c.delete(t),n});return c.set(t,{expiresAt:e+v,promise:i}),i},h=async(t,e,r)=>{const i=(await p(t)).find(n=>n.path===e);if(i===void 0)throw new u("NOT_FOUND",`function not found or not public: ${e}`);if(i.kind!==r)throw new u("BAD_REQUEST",`function ${e} is a ${i.kind}, not a ${r}`)},x=async(t,e,r,i=!1)=>{try{if(i!==!0&&O.has(e))return{content:[{text:`tool "${e}" is disabled: this MCP server is read-only. Enable writes with the LUNORA_MCP_ALLOW_WRITES env var.`,type:"text"}],isError:!0};switch(e){case"lunora_get_function_schema":{const n=S(r),a=(await p(t)).find(o=>o.path===n);return a===void 0?{content:[{text:`function not found: ${n}`,type:"text"}],isError:!0}:s({args:a.args??[],kind:a.kind,path:a.path})}case"lunora_list_functions":return s(await p(t));case"lunora_list_tables":return s(await t.listGlobalTables());case"lunora_run_action":{const{args:n,functionPath:a,shardKey:o}=l(r);return await h(t,a,"action"),s(await t.action(d(a),n,{shardKey:o}))}case"lunora_run_mutation":{const{args:n,functionPath:a,shardKey:o}=l(r);return await h(t,a,"mutation"),s(await t.mutation(d(a),n,{shardKey:o}))}case"lunora_run_query":{const{args:n,functionPath:a,shardKey:o}=l(r);return await h(t,a,"query"),s(await t.query(d(a),n,{shardKey:o}))}default:return{content:[{text:`unknown tool: ${e}`,type:"text"}],isError:!0}}}catch(n){return{content:[{text:n instanceof Error?n.message:String(n),type:"text"}],isError:!0}}};export{g as READ_ONLY_TOOL_DEFINITIONS,b as WRITE_TOOL_DEFINITIONS,x as callTool,T as toolDefinitions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as u}from"node:fs";import{dirname as l,join as f}from"node:path";import{fileURLToPath as p}from"node:url";import{LunoraClient as v}from"@lunora/client";import{LunoraError as g}from"@lunora/errors";import{Server as d}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as h}from"@modelcontextprotocol/sdk/server/stdio.js";import{ListToolsRequestSchema as w,CallToolRequestSchema as M}from"@modelcontextprotocol/sdk/types.js";import{agentToolDefinitions as S,isAgentToolName as T,callAgentTool as k}from"./AGENT_RUN_INPUT_SCHEMA-ihZg6vIZ.mjs";import{toolDefinitions as L,callTool as x}from"./READ_ONLY_TOOL_DEFINITIONS-J_O1zHbG.mjs";const y=()=>{try{let t=l(p(import.meta.url));for(let r=0;r<8;r+=1){try{const a=u(f(t,"package.json"),"utf8"),o=JSON.parse(a);if(o.name==="@lunora/mcp"&&typeof o.version=="string"&&o.version.length>0)return o.version}catch{}const e=l(t);if(e===t)break;t=e}}catch{}return"0.0.0"},A={name:"lunora",version:y()},R=t=>{if(t.client!==void 0)return t.client;if(t.url===void 0)throw new g("INTERNAL","createLunoraMcpServer requires either a `client` or a `url`");const r=new v({fetch:t.fetch,url:t.url});return t.token!==void 0&&r.setAuthToken(t.token),r},q=t=>{const r=R(t),e=t.allowWrites??!1,a=t.allowAgents??!1,o=t.agents??[],n=new d(A,{capabilities:{tools:{}}});return n.setRequestHandler(w,()=>({tools:[...L(e),...S(o,a)]})),n.setRequestHandler(M,async c=>{const{arguments:m,name:s}=c.params,i=m??{};return T(s,o)?await k(r,s,i,{allowAgents:a,exposures:o,...t.agentMaxWaitMs===void 0?{}:{maxWaitMs:t.agentMaxWaitMs},...t.agentPollIntervalMs===void 0?{}:{pollIntervalMs:t.agentPollIntervalMs}}):await x(r,s,i,e)}),n},O=async t=>{const r=q(t);return await r.connect(new h),r};export{O as connectStdio,q as createLunoraMcpServer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WebStandardStreamableHTTPServerTransport as c}from"@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";import{createLunoraMcpServer as n}from"./connectStdio-Dtos_i1h.mjs";const o=async(e,t,a)=>{const r=new c({enableJsonResponse:!0,sessionIdGenerator:void 0});await e.connect(r);const s=await r.handleRequest(t,a);return r.close().catch(()=>{}),e.close().catch(()=>{}),s},d=e=>t=>o(n(e),t);export{d as createMcpFetchHandler,o as serveStateless};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as h}from"@lunora/errors";import{createChargeMiddleware as f}from"@lunora/x402/charge";import{Server as y}from"@modelcontextprotocol/sdk/server/index.js";import{ListToolsRequestSchema as w,CallToolRequestSchema as S}from"@modelcontextprotocol/sdk/types.js";import{serveStateless as g}from"./createMcpFetchHandler-CHssdLE-.mjs";const M={name:"lunora-paid-mcp",version:"0.0.0"},R="tools/call",d=n=>{if(typeof n!="object"||n===null)return;const{method:s,params:a}=n;if(s!==R||typeof a!="object"||a===null)return;const{name:i}=a;return typeof i=="string"?i:void 0},C=()=>Response.json({error:"A JSON-RPC batch may not reference a paid MCP tool; send paid tools/call requests individually."},{status:400}),P=n=>{const s=new Map,a=new Map,i=new Map,m=n.serverInfo??M,c=(e,t,o)=>{if(s.has(e.name))throw new h("BAD_REQUEST",`MCP tool "${e.name}" is already registered.`);const r={description:e.description,inputSchema:e.inputSchema,name:e.name};e.annotations!==void 0&&(r.annotations=e.annotations),s.set(e.name,{definition:r,handler:t}),o!==void 0&&a.set(e.name,o)},p=()=>{const e=new y(m,{capabilities:{tools:{}}});return e.setRequestHandler(w,()=>({tools:[...s.values()].map(t=>t.definition)})),e.setRequestHandler(S,async t=>{const o=s.get(t.params.name);return o===void 0?{content:[{text:`unknown tool: ${t.params.name}`,type:"text"}],isError:!0}:await o.handler(t.params.arguments??{})}),e},u=(e,t)=>{let o=i.get(e);return o===void 0&&(o=f({...n.charge,price:t},{resource:e}).catch(r=>{throw i.delete(e),r}),i.set(e,o)),o};return{fetchHandler:async e=>{let t;try{t=await e.clone().json()}catch{t=void 0}const o=()=>g(p(),e,t===void 0?void 0:{parsedBody:t});if(Array.isArray(t))return t.some(v=>a.has(d(v)??""))?C():o();const r=d(t),l=r===void 0?void 0:a.get(r);return r===void 0||l===void 0?o():(await u(r,l)).handle(e,o)},paidTool:(e,t)=>{c(e,t,e.price)},tool:(e,t)=>{c(e,t)}}};export{P as createPaidMcpServer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/mcp",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.41",
|
|
4
4
|
"description": "Model Context Protocol server exposing a Lunora deployment to AI agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@lunora/client": "1.0.0-alpha.
|
|
52
|
+
"@lunora/client": "1.0.0-alpha.31",
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.8",
|
|
54
|
+
"@lunora/x402": "1.0.0-alpha.16",
|
|
53
55
|
"@modelcontextprotocol/sdk": "^1.29.0"
|
|
54
56
|
},
|
|
55
57
|
"engines": {
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
const RUN_INPUT_SCHEMA = {
|
|
2
|
-
properties: {
|
|
3
|
-
args: { description: "Arguments object passed to the function", type: "object" },
|
|
4
|
-
functionPath: { description: 'Function reference, e.g. "messages:send"', type: "string" },
|
|
5
|
-
shardKey: { description: "Optional shard key when the function is .shardBy()-partitioned", type: "string" }
|
|
6
|
-
},
|
|
7
|
-
required: ["functionPath"],
|
|
8
|
-
type: "object"
|
|
9
|
-
};
|
|
10
|
-
const NO_INPUT_SCHEMA = { properties: {}, type: "object" };
|
|
11
|
-
const FUNCTION_PATH_INPUT_SCHEMA = {
|
|
12
|
-
properties: {
|
|
13
|
-
functionPath: { description: 'Function reference, e.g. "messages:send"', type: "string" }
|
|
14
|
-
},
|
|
15
|
-
required: ["functionPath"],
|
|
16
|
-
type: "object"
|
|
17
|
-
};
|
|
18
|
-
const TOOL_DEFINITIONS = [
|
|
19
|
-
{
|
|
20
|
-
description: "List the deployment's public functions (queries, mutations, actions) with their kinds.",
|
|
21
|
-
inputSchema: NO_INPUT_SCHEMA,
|
|
22
|
-
name: "lunora_list_functions"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
description: "List the deployment's .global() tables and their column shapes.",
|
|
26
|
-
inputSchema: NO_INPUT_SCHEMA,
|
|
27
|
-
name: "lunora_list_tables"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
description: "Return a function's argument JSON Schema and kind, so a caller can construct a valid arguments object. Call lunora_list_functions first to discover available function paths.",
|
|
31
|
-
inputSchema: FUNCTION_PATH_INPUT_SCHEMA,
|
|
32
|
-
name: "lunora_get_function_schema"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
description: "Run a query and return its result. Read-only.",
|
|
36
|
-
inputSchema: RUN_INPUT_SCHEMA,
|
|
37
|
-
name: "lunora_run_query"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
description: "Run a mutation and return its result. Writes data — use with care.",
|
|
41
|
-
inputSchema: RUN_INPUT_SCHEMA,
|
|
42
|
-
name: "lunora_run_mutation"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
description: "Run an action and return its result. May call external services.",
|
|
46
|
-
inputSchema: RUN_INPUT_SCHEMA,
|
|
47
|
-
name: "lunora_run_action"
|
|
48
|
-
}
|
|
49
|
-
];
|
|
50
|
-
const readFunctionPath = (input) => {
|
|
51
|
-
const { functionPath } = input;
|
|
52
|
-
if (typeof functionPath !== "string" || functionPath.length === 0) {
|
|
53
|
-
throw new Error('"functionPath" is required and must be a non-empty string');
|
|
54
|
-
}
|
|
55
|
-
return functionPath;
|
|
56
|
-
};
|
|
57
|
-
const readRunArguments = (input) => {
|
|
58
|
-
const functionPath = readFunctionPath(input);
|
|
59
|
-
const rawArguments = input.args;
|
|
60
|
-
const isPlainObject = typeof rawArguments === "object" && rawArguments !== null && !Array.isArray(rawArguments);
|
|
61
|
-
const args = isPlainObject ? rawArguments : {};
|
|
62
|
-
const shardKey = typeof input.shardKey === "string" && input.shardKey.length > 0 ? input.shardKey : void 0;
|
|
63
|
-
return { args, functionPath, shardKey };
|
|
64
|
-
};
|
|
65
|
-
const reference = (functionPath) => {
|
|
66
|
-
return { __lunoraRef: functionPath };
|
|
67
|
-
};
|
|
68
|
-
const ok = (value) => {
|
|
69
|
-
const text = value === void 0 ? "null" : JSON.stringify(value, void 0, 2);
|
|
70
|
-
return { content: [{ text, type: "text" }] };
|
|
71
|
-
};
|
|
72
|
-
const callTool = async (client, name, input) => {
|
|
73
|
-
try {
|
|
74
|
-
switch (name) {
|
|
75
|
-
case "lunora_get_function_schema": {
|
|
76
|
-
const functionPath = readFunctionPath(input);
|
|
77
|
-
const functions = await client.listFunctions();
|
|
78
|
-
const descriptor = functions.find((function_) => function_.path === functionPath);
|
|
79
|
-
if (descriptor === void 0) {
|
|
80
|
-
return { content: [{ text: `function not found: ${functionPath}`, type: "text" }], isError: true };
|
|
81
|
-
}
|
|
82
|
-
return ok({ args: descriptor.args ?? [], kind: descriptor.kind, path: descriptor.path });
|
|
83
|
-
}
|
|
84
|
-
case "lunora_list_functions": {
|
|
85
|
-
return ok(await client.listFunctions());
|
|
86
|
-
}
|
|
87
|
-
case "lunora_list_tables": {
|
|
88
|
-
return ok(await client.listGlobalTables());
|
|
89
|
-
}
|
|
90
|
-
case "lunora_run_action": {
|
|
91
|
-
const { args, functionPath, shardKey } = readRunArguments(input);
|
|
92
|
-
return ok(await client.action(reference(functionPath), args, { shardKey }));
|
|
93
|
-
}
|
|
94
|
-
case "lunora_run_mutation": {
|
|
95
|
-
const { args, functionPath, shardKey } = readRunArguments(input);
|
|
96
|
-
return ok(await client.mutation(reference(functionPath), args, { shardKey }));
|
|
97
|
-
}
|
|
98
|
-
case "lunora_run_query": {
|
|
99
|
-
const { args, functionPath, shardKey } = readRunArguments(input);
|
|
100
|
-
return ok(await client.query(reference(functionPath), args, { shardKey }));
|
|
101
|
-
}
|
|
102
|
-
default: {
|
|
103
|
-
return { content: [{ text: `unknown tool: ${name}`, type: "text" }], isError: true };
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} catch (error) {
|
|
107
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
-
return { content: [{ text: message, type: "text" }], isError: true };
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export { TOOL_DEFINITIONS, callTool };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { LunoraClient } from '@lunora/client';
|
|
5
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
-
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
-
import { TOOL_DEFINITIONS, callTool } from './TOOL_DEFINITIONS-Dpiu38ji.mjs';
|
|
9
|
-
|
|
10
|
-
const resolveVersion = () => {
|
|
11
|
-
try {
|
|
12
|
-
let directory = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
14
|
-
try {
|
|
15
|
-
const raw = readFileSync(join(directory, "package.json"), "utf8");
|
|
16
|
-
const pkg = JSON.parse(raw);
|
|
17
|
-
if (pkg.name === "@lunora/mcp" && typeof pkg.version === "string" && pkg.version.length > 0) {
|
|
18
|
-
return pkg.version;
|
|
19
|
-
}
|
|
20
|
-
} catch {
|
|
21
|
-
}
|
|
22
|
-
const parent = dirname(directory);
|
|
23
|
-
if (parent === directory) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
directory = parent;
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
}
|
|
30
|
-
return "0.0.0";
|
|
31
|
-
};
|
|
32
|
-
const SERVER_INFO = { name: "lunora", version: resolveVersion() };
|
|
33
|
-
const resolveClient = (options) => {
|
|
34
|
-
if (options.client !== void 0) {
|
|
35
|
-
return options.client;
|
|
36
|
-
}
|
|
37
|
-
if (options.url === void 0) {
|
|
38
|
-
throw new Error("createLunoraMcpServer requires either a `client` or a `url`");
|
|
39
|
-
}
|
|
40
|
-
const client = new LunoraClient({ fetch: options.fetch, url: options.url });
|
|
41
|
-
if (options.token !== void 0) {
|
|
42
|
-
client.setAuthToken(options.token);
|
|
43
|
-
}
|
|
44
|
-
return client;
|
|
45
|
-
};
|
|
46
|
-
const createLunoraMcpServer = (options) => {
|
|
47
|
-
const client = resolveClient(options);
|
|
48
|
-
const server = new Server(SERVER_INFO, { capabilities: { tools: {} } });
|
|
49
|
-
server.setRequestHandler(ListToolsRequestSchema, () => {
|
|
50
|
-
return { tools: [...TOOL_DEFINITIONS] };
|
|
51
|
-
});
|
|
52
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
53
|
-
const result = await callTool(client, request.params.name, request.params.arguments ?? {});
|
|
54
|
-
return result;
|
|
55
|
-
});
|
|
56
|
-
return server;
|
|
57
|
-
};
|
|
58
|
-
const connectStdio = async (options) => {
|
|
59
|
-
const server = createLunoraMcpServer(options);
|
|
60
|
-
await server.connect(new StdioServerTransport());
|
|
61
|
-
return server;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export { connectStdio, createLunoraMcpServer };
|