@nite07/websearch-mcp 0.2.1 → 0.2.3
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 +29 -5
- package/README.zh.md +15 -0
- package/config.example.json +149 -3
- package/dist/live.d.ts +5 -0
- package/dist/live.js +14 -0
- package/dist/sdk.js +26 -2
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +39 -10
- package/dist/ui/page.html +460 -104
- package/dist/ui/server.js +22 -1
- package/dist/ui/state.d.ts +19 -1
- package/dist/ui/state.js +20 -1
- package/package.json +2 -2
package/dist/ui/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
2
|
import { networkInterfaces } from 'node:os';
|
|
3
|
-
import { catalog, SearchEngine } from '@nite07/search-core';
|
|
3
|
+
import { catalog, createPageFetchEngine, renderPageFetchReport, SearchEngine } from '@nite07/search-core';
|
|
4
4
|
import { credentialResolver, loadConfig } from '../config.js';
|
|
5
5
|
import { renderPage } from './page.js';
|
|
6
6
|
import { FailureLimiter, SessionStore, SESSION_COOKIE, cookieValue, sessionCookie } from './session.js';
|
|
@@ -183,6 +183,27 @@ export async function startUi(options) {
|
|
|
183
183
|
settings.log(`credential ${scope === 'browser' ? 'browser' : String(body.id)} ${body.remove === true ? 'removed' : 'saved'} from the page`);
|
|
184
184
|
return json(response, 200, { saved: true, revision: saved.revision, state: saved.state });
|
|
185
185
|
}
|
|
186
|
+
if (url.pathname === '/api/fetch-test' && method === 'POST') {
|
|
187
|
+
const body = (await readJson(request));
|
|
188
|
+
const format = body.format;
|
|
189
|
+
if (format !== 'html' && format !== 'markdown')
|
|
190
|
+
throw new SettingsError('A fetch test needs format "html" or "markdown"; there is no default.');
|
|
191
|
+
const target = typeof body.url === 'string' ? body.url.trim() : '';
|
|
192
|
+
if (!target)
|
|
193
|
+
throw new SettingsError('A fetch test needs a URL.');
|
|
194
|
+
const config = await loadConfig({ configPath: settings.configPath });
|
|
195
|
+
const engine = createPageFetchEngine(config.search, { resolveCredential: reference => credentialResolver(config)(reference) });
|
|
196
|
+
try {
|
|
197
|
+
// User-triggered only: nothing here runs on render or save. The log names the route and the
|
|
198
|
+
// stop reason, never the URL or the page content.
|
|
199
|
+
const result = await engine.fetchPage({ url: target, format }, AbortSignal.timeout(120_000));
|
|
200
|
+
settings.log(`page fetch test: route ${result.contentRoute ?? 'none'}, stop ${result.stopReason}, ok ${result.ok}`);
|
|
201
|
+
return json(response, 200, { ok: true, result, text: renderPageFetchReport(result) });
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
return json(response, 200, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
186
207
|
if (url.pathname === '/api/test' && method === 'POST') {
|
|
187
208
|
const body = (await readJson(request));
|
|
188
209
|
const backendId = typeof body.backendId === 'string' ? body.backendId : '';
|
package/dist/ui/state.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FETCH_BOUNDS } from '@nite07/search-core';
|
|
2
|
+
import type { AccessMode, BackendDefinition, ConfigIssue, FetchReadinessProblem, FetchReadinessProvider, SearchConfig } from '@nite07/search-core';
|
|
2
3
|
/** One credential row: never the value, only where it came from and how long it is. */
|
|
3
4
|
export interface CredentialState {
|
|
4
5
|
id: string;
|
|
@@ -23,6 +24,23 @@ export interface SettingsSnapshot {
|
|
|
23
24
|
};
|
|
24
25
|
/** Set when the file on disk does not validate; the page then opens on defaults so it can be repaired. */
|
|
25
26
|
loadError?: string;
|
|
27
|
+
/** Page fetching: verified providers, readiness reasons, and the shared editor vocabulary. */
|
|
28
|
+
fetch: {
|
|
29
|
+
providerId: string;
|
|
30
|
+
providers: FetchReadinessProvider[];
|
|
31
|
+
problems: FetchReadinessProblem[];
|
|
32
|
+
ready: boolean;
|
|
33
|
+
bounds: typeof FETCH_BOUNDS;
|
|
34
|
+
conditionTypes: readonly string[];
|
|
35
|
+
conditionFields: readonly string[];
|
|
36
|
+
matchOperators: readonly string[];
|
|
37
|
+
failureKinds: readonly string[];
|
|
38
|
+
presets: {
|
|
39
|
+
status: unknown;
|
|
40
|
+
cloudflare: unknown;
|
|
41
|
+
defaults: unknown;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
26
44
|
}
|
|
27
45
|
export interface SaveResult {
|
|
28
46
|
revision: string;
|
package/dist/ui/state.js
CHANGED
|
@@ -3,7 +3,7 @@ import { realpathSync } from 'node:fs';
|
|
|
3
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { basename, dirname, join } from 'node:path';
|
|
6
|
-
import { backendCredentialRef, browserCredentialRef, catalog, defaultConfig, parseConfig, validateConfig, } from '@nite07/search-core';
|
|
6
|
+
import { backendCredentialRef, browserCredentialRef, catalog, defaultConfig, CLOUDFLARE_CHALLENGE_PRESET, DEFAULT_FALLBACK_RULES, FETCH_BOUNDS, FETCH_CONDITION_FIELDS, FETCH_CONDITION_TYPES, FETCH_FAILURE_KINDS, FETCH_MATCH_OPERATORS, STATUS_ERROR_PRESET, fetchReadiness, fetchReadinessProviders, parseConfig, validateConfig, } from '@nite07/search-core';
|
|
7
7
|
export class SettingsError extends Error {
|
|
8
8
|
issues;
|
|
9
9
|
status;
|
|
@@ -183,6 +183,13 @@ export async function snapshot(path, env = process.env) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
const stored = raw?.credentials ?? {};
|
|
186
|
+
// Fetch readiness is a read-only projection: it never calls a provider and never spends a request.
|
|
187
|
+
const configured = (id) => {
|
|
188
|
+
const fromEnv = env[backendCredentialRef(id)];
|
|
189
|
+
return (typeof fromEnv === 'string' && fromEnv !== '') || (typeof stored[id] === 'string' && stored[id] !== '');
|
|
190
|
+
};
|
|
191
|
+
const fetchProviders = fetchReadinessProviders(config, catalog, configured);
|
|
192
|
+
const fetchProblems = fetchReadiness(config, fetchProviders);
|
|
186
193
|
return {
|
|
187
194
|
configPath: path,
|
|
188
195
|
revision: file?.revision ?? 'missing',
|
|
@@ -193,6 +200,18 @@ export async function snapshot(path, env = process.env) {
|
|
|
193
200
|
browser: credentialState('browser', browserCredentialRef(), null, stored, env),
|
|
194
201
|
compactByDefault: raw?.compactByDefault ?? false,
|
|
195
202
|
companion: { path: companionPath(path), active: Boolean(await readText(companionPath(path))) },
|
|
203
|
+
fetch: {
|
|
204
|
+
providerId: config.pageFetch.providerId,
|
|
205
|
+
providers: fetchProviders,
|
|
206
|
+
problems: fetchProblems,
|
|
207
|
+
ready: fetchProblems.length === 0,
|
|
208
|
+
bounds: FETCH_BOUNDS,
|
|
209
|
+
conditionTypes: FETCH_CONDITION_TYPES,
|
|
210
|
+
conditionFields: FETCH_CONDITION_FIELDS,
|
|
211
|
+
matchOperators: FETCH_MATCH_OPERATORS,
|
|
212
|
+
failureKinds: FETCH_FAILURE_KINDS,
|
|
213
|
+
presets: { status: STATUS_ERROR_PRESET, cloudflare: CLOUDFLARE_CHALLENGE_PRESET, defaults: DEFAULT_FALLBACK_RULES },
|
|
214
|
+
},
|
|
196
215
|
...(loadError ? { loadError } : {}),
|
|
197
216
|
};
|
|
198
217
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nite07/websearch-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "MCP server for multi-backend web search plus Reddit and X thread reading, built on @nite07/search-core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "nite07",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
46
|
-
"@nite07/search-core": "0.1
|
|
46
|
+
"@nite07/search-core": "0.2.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^22.10.2",
|