search1api-mcp 0.11.0 → 0.12.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 +3 -1
- package/build/config.js +5 -1
- package/build/http.js +60 -30
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The official MCP server for [Search1API](https://s1.dev/?utm_source=mcp) — web
|
|
|
10
10
|
## Authentication
|
|
11
11
|
|
|
12
12
|
- OAuth-aware clients can connect to the Remote MCP URL directly, then sign in and approve access in the browser.
|
|
13
|
-
- Existing integrations can continue to use an API key from the [Search1API dashboard](https://
|
|
13
|
+
- Existing integrations can continue to use an API key from the [Search1API dashboard](https://app.s1.dev).
|
|
14
14
|
- Every MCP request — including tool discovery (`initialize`, `tools/list`) — requires a credential. Unauthenticated requests draw the OAuth challenge, which is how clients trigger sign-in; pre-connect inspection is served by the static [server card](https://mcp.search1api.com/.well-known/mcp/server-card.json) instead.
|
|
15
15
|
|
|
16
16
|
## Quick Start (Remote MCP)
|
|
@@ -153,6 +153,8 @@ If you prefer to run the server locally, use Node.js 20 or newer with npx — no
|
|
|
153
153
|
}
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
To send requests through another Search1API-compatible address, such as a New API gateway with the Search1API plugin, set `SEARCH1API_API_URL` to that base URL (for example `https://your-gateway.example.com/search1api`) and `SEARCH1API_KEY` to the key that address accepts.
|
|
157
|
+
|
|
156
158
|
For self-hosted HTTP deployments behind a proxy, add any internal hostnames
|
|
157
159
|
that reach the Node.js process to the comma-separated `MCP_ALLOWED_HOSTS`
|
|
158
160
|
environment variable. `mcp.search1api.com` and localhost addresses are allowed
|
package/build/config.js
CHANGED
|
@@ -33,8 +33,12 @@ else {
|
|
|
33
33
|
log('API key located successfully.');
|
|
34
34
|
}
|
|
35
35
|
// API configuration
|
|
36
|
+
// SEARCH1API_API_URL points the tools at another Search1API-compatible base
|
|
37
|
+
// URL, such as a New API gateway with the Search1API plugin
|
|
38
|
+
// (https://your-gateway.example.com/search1api). The remote server reads the
|
|
39
|
+
// same variable.
|
|
36
40
|
export const API_CONFIG = {
|
|
37
|
-
BASE_URL: 'https://api.search1api.com',
|
|
41
|
+
BASE_URL: (process.env.SEARCH1API_API_URL?.trim() || 'https://api.search1api.com').replace(/\/+$/, ''),
|
|
38
42
|
DEFAULT_QUERY: 'latest news in the world',
|
|
39
43
|
ENDPOINTS: {
|
|
40
44
|
SEARCH: '/search',
|
package/build/http.js
CHANGED
|
@@ -46,41 +46,71 @@ export async function validateCredential(credential) {
|
|
|
46
46
|
}
|
|
47
47
|
return { credential, principal };
|
|
48
48
|
}
|
|
49
|
-
//
|
|
50
|
-
// again.
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
49
|
+
// How long a validation result is reused before the credential is checked
|
|
50
|
+
// again. Every MCP exchange carries the credential, and connected clients keep
|
|
51
|
+
// exchanging even when idle (re-discovery, reconnects, SSE attempts), so
|
|
52
|
+
// checking each one turned the API's /usage into its busiest endpoint: about
|
|
53
|
+
// 33k checks a day against about 1k tool calls. A minute collapses a client's
|
|
54
|
+
// bursts and most of its idle polling.
|
|
55
|
+
//
|
|
56
|
+
// Rejections: clients holding a dead token keep retrying (one ping every few
|
|
57
|
+
// seconds, indefinitely); matches the gateway's own cache of failed tokens.
|
|
58
|
+
// Acceptances: a revoked key, a disabled account or an expired OAuth token
|
|
59
|
+
// can still open a connection for up to this long. Tool calls are unaffected:
|
|
60
|
+
// the API authenticates and bills every one of them itself.
|
|
61
|
+
const ACCEPTED_CREDENTIAL_TTL_MS = 60_000;
|
|
54
62
|
const REJECTED_CREDENTIAL_TTL_MS = 60_000;
|
|
55
|
-
const
|
|
63
|
+
const CREDENTIAL_CACHE_MAX_ENTRIES = 10_000;
|
|
56
64
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
65
|
+
* Reuse validation results for a short time, keyed by the credential's hash.
|
|
66
|
+
*
|
|
67
|
+
* Both outcomes are cached, each for its own TTL. Validation outages (thrown
|
|
68
|
+
* errors) are never cached. Concurrent checks of the same credential share a
|
|
69
|
+
* single upstream call, since a client's exchanges often arrive together.
|
|
60
70
|
*/
|
|
61
|
-
export function
|
|
62
|
-
const
|
|
71
|
+
export function cacheCredentialValidation(validator, { acceptedTtlMs = ACCEPTED_CREDENTIAL_TTL_MS, rejectedTtlMs = REJECTED_CREDENTIAL_TTL_MS, maxEntries = CREDENTIAL_CACHE_MAX_ENTRIES, now = Date.now, } = {}) {
|
|
72
|
+
const cache = new Map();
|
|
73
|
+
const inFlight = new Map();
|
|
74
|
+
const remember = (key, principal) => {
|
|
75
|
+
const ttlMs = principal === null ? rejectedTtlMs : acceptedTtlMs;
|
|
76
|
+
if (ttlMs <= 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
cache.delete(key);
|
|
80
|
+
// Map keeps insertion order, so the first key is the oldest entry.
|
|
81
|
+
if (cache.size >= maxEntries) {
|
|
82
|
+
const oldest = cache.keys().next().value;
|
|
83
|
+
if (oldest !== undefined) {
|
|
84
|
+
cache.delete(oldest);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
cache.set(key, { expiresAt: now() + ttlMs, principal });
|
|
88
|
+
};
|
|
63
89
|
return async (credential) => {
|
|
64
90
|
const key = createHash("sha256").update(credential).digest("hex");
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
if (expiresAt > now()) {
|
|
68
|
-
return null
|
|
91
|
+
const cached = cache.get(key);
|
|
92
|
+
if (cached !== undefined) {
|
|
93
|
+
if (cached.expiresAt > now()) {
|
|
94
|
+
return cached.principal === null
|
|
95
|
+
? null
|
|
96
|
+
: { credential, principal: cached.principal };
|
|
69
97
|
}
|
|
70
|
-
|
|
98
|
+
cache.delete(key);
|
|
71
99
|
}
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
if (rejectedUntil.size >= maxEntries) {
|
|
76
|
-
const oldest = rejectedUntil.keys().next().value;
|
|
77
|
-
if (oldest !== undefined) {
|
|
78
|
-
rejectedUntil.delete(oldest);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
rejectedUntil.set(key, now() + ttlMs);
|
|
100
|
+
const pending = inFlight.get(key);
|
|
101
|
+
if (pending) {
|
|
102
|
+
return pending;
|
|
82
103
|
}
|
|
83
|
-
|
|
104
|
+
const check = validator(credential)
|
|
105
|
+
.then((authenticated) => {
|
|
106
|
+
remember(key, authenticated?.principal ?? null);
|
|
107
|
+
return authenticated;
|
|
108
|
+
})
|
|
109
|
+
.finally(() => {
|
|
110
|
+
inFlight.delete(key);
|
|
111
|
+
});
|
|
112
|
+
inFlight.set(key, check);
|
|
113
|
+
return check;
|
|
84
114
|
};
|
|
85
115
|
}
|
|
86
116
|
/**
|
|
@@ -88,8 +118,8 @@ export function cacheRejectedCredentials(validator, { ttlMs = REJECTED_CREDENTIA
|
|
|
88
118
|
*
|
|
89
119
|
* A single v2 handler serves the 2026-07-28 protocol and the SDK's default
|
|
90
120
|
* stateless 2025 fallback. Every presented credential is validated per
|
|
91
|
-
* exchange, so no credential or principal
|
|
92
|
-
* session. Every exchange requires a credential: the 401 + WWW-Authenticate
|
|
121
|
+
* exchange (through a one-minute result cache), so no credential or principal
|
|
122
|
+
* is retained in a server-side MCP session. Every exchange requires a credential: the 401 + WWW-Authenticate
|
|
93
123
|
* challenge on the first unauthenticated request is what spec-compliant
|
|
94
124
|
* clients treat as the trigger to start the OAuth flow, and serving
|
|
95
125
|
* discovery anonymously would leave clients that equate "tools listed" with
|
|
@@ -97,7 +127,7 @@ export function cacheRejectedCredentials(validator, { ttlMs = REJECTED_CREDENTIA
|
|
|
97
127
|
*/
|
|
98
128
|
export function createHttpApp(options = {}) {
|
|
99
129
|
const app = express();
|
|
100
|
-
const credentialValidator =
|
|
130
|
+
const credentialValidator = cacheCredentialValidation(options.validateCredential ?? validateCredential);
|
|
101
131
|
const authorizationServer = normalizeAuthorizationServer(options.authorizationServer ??
|
|
102
132
|
process.env.OAUTH_AUTHORIZATION_SERVER ??
|
|
103
133
|
DEFAULT_AUTHORIZATION_SERVER);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "search1api-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"mcpName": "io.github.superagents-lab/search1api",
|
|
5
5
|
"description": "A Model Context Protocol (MCP) server that provides search and crawl functionality using Search1API",
|
|
6
6
|
"private": false,
|
package/server.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "https://github.com/superagents-lab/search1api-mcp",
|
|
17
17
|
"source": "github"
|
|
18
18
|
},
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.12.0",
|
|
20
20
|
"remotes": [
|
|
21
21
|
{
|
|
22
22
|
"type": "streamable-http",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
{
|
|
28
28
|
"registryType": "npm",
|
|
29
29
|
"identifier": "search1api-mcp",
|
|
30
|
-
"version": "0.
|
|
30
|
+
"version": "0.12.0",
|
|
31
31
|
"transport": {
|
|
32
32
|
"type": "stdio"
|
|
33
33
|
},
|