@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,254 @@
|
|
|
1
|
+
// packages/mcp/src/identity.ts
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
var manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
4
|
+
var identity = Object.freeze({
|
|
5
|
+
name: manifest.name,
|
|
6
|
+
version: manifest.version,
|
|
7
|
+
adapter: "mcp"
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// packages/mcp/src/config.ts
|
|
11
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
12
|
+
import { isAbsolute } from "node:path";
|
|
13
|
+
|
|
14
|
+
// src/core/defaults.ts
|
|
15
|
+
function tuningDefaults() {
|
|
16
|
+
return {
|
|
17
|
+
searchWebSearch: { enabled: false, engine: "auto", maxResults: 8, reasoning: "minimal" },
|
|
18
|
+
defaultUrls: 10,
|
|
19
|
+
maxUrls: 20,
|
|
20
|
+
cacheDir: ".search",
|
|
21
|
+
extractMaxChars: 15e4,
|
|
22
|
+
fetchTimeoutMs: 2e4,
|
|
23
|
+
fetchConcurrency: 4,
|
|
24
|
+
extractionConcurrency: 4,
|
|
25
|
+
extractionMaxTokens: 3e3,
|
|
26
|
+
collationMaxTokens: 4e3,
|
|
27
|
+
browserFingerprint: "chrome_145",
|
|
28
|
+
disableLlmsFullDiscovery: false,
|
|
29
|
+
disableTelemetry: false,
|
|
30
|
+
llmTimeoutMs: 9e4,
|
|
31
|
+
llmRetryAttempts: 3,
|
|
32
|
+
retryBaseDelayMs: 1500,
|
|
33
|
+
retryMaxDelayMs: 2e4,
|
|
34
|
+
searchRetryAttempts: 2,
|
|
35
|
+
minRequestIntervalMs: 0,
|
|
36
|
+
httpProxy: void 0
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// packages/mcp/src/config.ts
|
|
41
|
+
function object(value, label) {
|
|
42
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
43
|
+
throw new Error(`${label} must be an object`);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function keys(value, allowed, label) {
|
|
47
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
48
|
+
throw new Error(`${label} contains an unknown key`);
|
|
49
|
+
}
|
|
50
|
+
function text(value, label) {
|
|
51
|
+
if (typeof value !== "string" || !value.trim() || value !== value.trim() || /[\x00-\x1f\x7f]/.test(value))
|
|
52
|
+
throw new Error(`${label} must be a nonempty, trimmed string without control characters`);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function integer(value, min, max, label) {
|
|
56
|
+
if (!Number.isSafeInteger(value) || value < min || value > max)
|
|
57
|
+
throw new Error(`${label} must be an integer between ${min} and ${max}`);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function choice(value, allowed, label) {
|
|
61
|
+
if (typeof value !== "string" || !allowed.includes(value))
|
|
62
|
+
throw new Error(`${label} has an unsupported value`);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
function bool(value, label) {
|
|
66
|
+
if (typeof value !== "boolean") throw new Error(`${label} must be boolean`);
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
function validateCacheDir(value) {
|
|
70
|
+
const path = text(value, "tuning.cacheDir");
|
|
71
|
+
if (isAbsolute(path) || path.includes("\\") || path.includes(":") || path.split("/").some((part) => !part || part === "." || part === ".."))
|
|
72
|
+
throw new Error("tuning.cacheDir must be a workspace-relative directory without traversal");
|
|
73
|
+
return path;
|
|
74
|
+
}
|
|
75
|
+
function model(value, role) {
|
|
76
|
+
const obj = object(value, `models.${role}`);
|
|
77
|
+
keys(obj, ["provider", "model"], `models.${role}`);
|
|
78
|
+
choice(obj.provider, ["openrouter"], `models.${role}.provider`);
|
|
79
|
+
const id = text(obj.model, `models.${role}.model`);
|
|
80
|
+
if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.:-]+$/.test(id) || id.startsWith("openrouter/"))
|
|
81
|
+
throw new Error(`models.${role}.model must select a concrete provider/model identifier`);
|
|
82
|
+
return { provider: "openrouter", model: id };
|
|
83
|
+
}
|
|
84
|
+
var ranges = {
|
|
85
|
+
defaultUrls: [1, 100],
|
|
86
|
+
maxUrls: [1, 100],
|
|
87
|
+
extractMaxChars: [1, 2e6],
|
|
88
|
+
fetchTimeoutMs: [1, 6e5],
|
|
89
|
+
fetchConcurrency: [1, 32],
|
|
90
|
+
extractionConcurrency: [1, 32],
|
|
91
|
+
extractionMaxTokens: [16, 128e3],
|
|
92
|
+
collationMaxTokens: [16, 128e3],
|
|
93
|
+
llmTimeoutMs: [1, 6e5],
|
|
94
|
+
llmRetryAttempts: [1, 10],
|
|
95
|
+
retryBaseDelayMs: [0, 12e4],
|
|
96
|
+
retryMaxDelayMs: [0, 12e4],
|
|
97
|
+
searchRetryAttempts: [1, 10],
|
|
98
|
+
minRequestIntervalMs: [0, 12e4]
|
|
99
|
+
};
|
|
100
|
+
function validateDomains(value, label) {
|
|
101
|
+
if (!Array.isArray(value) || value.length > 100 || value.some(
|
|
102
|
+
(item) => typeof item !== "string" || !/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)*[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(
|
|
103
|
+
item
|
|
104
|
+
)
|
|
105
|
+
))
|
|
106
|
+
throw new Error(`${label} must contain hostnames, not URLs`);
|
|
107
|
+
return [...value];
|
|
108
|
+
}
|
|
109
|
+
function webSearch(value) {
|
|
110
|
+
const obj = object(value, "tuning.searchWebSearch");
|
|
111
|
+
keys(
|
|
112
|
+
obj,
|
|
113
|
+
[
|
|
114
|
+
"enabled",
|
|
115
|
+
"engine",
|
|
116
|
+
"maxResults",
|
|
117
|
+
"searchContextSize",
|
|
118
|
+
"allowedDomains",
|
|
119
|
+
"excludedDomains",
|
|
120
|
+
"reasoning"
|
|
121
|
+
],
|
|
122
|
+
"tuning.searchWebSearch"
|
|
123
|
+
);
|
|
124
|
+
const result = {
|
|
125
|
+
enabled: bool(obj.enabled, "searchWebSearch.enabled")
|
|
126
|
+
};
|
|
127
|
+
if (obj.engine !== void 0)
|
|
128
|
+
result.engine = choice(
|
|
129
|
+
obj.engine,
|
|
130
|
+
["auto", "native", "exa", "parallel", "perplexity", "firecrawl"],
|
|
131
|
+
"searchWebSearch.engine"
|
|
132
|
+
);
|
|
133
|
+
if (obj.maxResults !== void 0)
|
|
134
|
+
result.maxResults = integer(
|
|
135
|
+
obj.maxResults,
|
|
136
|
+
1,
|
|
137
|
+
result.engine === "perplexity" ? 20 : 25,
|
|
138
|
+
"searchWebSearch.maxResults"
|
|
139
|
+
);
|
|
140
|
+
if (obj.searchContextSize !== void 0)
|
|
141
|
+
result.searchContextSize = choice(
|
|
142
|
+
obj.searchContextSize,
|
|
143
|
+
["low", "medium", "high"],
|
|
144
|
+
"searchWebSearch.searchContextSize"
|
|
145
|
+
);
|
|
146
|
+
if (obj.reasoning !== void 0)
|
|
147
|
+
result.reasoning = choice(
|
|
148
|
+
obj.reasoning,
|
|
149
|
+
["minimal", "low", "medium", "high"],
|
|
150
|
+
"searchWebSearch.reasoning"
|
|
151
|
+
);
|
|
152
|
+
if (obj.allowedDomains !== void 0)
|
|
153
|
+
result.allowedDomains = validateDomains(obj.allowedDomains, "searchWebSearch.allowedDomains");
|
|
154
|
+
if (obj.excludedDomains !== void 0)
|
|
155
|
+
result.excludedDomains = validateDomains(
|
|
156
|
+
obj.excludedDomains,
|
|
157
|
+
"searchWebSearch.excludedDomains"
|
|
158
|
+
);
|
|
159
|
+
if (["perplexity", "firecrawl"].includes(result.engine ?? "") && result.allowedDomains?.length && result.excludedDomains?.length)
|
|
160
|
+
throw new Error("This search engine cannot combine allowed and excluded domains");
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
function freeze(value) {
|
|
164
|
+
if (value && typeof value === "object") {
|
|
165
|
+
for (const child of Object.values(value)) freeze(child);
|
|
166
|
+
Object.freeze(value);
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
async function parseConfig(value, workspace) {
|
|
171
|
+
const root = object(value, "configuration");
|
|
172
|
+
keys(root, ["providers", "models", "tuning"], "configuration");
|
|
173
|
+
const providers = object(root.providers, "providers");
|
|
174
|
+
keys(providers, ["openrouter"], "providers");
|
|
175
|
+
const provider = object(providers.openrouter, "providers.openrouter");
|
|
176
|
+
keys(provider, ["apiKeyEnv"], "providers.openrouter");
|
|
177
|
+
const apiKeyEnv = text(provider.apiKeyEnv, "providers.openrouter.apiKeyEnv");
|
|
178
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(apiKeyEnv))
|
|
179
|
+
throw new Error("apiKeyEnv must name an environment variable, not contain a credential");
|
|
180
|
+
const models = object(root.models, "models");
|
|
181
|
+
keys(models, ["search", "extract", "collate"], "models");
|
|
182
|
+
const tuning = root.tuning === void 0 ? {} : object(root.tuning, "tuning");
|
|
183
|
+
keys(
|
|
184
|
+
tuning,
|
|
185
|
+
[
|
|
186
|
+
...Object.keys(ranges),
|
|
187
|
+
"cacheDir",
|
|
188
|
+
"browserFingerprint",
|
|
189
|
+
"disableTelemetry",
|
|
190
|
+
"disableLlmsFullDiscovery",
|
|
191
|
+
"searchWebSearch"
|
|
192
|
+
],
|
|
193
|
+
"tuning"
|
|
194
|
+
);
|
|
195
|
+
const settings = {
|
|
196
|
+
...tuningDefaults(),
|
|
197
|
+
searchModel: model(models.search, "search"),
|
|
198
|
+
extractModel: model(models.extract, "extract"),
|
|
199
|
+
collateModel: model(models.collate, "collate")
|
|
200
|
+
};
|
|
201
|
+
for (const [key, [min, max]] of Object.entries(ranges)) {
|
|
202
|
+
if (tuning[key] !== void 0)
|
|
203
|
+
Object.assign(settings, { [key]: integer(tuning[key], min, max, `tuning.${key}`) });
|
|
204
|
+
}
|
|
205
|
+
if (tuning.cacheDir !== void 0) settings.cacheDir = validateCacheDir(tuning.cacheDir);
|
|
206
|
+
if (tuning.browserFingerprint !== void 0) {
|
|
207
|
+
settings.browserFingerprint = choice(
|
|
208
|
+
tuning.browserFingerprint,
|
|
209
|
+
["chrome_145"],
|
|
210
|
+
"tuning.browserFingerprint"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
for (const key of ["disableTelemetry", "disableLlmsFullDiscovery"])
|
|
214
|
+
if (tuning[key] !== void 0) settings[key] = bool(tuning[key], `tuning.${key}`);
|
|
215
|
+
if (tuning.searchWebSearch !== void 0)
|
|
216
|
+
settings.searchWebSearch = webSearch(tuning.searchWebSearch);
|
|
217
|
+
if (settings.defaultUrls > settings.maxUrls)
|
|
218
|
+
throw new Error("defaultUrls must not exceed maxUrls");
|
|
219
|
+
if (settings.retryBaseDelayMs > settings.retryMaxDelayMs)
|
|
220
|
+
throw new Error("retryBaseDelayMs must not exceed retryMaxDelayMs");
|
|
221
|
+
if (!settings.searchWebSearch.enabled && !["perplexity/sonar", "perplexity/sonar-pro", "perplexity/sonar-pro-search"].includes(
|
|
222
|
+
settings.searchModel.model
|
|
223
|
+
))
|
|
224
|
+
throw new Error(
|
|
225
|
+
"Search requires an explicitly enabled searchWebSearch tool or a supported Sonar search model"
|
|
226
|
+
);
|
|
227
|
+
if (!isAbsolute(text(workspace, "workspace")))
|
|
228
|
+
throw new Error("workspace must be an explicit absolute directory");
|
|
229
|
+
let canonical;
|
|
230
|
+
try {
|
|
231
|
+
canonical = await realpath(workspace);
|
|
232
|
+
if (!(await stat(canonical)).isDirectory()) throw new Error();
|
|
233
|
+
} catch {
|
|
234
|
+
throw new Error("workspace must be an existing readable directory");
|
|
235
|
+
}
|
|
236
|
+
return freeze({ workspace: canonical, apiKeyEnv, settings });
|
|
237
|
+
}
|
|
238
|
+
async function loadConfig(path, workspace) {
|
|
239
|
+
let value;
|
|
240
|
+
try {
|
|
241
|
+
value = JSON.parse(await readFile(path, "utf8"));
|
|
242
|
+
} catch {
|
|
243
|
+
throw new Error("Cannot read configuration: provide an explicit readable JSON file");
|
|
244
|
+
}
|
|
245
|
+
return parseConfig(value, workspace);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export {
|
|
249
|
+
identity,
|
|
250
|
+
validateCacheDir,
|
|
251
|
+
validateDomains,
|
|
252
|
+
parseConfig,
|
|
253
|
+
loadConfig
|
|
254
|
+
};
|