@curio-data/mcp-intelli-search 0.15.0-alpha.0 → 0.16.0
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/README.md +448 -103
- package/dist/{chunk-V6E7CJEW.js → chunk-CMJ2LFUN.js} +531 -259
- package/dist/{chunk-5I6PWQPA.js → chunk-EHXBTGSE.js} +98 -14
- package/dist/cli.js +18 -3
- package/dist/runtime.js +4 -2
- package/dist/server.js +66 -27
- package/package.json +3 -3
|
@@ -9,7 +9,7 @@ var identity = Object.freeze({
|
|
|
9
9
|
|
|
10
10
|
// packages/mcp/src/config.ts
|
|
11
11
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
12
|
-
import { isAbsolute } from "node:path";
|
|
12
|
+
import { isAbsolute, resolve } from "node:path";
|
|
13
13
|
|
|
14
14
|
// src/core/defaults.ts
|
|
15
15
|
function tuningDefaults() {
|
|
@@ -167,7 +167,66 @@ function freeze(value) {
|
|
|
167
167
|
}
|
|
168
168
|
return value;
|
|
169
169
|
}
|
|
170
|
+
var ConfigurationError = class extends Error {
|
|
171
|
+
constructor(reason, message) {
|
|
172
|
+
super(message);
|
|
173
|
+
this.reason = reason;
|
|
174
|
+
this.name = "ConfigurationError";
|
|
175
|
+
}
|
|
176
|
+
reason;
|
|
177
|
+
};
|
|
178
|
+
function position(source, offset) {
|
|
179
|
+
const before = source.slice(0, Math.max(0, Math.min(offset, source.length)));
|
|
180
|
+
const lines = before.split("\n");
|
|
181
|
+
return { line: lines.length, column: lines[lines.length - 1].length + 1 };
|
|
182
|
+
}
|
|
183
|
+
function failureOffset(source) {
|
|
184
|
+
try {
|
|
185
|
+
JSON.parse(source);
|
|
186
|
+
return void 0;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const message = error instanceof Error ? error.message : "";
|
|
189
|
+
if (/Unexpected end/.test(message)) return void 0;
|
|
190
|
+
const offset = /at position (\d+)/.exec(message);
|
|
191
|
+
if (!offset) return -1;
|
|
192
|
+
const at = Number(offset[1]);
|
|
193
|
+
return at < source.length ? at : void 0;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function syntaxLocation(source) {
|
|
197
|
+
let offset = failureOffset(source);
|
|
198
|
+
if (offset === -1) {
|
|
199
|
+
let low = 1;
|
|
200
|
+
let high = source.length;
|
|
201
|
+
while (low < high) {
|
|
202
|
+
const middle = low + high >> 1;
|
|
203
|
+
if (failureOffset(source.slice(0, middle)) === void 0) low = middle + 1;
|
|
204
|
+
else high = middle;
|
|
205
|
+
}
|
|
206
|
+
offset = low - 1;
|
|
207
|
+
}
|
|
208
|
+
if (offset === void 0)
|
|
209
|
+
return `end of input (line ${position(source, source.trimEnd().length).line}); the file is incomplete`;
|
|
210
|
+
const { line, column } = position(source, offset);
|
|
211
|
+
return `line ${line}, column ${column}`;
|
|
212
|
+
}
|
|
213
|
+
async function resolveWorkspace(workspace) {
|
|
214
|
+
if (!isAbsolute(text(workspace, "workspace")))
|
|
215
|
+
throw new Error("workspace must be an explicit absolute directory");
|
|
216
|
+
let canonical;
|
|
217
|
+
try {
|
|
218
|
+
canonical = await realpath(workspace);
|
|
219
|
+
if (!(await stat(canonical)).isDirectory()) throw new Error();
|
|
220
|
+
} catch {
|
|
221
|
+
throw new Error("workspace must be an existing readable directory");
|
|
222
|
+
}
|
|
223
|
+
return canonical;
|
|
224
|
+
}
|
|
170
225
|
async function parseConfig(value, workspace) {
|
|
226
|
+
const { apiKeyEnv, settings } = parseDocument(value);
|
|
227
|
+
return freeze({ workspace: await resolveWorkspace(workspace), apiKeyEnv, settings });
|
|
228
|
+
}
|
|
229
|
+
function parseDocument(value) {
|
|
171
230
|
const root = object(value, "configuration");
|
|
172
231
|
keys(root, ["providers", "models", "tuning"], "configuration");
|
|
173
232
|
const providers = object(root.providers, "providers");
|
|
@@ -224,31 +283,56 @@ async function parseConfig(value, workspace) {
|
|
|
224
283
|
throw new Error(
|
|
225
284
|
"Search requires an explicitly enabled searchWebSearch tool or a supported Sonar search model"
|
|
226
285
|
);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
286
|
+
return { apiKeyEnv, settings };
|
|
287
|
+
}
|
|
288
|
+
async function loadConfig(file, workspace) {
|
|
289
|
+
const path = resolve(file).replace(/[\x00-\x1f\x7f]/g, "?");
|
|
290
|
+
let source;
|
|
230
291
|
try {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
292
|
+
source = await readFile(file, "utf8");
|
|
293
|
+
} catch (error) {
|
|
294
|
+
const code = error.code;
|
|
295
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
296
|
+
throw new ConfigurationError("missing", `Configuration file not found: ${path}`);
|
|
297
|
+
throw new ConfigurationError(
|
|
298
|
+
"unreadable",
|
|
299
|
+
code === "EISDIR" ? `Configuration path is a directory, not a file: ${path}` : code === "EACCES" || code === "EPERM" ? `Configuration file is not readable (permission denied): ${path}` : `Cannot read configuration file: ${path}`
|
|
300
|
+
);
|
|
235
301
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
302
|
+
if (source.startsWith("\uFEFF")) source = source.slice(1);
|
|
303
|
+
if (!source.trim())
|
|
304
|
+
throw new ConfigurationError("invalid-json", `Configuration file is empty: ${path}`);
|
|
239
305
|
let value;
|
|
240
306
|
try {
|
|
241
|
-
value = JSON.parse(
|
|
307
|
+
value = JSON.parse(source);
|
|
242
308
|
} catch {
|
|
243
|
-
throw new
|
|
309
|
+
throw new ConfigurationError(
|
|
310
|
+
"invalid-json",
|
|
311
|
+
`Configuration file is not valid JSON at ${syntaxLocation(source)}: ${path}`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
let parsed;
|
|
315
|
+
try {
|
|
316
|
+
parsed = parseDocument(value);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
throw new ConfigurationError(
|
|
319
|
+
"invalid",
|
|
320
|
+
`Invalid configuration in ${path}: ${error instanceof Error ? error.message : "unknown defect"}`
|
|
321
|
+
);
|
|
244
322
|
}
|
|
245
|
-
return
|
|
323
|
+
return freeze({
|
|
324
|
+
workspace: await resolveWorkspace(workspace),
|
|
325
|
+
apiKeyEnv: parsed.apiKeyEnv,
|
|
326
|
+
settings: parsed.settings
|
|
327
|
+
});
|
|
246
328
|
}
|
|
247
329
|
|
|
248
330
|
export {
|
|
249
331
|
identity,
|
|
250
332
|
validateCacheDir,
|
|
251
333
|
validateDomains,
|
|
334
|
+
ConfigurationError,
|
|
335
|
+
resolveWorkspace,
|
|
252
336
|
parseConfig,
|
|
253
337
|
loadConfig
|
|
254
338
|
};
|
package/dist/cli.js
CHANGED
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
installStdoutGuard
|
|
4
4
|
} from "./chunk-ZTHYRKI2.js";
|
|
5
5
|
import {
|
|
6
|
+
ConfigurationError,
|
|
6
7
|
identity,
|
|
7
|
-
loadConfig
|
|
8
|
-
|
|
8
|
+
loadConfig,
|
|
9
|
+
resolveWorkspace
|
|
10
|
+
} from "./chunk-EHXBTGSE.js";
|
|
9
11
|
|
|
10
12
|
// packages/mcp/src/cli.ts
|
|
11
13
|
import { parseArgs } from "node:util";
|
|
@@ -63,11 +65,24 @@ to standard error; standard output carries protocol messages only.
|
|
|
63
65
|
throw new Error(
|
|
64
66
|
"Explicit --config and --workspace are required (or their INTELLI_SEARCH_* environment equivalents)"
|
|
65
67
|
);
|
|
66
|
-
const config
|
|
68
|
+
const { config: file, workspace } = args;
|
|
67
69
|
if (args["check-config"]) {
|
|
70
|
+
await loadConfig(file, workspace);
|
|
68
71
|
process.stdout.write("Configuration is valid.\n");
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
74
|
+
await resolveWorkspace(workspace);
|
|
75
|
+
let config;
|
|
76
|
+
try {
|
|
77
|
+
config = await loadConfig(file, workspace);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (!(error instanceof ConfigurationError)) throw error;
|
|
80
|
+
process.stderr.write(
|
|
81
|
+
`[mcp-intelli-search] ${error.message}. Serving anyway: each tool call reports this and rereads the file until it loads
|
|
82
|
+
`
|
|
83
|
+
);
|
|
84
|
+
config = () => loadConfig(file, workspace);
|
|
85
|
+
}
|
|
71
86
|
installStdoutGuard();
|
|
72
87
|
const { startServer } = await import("./server.js");
|
|
73
88
|
await startServer(config);
|
package/dist/runtime.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StandaloneError,
|
|
3
3
|
createRuntime
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-CMJ2LFUN.js";
|
|
5
5
|
import {
|
|
6
|
+
ConfigurationError,
|
|
6
7
|
identity,
|
|
7
8
|
loadConfig,
|
|
8
9
|
parseConfig
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EHXBTGSE.js";
|
|
10
11
|
export {
|
|
12
|
+
ConfigurationError,
|
|
11
13
|
StandaloneError,
|
|
12
14
|
createRuntime,
|
|
13
15
|
identity,
|
package/dist/server.js
CHANGED
|
@@ -8,10 +8,11 @@ import {
|
|
|
8
8
|
extractSchema,
|
|
9
9
|
researchSchema,
|
|
10
10
|
searchSchema
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CMJ2LFUN.js";
|
|
12
12
|
import {
|
|
13
|
+
ConfigurationError,
|
|
13
14
|
identity
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-EHXBTGSE.js";
|
|
15
16
|
|
|
16
17
|
// packages/mcp/src/server.ts
|
|
17
18
|
import { McpServer, fromJsonSchema } from "@modelcontextprotocol/server";
|
|
@@ -90,11 +91,13 @@ var OperationQueue = class {
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
// packages/mcp/src/server.ts
|
|
94
|
+
var skillGuidance = "Before the first intelli-search call in a session, load the intelli-search skill if available (plugins expose it as intelli-search:intelli-search). If the host has no such skill, use the tool descriptions without blocking.";
|
|
95
|
+
var serverInstructions = "Use intelli-search for current web information. " + skillGuidance + " Start with intelli_search for factual questions, latest versions, release dates and brief lookups. It returns an answer with sources without the multi-page fetch, extraction and collation pipeline. If a search answer looks stale or its sources disagree on the current version, try one narrower intelli_search targeting official sources before escalating. Use intelli_research for comparisons, detailed analysis or when a search answer leaves a specific evidence gap requiring multiple pages. Do not expand a simple lookup into unrequested research. For research, supply a focusPrompt and set maxUrls to the smallest useful breadth (3 for targeted research). Use the returned summary; read cache files only when it is insufficient.";
|
|
93
96
|
var toolDefinitions = [
|
|
94
97
|
{
|
|
95
98
|
name: "intelli_search",
|
|
96
99
|
title: "Intelli Search",
|
|
97
|
-
description: "
|
|
100
|
+
description: "Start here for quick factual questions, latest model or package versions, release dates and brief lookups. Returns a grounded answer with source URLs without fetching and extracting each page. A request for current information or sources alone does not need intelli_research. Escalate to intelli_research only for detailed analysis, comparisons or a specific evidence gap requiring multiple pages. " + skillGuidance,
|
|
98
101
|
schema: searchSchema,
|
|
99
102
|
annotations: {
|
|
100
103
|
title: "Intelli Search",
|
|
@@ -106,7 +109,7 @@ var toolDefinitions = [
|
|
|
106
109
|
{
|
|
107
110
|
name: "intelli_extract",
|
|
108
111
|
title: "Intelli Extract",
|
|
109
|
-
description: "Extract query-relevant content from a web page, compressing the full page to the parts that matter for a given query. Always provide focusPrompt to guide extraction; without it the extraction is generic. Use this for individual pages you already have; for end-to-end research, use intelli_research.",
|
|
112
|
+
description: "Extract query-relevant content from a web page, compressing the full page to the parts that matter for a given query. Always provide focusPrompt to guide extraction; without it the extraction is generic. Use this for individual pages you already have; for end-to-end research, use intelli_research. " + skillGuidance,
|
|
110
113
|
schema: extractSchema,
|
|
111
114
|
annotations: {
|
|
112
115
|
title: "Intelli Extract",
|
|
@@ -118,12 +121,12 @@ var toolDefinitions = [
|
|
|
118
121
|
{
|
|
119
122
|
name: "intelli_collate",
|
|
120
123
|
title: "Intelli Collate",
|
|
121
|
-
description: "Deduplicate and synthesise multiple per-page extractions into a single concise summary. Writes results to the workspace cache for follow-up. Use this after extracting multiple pages with intelli_extract; for end-to-end research, use intelli_research.",
|
|
124
|
+
description: "Deduplicate and synthesise multiple per-page extractions into a single concise summary. Writes results to the workspace cache for follow-up. Use this after extracting multiple pages with intelli_extract; for end-to-end research, use intelli_research. Repeating a query on the same UTC date attempts to archive its earlier cached report, extractions and numbered sources to the lowest free numbered sibling folder (.1, then .2 and so on); archiving is best-effort and a failure lets the completed run replace files in place, so copy a report elsewhere if it must be retained. " + skillGuidance,
|
|
122
125
|
schema: collateSchema,
|
|
123
126
|
annotations: {
|
|
124
127
|
title: "Intelli Collate",
|
|
125
128
|
readOnlyHint: false,
|
|
126
|
-
destructiveHint:
|
|
129
|
+
destructiveHint: true,
|
|
127
130
|
idempotentHint: false,
|
|
128
131
|
openWorldHint: true
|
|
129
132
|
}
|
|
@@ -131,12 +134,12 @@ var toolDefinitions = [
|
|
|
131
134
|
{
|
|
132
135
|
name: "intelli_research",
|
|
133
136
|
title: "Intelli Research",
|
|
134
|
-
description: "
|
|
137
|
+
description: "Use for multi-page comparisons, detailed analysis or a specific evidence gap left by intelli_search. For a quick fact, latest model or package version, or release date, call intelli_search first, not this tool. Do not expand a simple lookup into unrequested research. This longer-running pipeline searches, fetches pages, extracts each page and collates the results; it can take minutes and incurs more provider calls than intelli_search. " + skillGuidance + " Writes results to the workspace cache; use the returned summary directly and read cached pages only when it is insufficient. Use maxUrls to control breadth: 3 for targeted, 10 (default) for broad, 16 for exhaustive. Always provide focusPrompt to guide extraction. All operations call external services and incur provider charges. Repeating a query on the same UTC date attempts to archive its cached report, extractions and numbered sources to the lowest free numbered sibling folder (.1, then .2 and so on); archiving is best-effort and a failure lets the completed run replace files in place, so copy a report elsewhere if it must be retained. A degraded repeat preserves the earlier successful report.",
|
|
135
138
|
schema: researchSchema,
|
|
136
139
|
annotations: {
|
|
137
140
|
title: "Intelli Research",
|
|
138
141
|
readOnlyHint: false,
|
|
139
|
-
destructiveHint:
|
|
142
|
+
destructiveHint: true,
|
|
140
143
|
idempotentHint: false,
|
|
141
144
|
openWorldHint: true
|
|
142
145
|
}
|
|
@@ -151,7 +154,34 @@ function errorResult(name, code, message) {
|
|
|
151
154
|
function successResult(result) {
|
|
152
155
|
return {
|
|
153
156
|
content: [{ type: "text", text: result.text }],
|
|
154
|
-
structuredContent: { outcome: result.outcome, details: result.details }
|
|
157
|
+
structuredContent: { outcome: result.outcome, text: result.text, details: result.details }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
var recoveryHint = "Create or repair the file, then call the tool again; the server rereads it on each call until it loads";
|
|
161
|
+
function lazyRuntime(load, options) {
|
|
162
|
+
let ready;
|
|
163
|
+
return () => {
|
|
164
|
+
if (!ready) {
|
|
165
|
+
const attempt = load().then((config) => createRuntime(config, options)).then(
|
|
166
|
+
(runtime) => {
|
|
167
|
+
process.stderr.write("[mcp-intelli-search] Configuration loaded\n");
|
|
168
|
+
return runtime;
|
|
169
|
+
},
|
|
170
|
+
(error) => {
|
|
171
|
+
if (error instanceof ConfigurationError)
|
|
172
|
+
throw new StandaloneError("CONFIGURATION", `${error.message}. ${recoveryHint}`);
|
|
173
|
+
throw new StandaloneError(
|
|
174
|
+
"WORKSPACE",
|
|
175
|
+
error instanceof Error ? error.message : "Workspace unavailable"
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
ready = attempt;
|
|
180
|
+
attempt.catch(() => {
|
|
181
|
+
if (ready === attempt) ready = void 0;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return ready;
|
|
155
185
|
};
|
|
156
186
|
}
|
|
157
187
|
function createProtocolServer(runtime, limits = defaultQueueLimits, onEnqueue) {
|
|
@@ -168,7 +198,11 @@ function createProtocolServer(runtime, limits = defaultQueueLimits, onEnqueue) {
|
|
|
168
198
|
},
|
|
169
199
|
onEnqueue
|
|
170
200
|
);
|
|
171
|
-
const
|
|
201
|
+
const resolveRuntime = typeof runtime === "function" ? runtime : () => Promise.resolve(runtime);
|
|
202
|
+
const server = new McpServer(
|
|
203
|
+
{ name: identity.name, version: identity.version },
|
|
204
|
+
{ instructions: serverInstructions }
|
|
205
|
+
);
|
|
172
206
|
for (const tool of toolDefinitions) {
|
|
173
207
|
server.registerTool(
|
|
174
208
|
tool.name,
|
|
@@ -190,21 +224,23 @@ function createProtocolServer(runtime, limits = defaultQueueLimits, onEnqueue) {
|
|
|
190
224
|
)
|
|
191
225
|
};
|
|
192
226
|
return queue.submit(
|
|
193
|
-
() =>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
void
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
227
|
+
() => resolveRuntime().then(
|
|
228
|
+
(ready) => ready.execute(tool.name, args, {
|
|
229
|
+
signal,
|
|
230
|
+
onProgress: token === void 0 ? void 0 : (progress) => {
|
|
231
|
+
void ctx.mcpReq.notify({
|
|
232
|
+
method: "notifications/progress",
|
|
233
|
+
params: {
|
|
234
|
+
progressToken: token,
|
|
235
|
+
progress: progress.pct,
|
|
236
|
+
total: 100,
|
|
237
|
+
message: progress.message
|
|
238
|
+
}
|
|
239
|
+
}).catch(() => {
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
).then(
|
|
208
244
|
(result) => successResult(result),
|
|
209
245
|
(error) => {
|
|
210
246
|
if (error instanceof StandaloneError)
|
|
@@ -226,7 +262,8 @@ function createProtocolServer(runtime, limits = defaultQueueLimits, onEnqueue) {
|
|
|
226
262
|
}
|
|
227
263
|
async function startServer(config, options = {}) {
|
|
228
264
|
const protocol = installStdoutGuard();
|
|
229
|
-
const
|
|
265
|
+
const runtimeOptions = { ...options, env: { ...options.env ?? process.env } };
|
|
266
|
+
const runtime = typeof config === "function" ? lazyRuntime(config, runtimeOptions) : await createRuntime(config, runtimeOptions);
|
|
230
267
|
const { server, queue, shutdown } = createProtocolServer(
|
|
231
268
|
runtime,
|
|
232
269
|
{
|
|
@@ -277,5 +314,7 @@ async function startServer(config, options = {}) {
|
|
|
277
314
|
}
|
|
278
315
|
export {
|
|
279
316
|
createProtocolServer,
|
|
280
|
-
|
|
317
|
+
lazyRuntime,
|
|
318
|
+
startServer,
|
|
319
|
+
successResult
|
|
281
320
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curio-data/mcp-intelli-search",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Standalone intelligent web research engine and Model Context Protocol stdio server.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "node ../../scripts/build-mcp.mjs",
|
|
30
30
|
"typecheck": "tsc -p tsconfig.json",
|
|
31
|
-
"test": "node
|
|
31
|
+
"test": "node ../../scripts/run-tests.mjs mcp",
|
|
32
32
|
"prepack": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/server": "^2.3.0",
|
|
36
|
-
"defuddle": "^0.
|
|
36
|
+
"defuddle": "^0.19.4",
|
|
37
37
|
"linkedom": "^0.18.12",
|
|
38
38
|
"typebox": "^1.3.7",
|
|
39
39
|
"wreq-js": "^2.3.0"
|