@curio-data/mcp-intelli-search 0.15.0-alpha.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/LICENSE +199 -0
- package/NOTICE +41 -0
- package/README.md +260 -0
- package/dist/chunk-5I6PWQPA.js +254 -0
- package/dist/chunk-V6E7CJEW.js +2505 -0
- package/dist/chunk-ZTHYRKI2.js +23 -0
- package/dist/cli.js +88 -0
- package/dist/runtime.js +16 -0
- package/dist/server.js +281 -0
- package/package.json +44 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// packages/mcp/src/stdout-guard.ts
|
|
2
|
+
import { Writable } from "node:stream";
|
|
3
|
+
var protocol;
|
|
4
|
+
function installStdoutGuard() {
|
|
5
|
+
if (protocol) return protocol;
|
|
6
|
+
const original = process.stdout.write.bind(process.stdout);
|
|
7
|
+
const divert = process.stderr.write.bind(
|
|
8
|
+
process.stderr
|
|
9
|
+
);
|
|
10
|
+
protocol = new Writable({
|
|
11
|
+
write(chunk, encoding, callback) {
|
|
12
|
+
original(chunk, encoding, callback);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
process.stdout.on("error", () => {
|
|
16
|
+
});
|
|
17
|
+
process.stdout.write = ((chunk, ...rest) => divert(chunk, ...rest));
|
|
18
|
+
return protocol;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
installStdoutGuard
|
|
23
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
installStdoutGuard
|
|
4
|
+
} from "./chunk-ZTHYRKI2.js";
|
|
5
|
+
import {
|
|
6
|
+
identity,
|
|
7
|
+
loadConfig
|
|
8
|
+
} from "./chunk-5I6PWQPA.js";
|
|
9
|
+
|
|
10
|
+
// packages/mcp/src/cli.ts
|
|
11
|
+
import { parseArgs } from "node:util";
|
|
12
|
+
function cliOptions(argv, env = process.env) {
|
|
13
|
+
const { values } = parseArgs({
|
|
14
|
+
args: argv,
|
|
15
|
+
strict: true,
|
|
16
|
+
allowPositionals: false,
|
|
17
|
+
options: {
|
|
18
|
+
config: { type: "string" },
|
|
19
|
+
workspace: { type: "string" },
|
|
20
|
+
help: { type: "boolean" },
|
|
21
|
+
version: { type: "boolean" },
|
|
22
|
+
"check-config": { type: "boolean" }
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
...values,
|
|
27
|
+
config: values.config ?? env.INTELLI_SEARCH_CONFIG,
|
|
28
|
+
workspace: values.workspace ?? env.INTELLI_SEARCH_WORKSPACE
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function main() {
|
|
32
|
+
let args;
|
|
33
|
+
try {
|
|
34
|
+
args = cliOptions(process.argv.slice(2));
|
|
35
|
+
} catch {
|
|
36
|
+
throw new Error("Invalid arguments. Run mcp-intelli-search --help");
|
|
37
|
+
}
|
|
38
|
+
if (args.help) {
|
|
39
|
+
process.stdout.write(
|
|
40
|
+
`Usage: mcp-intelli-search --config FILE --workspace ABSOLUTE_DIRECTORY
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--config FILE Explicit JSON configuration (or INTELLI_SEARCH_CONFIG)
|
|
44
|
+
--workspace DIR Existing absolute workspace (or INTELLI_SEARCH_WORKSPACE)
|
|
45
|
+
--check-config Validate configuration without inference or serving
|
|
46
|
+
--help Show this help
|
|
47
|
+
--version Show package version
|
|
48
|
+
|
|
49
|
+
Command-line values take precedence over environment values.
|
|
50
|
+
Without --check-config the executable serves the four intelli_* research tools
|
|
51
|
+
as a Model Context Protocol server over standard input/output. Diagnostics go
|
|
52
|
+
to standard error; standard output carries protocol messages only.
|
|
53
|
+
`
|
|
54
|
+
);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (args.version) {
|
|
58
|
+
process.stdout.write(`${identity.version}
|
|
59
|
+
`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!args.config || !args.workspace)
|
|
63
|
+
throw new Error(
|
|
64
|
+
"Explicit --config and --workspace are required (or their INTELLI_SEARCH_* environment equivalents)"
|
|
65
|
+
);
|
|
66
|
+
const config = await loadConfig(args.config, args.workspace);
|
|
67
|
+
if (args["check-config"]) {
|
|
68
|
+
process.stdout.write("Configuration is valid.\n");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
installStdoutGuard();
|
|
72
|
+
const { startServer } = await import("./server.js");
|
|
73
|
+
await startServer(config);
|
|
74
|
+
process.stderr.write(
|
|
75
|
+
`[mcp-intelli-search] ${identity.name} ${identity.version} serving stdio
|
|
76
|
+
`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
void main().catch((error) => {
|
|
80
|
+
process.stderr.write(
|
|
81
|
+
`mcp-intelli-search: ${error instanceof Error ? error.message : "Startup failed"}
|
|
82
|
+
`
|
|
83
|
+
);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
cliOptions
|
|
88
|
+
};
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StandaloneError,
|
|
3
|
+
createRuntime
|
|
4
|
+
} from "./chunk-V6E7CJEW.js";
|
|
5
|
+
import {
|
|
6
|
+
identity,
|
|
7
|
+
loadConfig,
|
|
8
|
+
parseConfig
|
|
9
|
+
} from "./chunk-5I6PWQPA.js";
|
|
10
|
+
export {
|
|
11
|
+
StandaloneError,
|
|
12
|
+
createRuntime,
|
|
13
|
+
identity,
|
|
14
|
+
loadConfig,
|
|
15
|
+
parseConfig
|
|
16
|
+
};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installStdoutGuard
|
|
3
|
+
} from "./chunk-ZTHYRKI2.js";
|
|
4
|
+
import {
|
|
5
|
+
StandaloneError,
|
|
6
|
+
collateSchema,
|
|
7
|
+
createRuntime,
|
|
8
|
+
extractSchema,
|
|
9
|
+
researchSchema,
|
|
10
|
+
searchSchema
|
|
11
|
+
} from "./chunk-V6E7CJEW.js";
|
|
12
|
+
import {
|
|
13
|
+
identity
|
|
14
|
+
} from "./chunk-5I6PWQPA.js";
|
|
15
|
+
|
|
16
|
+
// packages/mcp/src/server.ts
|
|
17
|
+
import { McpServer, fromJsonSchema } from "@modelcontextprotocol/server";
|
|
18
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
19
|
+
|
|
20
|
+
// packages/mcp/src/queue.ts
|
|
21
|
+
var defaultQueueLimits = Object.freeze({
|
|
22
|
+
maxConcurrent: 1,
|
|
23
|
+
maxQueued: 8
|
|
24
|
+
});
|
|
25
|
+
var OperationQueue = class {
|
|
26
|
+
constructor(limits, fallback, onEnqueue) {
|
|
27
|
+
this.limits = limits;
|
|
28
|
+
this.fallback = fallback;
|
|
29
|
+
this.onEnqueue = onEnqueue;
|
|
30
|
+
}
|
|
31
|
+
limits;
|
|
32
|
+
fallback;
|
|
33
|
+
onEnqueue;
|
|
34
|
+
active = 0;
|
|
35
|
+
closed = false;
|
|
36
|
+
pending = [];
|
|
37
|
+
running = /* @__PURE__ */ new Set();
|
|
38
|
+
submit(start, signal, factories = this.fallback) {
|
|
39
|
+
if (this.closed || signal.aborted) return Promise.resolve(factories.cancelled());
|
|
40
|
+
if (this.pending.length >= this.limits.maxQueued) return Promise.resolve(factories.busy());
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
const entry = {
|
|
43
|
+
signal,
|
|
44
|
+
start,
|
|
45
|
+
factories,
|
|
46
|
+
settle: resolve
|
|
47
|
+
};
|
|
48
|
+
signal.addEventListener(
|
|
49
|
+
"abort",
|
|
50
|
+
() => {
|
|
51
|
+
const index = this.pending.indexOf(entry);
|
|
52
|
+
if (index >= 0) {
|
|
53
|
+
this.pending.splice(index, 1);
|
|
54
|
+
resolve(factories.cancelled());
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{ once: true }
|
|
58
|
+
);
|
|
59
|
+
this.pending.push(entry);
|
|
60
|
+
this.onEnqueue?.();
|
|
61
|
+
this.drain();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
drain() {
|
|
65
|
+
while (!this.closed && this.active < this.limits.maxConcurrent && this.pending.length) {
|
|
66
|
+
const entry = this.pending.shift();
|
|
67
|
+
if (entry.signal.aborted) {
|
|
68
|
+
entry.settle(entry.factories.cancelled());
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
this.active++;
|
|
72
|
+
const task = entry.start().then(
|
|
73
|
+
(result) => entry.settle(result),
|
|
74
|
+
() => entry.settle(entry.factories.cancelled())
|
|
75
|
+
);
|
|
76
|
+
const tracked = task.finally(() => {
|
|
77
|
+
this.active--;
|
|
78
|
+
this.running.delete(tracked);
|
|
79
|
+
this.drain();
|
|
80
|
+
});
|
|
81
|
+
this.running.add(tracked);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Settles queued work as cancelled and waits for active work to finish. */
|
|
85
|
+
async close() {
|
|
86
|
+
this.closed = true;
|
|
87
|
+
for (const entry of this.pending.splice(0)) entry.settle(entry.factories.cancelled());
|
|
88
|
+
await Promise.allSettled([...this.running]);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// packages/mcp/src/server.ts
|
|
93
|
+
var toolDefinitions = [
|
|
94
|
+
{
|
|
95
|
+
name: "intelli_search",
|
|
96
|
+
title: "Intelli Search",
|
|
97
|
+
description: "Search the web and return a concise answer with source URLs. For multi-page deep research, use intelli_research instead.",
|
|
98
|
+
schema: searchSchema,
|
|
99
|
+
annotations: {
|
|
100
|
+
title: "Intelli Search",
|
|
101
|
+
readOnlyHint: true,
|
|
102
|
+
idempotentHint: false,
|
|
103
|
+
openWorldHint: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "intelli_extract",
|
|
108
|
+
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.",
|
|
110
|
+
schema: extractSchema,
|
|
111
|
+
annotations: {
|
|
112
|
+
title: "Intelli Extract",
|
|
113
|
+
readOnlyHint: true,
|
|
114
|
+
idempotentHint: false,
|
|
115
|
+
openWorldHint: true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "intelli_collate",
|
|
120
|
+
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.",
|
|
122
|
+
schema: collateSchema,
|
|
123
|
+
annotations: {
|
|
124
|
+
title: "Intelli Collate",
|
|
125
|
+
readOnlyHint: false,
|
|
126
|
+
destructiveHint: false,
|
|
127
|
+
idempotentHint: false,
|
|
128
|
+
openWorldHint: true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "intelli_research",
|
|
133
|
+
title: "Intelli Research",
|
|
134
|
+
description: "Search the web, fetch top results, extract relevant content from each page, and deduplicate into a concise summary. Writes all results to the workspace cache for follow-up; use the returned summary directly and read cached pages only when it is insufficient. This is the primary research tool; for quick factual lookups, use intelli_search instead. 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.",
|
|
135
|
+
schema: researchSchema,
|
|
136
|
+
annotations: {
|
|
137
|
+
title: "Intelli Research",
|
|
138
|
+
readOnlyHint: false,
|
|
139
|
+
destructiveHint: false,
|
|
140
|
+
idempotentHint: false,
|
|
141
|
+
openWorldHint: true
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
function errorResult(name, code, message) {
|
|
146
|
+
return {
|
|
147
|
+
isError: true,
|
|
148
|
+
content: [{ type: "text", text: `${name} failed (${code}): ${message}` }]
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function successResult(result) {
|
|
152
|
+
return {
|
|
153
|
+
content: [{ type: "text", text: result.text }],
|
|
154
|
+
structuredContent: { outcome: result.outcome, details: result.details }
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function createProtocolServer(runtime, limits = defaultQueueLimits, onEnqueue) {
|
|
158
|
+
const shutdown = new AbortController();
|
|
159
|
+
const queue = new OperationQueue(
|
|
160
|
+
limits,
|
|
161
|
+
{
|
|
162
|
+
cancelled: () => errorResult("operation", "CANCELLED", "Operation cancelled"),
|
|
163
|
+
busy: () => errorResult(
|
|
164
|
+
"operation",
|
|
165
|
+
"OPERATION",
|
|
166
|
+
"Server busy: too many queued operations; retry after a running operation completes"
|
|
167
|
+
)
|
|
168
|
+
},
|
|
169
|
+
onEnqueue
|
|
170
|
+
);
|
|
171
|
+
const server = new McpServer({ name: identity.name, version: identity.version });
|
|
172
|
+
for (const tool of toolDefinitions) {
|
|
173
|
+
server.registerTool(
|
|
174
|
+
tool.name,
|
|
175
|
+
{
|
|
176
|
+
title: tool.title,
|
|
177
|
+
description: tool.description,
|
|
178
|
+
inputSchema: fromJsonSchema(tool.schema),
|
|
179
|
+
annotations: tool.annotations
|
|
180
|
+
},
|
|
181
|
+
async (args, ctx) => {
|
|
182
|
+
const token = ctx.mcpReq._meta?.progressToken;
|
|
183
|
+
const signal = AbortSignal.any([ctx.mcpReq.signal, shutdown.signal]);
|
|
184
|
+
const factories = {
|
|
185
|
+
cancelled: () => errorResult(tool.name, "CANCELLED", "Operation cancelled"),
|
|
186
|
+
busy: () => errorResult(
|
|
187
|
+
tool.name,
|
|
188
|
+
"OPERATION",
|
|
189
|
+
"Server busy: too many queued operations; retry after a running operation completes"
|
|
190
|
+
)
|
|
191
|
+
};
|
|
192
|
+
return queue.submit(
|
|
193
|
+
() => runtime.execute(tool.name, args, {
|
|
194
|
+
signal,
|
|
195
|
+
onProgress: token === void 0 ? void 0 : (progress) => {
|
|
196
|
+
void ctx.mcpReq.notify({
|
|
197
|
+
method: "notifications/progress",
|
|
198
|
+
params: {
|
|
199
|
+
progressToken: token,
|
|
200
|
+
progress: progress.pct,
|
|
201
|
+
total: 100,
|
|
202
|
+
message: progress.message
|
|
203
|
+
}
|
|
204
|
+
}).catch(() => {
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}).then(
|
|
208
|
+
(result) => successResult(result),
|
|
209
|
+
(error) => {
|
|
210
|
+
if (error instanceof StandaloneError)
|
|
211
|
+
return errorResult(tool.name, error.code, error.message);
|
|
212
|
+
process.stderr.write(
|
|
213
|
+
`[mcp-intelli-search] unclassified ${tool.name} failure: ${error instanceof Error ? error.message : "unknown"}
|
|
214
|
+
`
|
|
215
|
+
);
|
|
216
|
+
return errorResult(tool.name, "OPERATION", "Operation failed");
|
|
217
|
+
}
|
|
218
|
+
),
|
|
219
|
+
signal,
|
|
220
|
+
factories
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return { server, queue, shutdown };
|
|
226
|
+
}
|
|
227
|
+
async function startServer(config, options = {}) {
|
|
228
|
+
const protocol = installStdoutGuard();
|
|
229
|
+
const runtime = await createRuntime(config, options);
|
|
230
|
+
const { server, queue, shutdown } = createProtocolServer(
|
|
231
|
+
runtime,
|
|
232
|
+
{
|
|
233
|
+
...defaultQueueLimits,
|
|
234
|
+
...options.queue
|
|
235
|
+
},
|
|
236
|
+
options.onEnqueue
|
|
237
|
+
);
|
|
238
|
+
const transport = new StdioServerTransport(process.stdin, protocol);
|
|
239
|
+
let closing;
|
|
240
|
+
let notifyClosed = () => {
|
|
241
|
+
};
|
|
242
|
+
const closed = new Promise((resolve) => {
|
|
243
|
+
notifyClosed = resolve;
|
|
244
|
+
});
|
|
245
|
+
const close = () => {
|
|
246
|
+
closing ??= (async () => {
|
|
247
|
+
shutdown.abort();
|
|
248
|
+
try {
|
|
249
|
+
await queue.close();
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
await server.close();
|
|
254
|
+
} catch {
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
process.stdin.destroy();
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
notifyClosed();
|
|
261
|
+
})();
|
|
262
|
+
return closing;
|
|
263
|
+
};
|
|
264
|
+
await server.connect(transport);
|
|
265
|
+
server.server.onclose = () => void close();
|
|
266
|
+
const hardExit = (signal) => {
|
|
267
|
+
const timer = setTimeout(() => process.exit(1), 1e4);
|
|
268
|
+
timer.unref();
|
|
269
|
+
void close().then(() => {
|
|
270
|
+
clearTimeout(timer);
|
|
271
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
process.once("SIGINT", () => hardExit("SIGINT"));
|
|
275
|
+
process.once("SIGTERM", () => hardExit("SIGTERM"));
|
|
276
|
+
return { close, closed };
|
|
277
|
+
}
|
|
278
|
+
export {
|
|
279
|
+
createProtocolServer,
|
|
280
|
+
startServer
|
|
281
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@curio-data/mcp-intelli-search",
|
|
3
|
+
"version": "0.15.0-alpha.0",
|
|
4
|
+
"description": "Standalone intelligent web research engine and Model Context Protocol stdio server.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"mcp-intelli-search": "dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
"./runtime": "./dist/runtime.js",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/Curio-Data/pi-intelli-search.git",
|
|
20
|
+
"directory": "packages/mcp"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"NOTICE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node ../../scripts/build-mcp.mjs",
|
|
30
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
31
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
32
|
+
"prepack": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@modelcontextprotocol/server": "^2.3.0",
|
|
36
|
+
"defuddle": "^0.16.0",
|
|
37
|
+
"linkedom": "^0.18.12",
|
|
38
|
+
"typebox": "^1.3.7",
|
|
39
|
+
"wreq-js": "^2.3.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@modelcontextprotocol/client": "^2.3.0"
|
|
43
|
+
}
|
|
44
|
+
}
|