@lunora/mcp 1.0.0-alpha.21 → 1.0.0-alpha.211
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 +120 -0
- package/README.md +229 -10
- package/dist/bin.mjs +4 -37
- package/dist/docs/index.d.mts +258 -0
- package/dist/docs/index.d.ts +258 -0
- package/dist/docs/index.mjs +1 -0
- package/dist/index.d.mts +518 -27
- package/dist/index.d.ts +518 -27
- package/dist/index.mjs +1 -4
- package/dist/packem_shared/AGENT_RUN_INPUT_SCHEMA-hKbpa3Dg.mjs +1 -0
- package/dist/packem_shared/DEFAULT_DOCS_BASE_URL-CiHy_Dbz.mjs +4 -0
- package/dist/packem_shared/DEFAULT_MAX_REQUEST_BYTES-CbbpkHRK.mjs +1 -0
- package/dist/packem_shared/DEFAULT_SEARCH_LIMIT-B8C5JM2y.mjs +3 -0
- package/dist/packem_shared/DOCS_SERVER_NAME-CUnLrk1a.mjs +1 -0
- package/dist/packem_shared/DOCS_URI_SCHEME-C35UQ5Fo.mjs +3 -0
- package/dist/packem_shared/LOCAL_SERVER_NAME-C0IDD-qv.mjs +1 -0
- package/dist/packem_shared/OBSERVABILITY_TOOL_DEFINITIONS-mO4JuHgV.mjs +1 -0
- package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-D0P_U10J.mjs +1 -0
- package/dist/packem_shared/connectStdio-Cpwf1Lbw.mjs +1 -0
- package/dist/packem_shared/createAuthedMcpFetchHandler-o5r1AXH-.mjs +1 -0
- package/dist/packem_shared/createMcpFetchHandler-B8mrSCqy.mjs +1 -0
- package/dist/packem_shared/createPaidMcpServer-C_V1beyQ.mjs +1 -0
- package/dist/packem_shared/createToolServer-BtGuPyMU.mjs +1 -0
- package/dist/packem_shared/observability-tools-D4Z8dGS-.mjs +1 -0
- package/dist/packem_shared/promise-memo-OqVPWoUX.mjs +1 -0
- package/dist/packem_shared/serve-stateless.d-CKsbI0fP.d.mts +154 -0
- package/dist/packem_shared/serve-stateless.d-CKsbI0fP.d.ts +154 -0
- package/dist/packem_shared/toDocsSearchHits-CBLmtWXt.mjs +1 -0
- package/dist/packem_shared/tool-call-Bs-QeKp6.mjs +1 -0
- package/dist/packem_shared/tools-CFdbSZHO.mjs +2 -0
- package/package.json +18 -5
- package/dist/packem_shared/READ_ONLY_TOOL_DEFINITIONS-B5x61zt4.mjs +0 -145
- package/dist/packem_shared/connectStdio-mHv2dT3u.mjs +0 -66
- package/dist/packem_shared/createMcpFetchHandler-CGqlLHxj.mjs +0 -14
- package/dist/packem_shared/createPaidMcpServer-S7RdldZo.mjs +0 -93
|
@@ -1,66 +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 { LunoraError } from '@lunora/errors';
|
|
6
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
-
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
-
import { toolDefinitions, callTool } from './READ_ONLY_TOOL_DEFINITIONS-B5x61zt4.mjs';
|
|
10
|
-
|
|
11
|
-
const resolveVersion = () => {
|
|
12
|
-
try {
|
|
13
|
-
let directory = dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
15
|
-
try {
|
|
16
|
-
const raw = readFileSync(join(directory, "package.json"), "utf8");
|
|
17
|
-
const pkg = JSON.parse(raw);
|
|
18
|
-
if (pkg.name === "@lunora/mcp" && typeof pkg.version === "string" && pkg.version.length > 0) {
|
|
19
|
-
return pkg.version;
|
|
20
|
-
}
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
const parent = dirname(directory);
|
|
24
|
-
if (parent === directory) {
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
directory = parent;
|
|
28
|
-
}
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
return "0.0.0";
|
|
32
|
-
};
|
|
33
|
-
const SERVER_INFO = { name: "lunora", version: resolveVersion() };
|
|
34
|
-
const resolveClient = (options) => {
|
|
35
|
-
if (options.client !== void 0) {
|
|
36
|
-
return options.client;
|
|
37
|
-
}
|
|
38
|
-
if (options.url === void 0) {
|
|
39
|
-
throw new LunoraError("INTERNAL", "createLunoraMcpServer requires either a `client` or a `url`");
|
|
40
|
-
}
|
|
41
|
-
const client = new LunoraClient({ fetch: options.fetch, url: options.url });
|
|
42
|
-
if (options.token !== void 0) {
|
|
43
|
-
client.setAuthToken(options.token);
|
|
44
|
-
}
|
|
45
|
-
return client;
|
|
46
|
-
};
|
|
47
|
-
const createLunoraMcpServer = (options) => {
|
|
48
|
-
const client = resolveClient(options);
|
|
49
|
-
const allowWrites = options.allowWrites ?? false;
|
|
50
|
-
const server = new Server(SERVER_INFO, { capabilities: { tools: {} } });
|
|
51
|
-
server.setRequestHandler(ListToolsRequestSchema, () => {
|
|
52
|
-
return { tools: [...toolDefinitions(allowWrites)] };
|
|
53
|
-
});
|
|
54
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
55
|
-
const result = await callTool(client, request.params.name, request.params.arguments ?? {}, allowWrites);
|
|
56
|
-
return result;
|
|
57
|
-
});
|
|
58
|
-
return server;
|
|
59
|
-
};
|
|
60
|
-
const connectStdio = async (options) => {
|
|
61
|
-
const server = createLunoraMcpServer(options);
|
|
62
|
-
await server.connect(new StdioServerTransport());
|
|
63
|
-
return server;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export { connectStdio, createLunoraMcpServer };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
2
|
-
import { createLunoraMcpServer } from './connectStdio-mHv2dT3u.mjs';
|
|
3
|
-
|
|
4
|
-
const serveStateless = async (server, request, options) => {
|
|
5
|
-
const transport = new WebStandardStreamableHTTPServerTransport({ enableJsonResponse: true, sessionIdGenerator: void 0 });
|
|
6
|
-
await server.connect(transport);
|
|
7
|
-
const response = await transport.handleRequest(request, options);
|
|
8
|
-
transport.close().catch(() => void 0);
|
|
9
|
-
server.close().catch(() => void 0);
|
|
10
|
-
return response;
|
|
11
|
-
};
|
|
12
|
-
const createMcpFetchHandler = (options) => (request) => serveStateless(createLunoraMcpServer(options), request);
|
|
13
|
-
|
|
14
|
-
export { createMcpFetchHandler, serveStateless };
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { createChargeMiddleware } from '@lunora/x402/charge';
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
-
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
-
import { serveStateless } from './createMcpFetchHandler-CGqlLHxj.mjs';
|
|
6
|
-
|
|
7
|
-
const DEFAULT_SERVER_INFO = { name: "lunora-paid-mcp", version: "0.0.0" };
|
|
8
|
-
const CALL_TOOL_METHOD = "tools/call";
|
|
9
|
-
const callToolName = (message) => {
|
|
10
|
-
if (typeof message !== "object" || message === null) {
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
13
|
-
const { method, params } = message;
|
|
14
|
-
if (method !== CALL_TOOL_METHOD || typeof params !== "object" || params === null) {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
const { name } = params;
|
|
18
|
-
return typeof name === "string" ? name : void 0;
|
|
19
|
-
};
|
|
20
|
-
const refuseBatch = () => Response.json({ error: "A JSON-RPC batch may not reference a paid MCP tool; send paid tools/call requests individually." }, { status: 400 });
|
|
21
|
-
const createPaidMcpServer = (config) => {
|
|
22
|
-
const tools = /* @__PURE__ */ new Map();
|
|
23
|
-
const prices = /* @__PURE__ */ new Map();
|
|
24
|
-
const middlewareByTool = /* @__PURE__ */ new Map();
|
|
25
|
-
const serverInfo = config.serverInfo ?? DEFAULT_SERVER_INFO;
|
|
26
|
-
const register = (options, handler, price) => {
|
|
27
|
-
if (tools.has(options.name)) {
|
|
28
|
-
throw new LunoraError("BAD_REQUEST", `MCP tool "${options.name}" is already registered.`);
|
|
29
|
-
}
|
|
30
|
-
const definition = { description: options.description, inputSchema: options.inputSchema, name: options.name };
|
|
31
|
-
if (options.annotations !== void 0) {
|
|
32
|
-
definition.annotations = options.annotations;
|
|
33
|
-
}
|
|
34
|
-
tools.set(options.name, { definition, handler });
|
|
35
|
-
if (price !== void 0) {
|
|
36
|
-
prices.set(options.name, price);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const buildServer = () => {
|
|
40
|
-
const server = new Server(serverInfo, { capabilities: { tools: {} } });
|
|
41
|
-
server.setRequestHandler(ListToolsRequestSchema, () => {
|
|
42
|
-
return { tools: [...tools.values()].map((entry) => entry.definition) };
|
|
43
|
-
});
|
|
44
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
45
|
-
const entry = tools.get(request.params.name);
|
|
46
|
-
if (entry === void 0) {
|
|
47
|
-
return { content: [{ text: `unknown tool: ${request.params.name}`, type: "text" }], isError: true };
|
|
48
|
-
}
|
|
49
|
-
const result = await entry.handler(request.params.arguments ?? {});
|
|
50
|
-
return result;
|
|
51
|
-
});
|
|
52
|
-
return server;
|
|
53
|
-
};
|
|
54
|
-
const gateFor = (name, price) => {
|
|
55
|
-
let pending = middlewareByTool.get(name);
|
|
56
|
-
if (pending === void 0) {
|
|
57
|
-
pending = createChargeMiddleware({ ...config.charge, price }, { resource: name }).catch((error) => {
|
|
58
|
-
middlewareByTool.delete(name);
|
|
59
|
-
throw error;
|
|
60
|
-
});
|
|
61
|
-
middlewareByTool.set(name, pending);
|
|
62
|
-
}
|
|
63
|
-
return pending;
|
|
64
|
-
};
|
|
65
|
-
const fetchHandler = async (request) => {
|
|
66
|
-
let parsedBody;
|
|
67
|
-
try {
|
|
68
|
-
parsedBody = await request.clone().json();
|
|
69
|
-
} catch {
|
|
70
|
-
parsedBody = void 0;
|
|
71
|
-
}
|
|
72
|
-
const dispatch = () => serveStateless(buildServer(), request, parsedBody === void 0 ? void 0 : { parsedBody });
|
|
73
|
-
if (Array.isArray(parsedBody)) {
|
|
74
|
-
return parsedBody.some((message) => prices.has(callToolName(message) ?? "")) ? refuseBatch() : dispatch();
|
|
75
|
-
}
|
|
76
|
-
const name = callToolName(parsedBody);
|
|
77
|
-
const price = name === void 0 ? void 0 : prices.get(name);
|
|
78
|
-
if (name === void 0 || price === void 0) {
|
|
79
|
-
return dispatch();
|
|
80
|
-
}
|
|
81
|
-
const middleware = await gateFor(name, price);
|
|
82
|
-
return middleware.handle(request, dispatch);
|
|
83
|
-
};
|
|
84
|
-
const paidTool = (options, handler) => {
|
|
85
|
-
register(options, handler, options.price);
|
|
86
|
-
};
|
|
87
|
-
const tool = (options, handler) => {
|
|
88
|
-
register(options, handler);
|
|
89
|
-
};
|
|
90
|
-
return { fetchHandler, paidTool, tool };
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { createPaidMcpServer };
|