search1api-mcp 0.5.4 → 0.6.1
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 +4 -0
- package/build/http.js +76 -23
- package/build/index.js +8 -4
- package/build/server.js +15 -0
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ The official MCP server for [Search1API](https://s1.dev/?utm_source=mcp) — web
|
|
|
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
13
|
- Existing integrations can continue to use an API key from the [Search1API dashboard](https://dashboard.search1api.com).
|
|
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.
|
|
14
15
|
|
|
15
16
|
## Quick Start (Remote MCP)
|
|
16
17
|
|
|
@@ -196,6 +197,9 @@ Get trending topics from popular platforms.
|
|
|
196
197
|
|
|
197
198
|
## Version History
|
|
198
199
|
|
|
200
|
+
- v0.6.1: Bug fix — MCP discovery (`initialize`, `tools/list`, `resources/*`, `prompts/list`, `server/discover`) requires a credential again. Serving it anonymously made clients that equate "tools listed" with "signed in" show a connected state with no way to trigger the OAuth flow; the 401 challenge now answers every unauthenticated request, restoring OAuth sign-in at connect time. Directory visibility is unchanged via the static server card and registry metadata
|
|
201
|
+
- v0.6.0: MCP discovery (`initialize`, `tools/list`, `resources/*`, `prompts/list`, `server/discover`) is served without a credential so clients and directories can enumerate tools before signing in; tool calls still require OAuth or an API key. Stdio mode starts without `SEARCH1API_KEY` and serves tool metadata, refusing only at call time. Malformed requests answer as JSON-RPC instead of an HTML error page
|
|
202
|
+
- v0.5.4: OAuth issuer moved to `clerk.s1.dev` and is configurable with `OAUTH_AUTHORIZATION_SERVER`; MCP server card published at `/.well-known/mcp/server-card.json`; OAuth discovery documents now send cache headers
|
|
199
203
|
- v0.5.3: OAuth resource and tool metadata no longer require OIDC session scopes; Smithery and Glama registry badges added
|
|
200
204
|
- v0.5.2: MCP `Origin` validation now runs before request parsing and authentication; self-hosted HTTP deployments can configure trusted browser origins with `MCP_ALLOWED_ORIGINS`
|
|
201
205
|
- v0.5.1: Documentation, LobeHub manifest, and MCP Registry metadata synchronized; `robots.txt` served on the transport host
|
package/build/http.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { hostHeaderValidation, originValidation, toNodeHandler, } from "@modelcontextprotocol/node";
|
|
5
|
-
import { createMcpHandler, } from "@modelcontextprotocol/server";
|
|
5
|
+
import { createMcpHandler, INTERNAL_ERROR, PARSE_ERROR, } from "@modelcontextprotocol/server";
|
|
6
6
|
import express from "express";
|
|
7
|
-
import { createMcpServer } from "./server.js";
|
|
7
|
+
import { createMcpServer, unauthenticatedCredential, UNAUTHENTICATED, } from "./server.js";
|
|
8
8
|
import { ALL_TOOLS } from "./tools/index.js";
|
|
9
9
|
import { PACKAGE_VERSION } from "./version.js";
|
|
10
10
|
import { log } from "./utils.js";
|
|
@@ -44,8 +44,13 @@ export async function validateCredential(credential) {
|
|
|
44
44
|
* Build the HTTP application without starting a listener.
|
|
45
45
|
*
|
|
46
46
|
* A single v2 handler serves the 2026-07-28 protocol and the SDK's default
|
|
47
|
-
* stateless 2025 fallback.
|
|
48
|
-
* so no credential or principal is retained in a server-side MCP
|
|
47
|
+
* stateless 2025 fallback. Every presented credential is validated per
|
|
48
|
+
* exchange, so no credential or principal is retained in a server-side MCP
|
|
49
|
+
* session. Every exchange requires a credential: the 401 + WWW-Authenticate
|
|
50
|
+
* challenge on the first unauthenticated request is what spec-compliant
|
|
51
|
+
* clients treat as the trigger to start the OAuth flow, and serving
|
|
52
|
+
* discovery anonymously would leave clients that equate "tools listed" with
|
|
53
|
+
* "signed in" stuck connected but unable to authorize.
|
|
49
54
|
*/
|
|
50
55
|
export function createHttpApp(options = {}) {
|
|
51
56
|
const app = express();
|
|
@@ -57,7 +62,7 @@ export function createHttpApp(options = {}) {
|
|
|
57
62
|
const allowedOriginHostnames = options.allowedOriginHostnames ?? configuredAllowedOriginHostnames();
|
|
58
63
|
const validateHost = hostHeaderValidation(allowedHostnames);
|
|
59
64
|
const validateOrigin = originValidation(allowedOriginHostnames);
|
|
60
|
-
const mcpHandler = createMcpHandler(({ authInfo }) => createMcpServer(authInfo
|
|
65
|
+
const mcpHandler = createMcpHandler(({ authInfo }) => createMcpServer(toolCredential(authInfo)), {
|
|
61
66
|
legacy: "stateless",
|
|
62
67
|
onerror: (error) => log("MCP handler error:", error),
|
|
63
68
|
});
|
|
@@ -81,8 +86,8 @@ export function createHttpApp(options = {}) {
|
|
|
81
86
|
}
|
|
82
87
|
res.redirect(301, target.toString());
|
|
83
88
|
});
|
|
84
|
-
// /mcp is a transport endpoint that answers
|
|
85
|
-
//
|
|
89
|
+
// /mcp is a transport endpoint that answers nothing without a credential,
|
|
90
|
+
// so search engines gain nothing from walking this host. Keep the OAuth
|
|
86
91
|
// discovery documents reachable for agents.
|
|
87
92
|
app.get("/robots.txt", (_req, res) => {
|
|
88
93
|
res
|
|
@@ -106,9 +111,11 @@ export function createHttpApp(options = {}) {
|
|
|
106
111
|
.type("application/json")
|
|
107
112
|
.json(protectedResourceMetadata);
|
|
108
113
|
});
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
114
|
+
// A single static document for directories that read one URL rather than
|
|
115
|
+
// speak MCP. The transport endpoint challenges every unauthenticated
|
|
116
|
+
// request so clients trigger OAuth at connect time, which makes this card
|
|
117
|
+
// the only pre-connection description of the tool set. It is built from
|
|
118
|
+
// ALL_TOOLS, so it cannot drift from the real tool set.
|
|
112
119
|
app.get("/.well-known/mcp/server-card.json", (_req, res) => {
|
|
113
120
|
res
|
|
114
121
|
.set("Cache-Control", OAUTH_DISCOVERY_CACHE_CONTROL)
|
|
@@ -159,18 +166,42 @@ export function createHttpApp(options = {}) {
|
|
|
159
166
|
});
|
|
160
167
|
app.use(express.json());
|
|
161
168
|
app.all("/mcp", async (req, res) => {
|
|
162
|
-
const
|
|
163
|
-
if (
|
|
169
|
+
const outcome = await authenticateMcpRequest(req, res, credentialValidator);
|
|
170
|
+
if (outcome.status === "handled") {
|
|
164
171
|
return;
|
|
165
172
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
if (outcome.status === "authenticated") {
|
|
174
|
+
const authInfo = {
|
|
175
|
+
token: outcome.credential.credential,
|
|
176
|
+
clientId: outcome.credential.principal,
|
|
177
|
+
scopes: [],
|
|
178
|
+
};
|
|
179
|
+
req.auth = authInfo;
|
|
180
|
+
}
|
|
172
181
|
await nodeHandler(req, res, req.body);
|
|
173
182
|
});
|
|
183
|
+
// Express renders an HTML page for anything that fails before a route runs --
|
|
184
|
+
// most often body-parser rejecting a malformed or oversized payload. MCP
|
|
185
|
+
// clients and directory validators only parse JSON-RPC, so shape it here.
|
|
186
|
+
app.use("/mcp", (error, _req, res, next) => {
|
|
187
|
+
if (res.headersSent) {
|
|
188
|
+
next(error);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
log("MCP request rejected before dispatch:", error);
|
|
192
|
+
const status = error.status ?? error.statusCode ?? 500;
|
|
193
|
+
const clientError = status >= 400 && status < 500;
|
|
194
|
+
res.status(clientError ? status : 500).json({
|
|
195
|
+
jsonrpc: "2.0",
|
|
196
|
+
error: {
|
|
197
|
+
code: clientError ? PARSE_ERROR : INTERNAL_ERROR,
|
|
198
|
+
message: clientError
|
|
199
|
+
? "The request body is not a valid JSON-RPC message."
|
|
200
|
+
: "The MCP request could not be processed.",
|
|
201
|
+
},
|
|
202
|
+
id: null,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
174
205
|
return {
|
|
175
206
|
app,
|
|
176
207
|
mcpHandler,
|
|
@@ -261,16 +292,38 @@ function challenge(res, message, error) {
|
|
|
261
292
|
res.set("WWW-Authenticate", `Bearer resource_metadata="${MCP_RESOURCE_METADATA}"${errorParameter}`);
|
|
262
293
|
res.status(401).json({
|
|
263
294
|
jsonrpc: "2.0",
|
|
264
|
-
error: { code:
|
|
295
|
+
error: { code: UNAUTHENTICATED, message },
|
|
265
296
|
id: null,
|
|
266
297
|
});
|
|
267
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Resolve the credential a tool handler is allowed to spend.
|
|
301
|
+
*
|
|
302
|
+
* Unauthenticated exchanges are answered 401 by authenticateMcpRequest and
|
|
303
|
+
* never reach the MCP handler, so no tool handler should observe one. Should a
|
|
304
|
+
* future routing change let a call through, fail loudly here rather than let
|
|
305
|
+
* makeRequest fall back to the operator's own SEARCH1API_KEY and bill an
|
|
306
|
+
* unauthenticated caller to us.
|
|
307
|
+
*/
|
|
308
|
+
function toolCredential(authInfo) {
|
|
309
|
+
if (authInfo?.token) {
|
|
310
|
+
return authInfo.token;
|
|
311
|
+
}
|
|
312
|
+
return unauthenticatedCredential("Authentication is required to call Search1API tools.");
|
|
313
|
+
}
|
|
268
314
|
async function authenticateMcpRequest(req, res, credentialValidator) {
|
|
269
315
|
const credential = extractCredential(req);
|
|
270
316
|
if (!credential) {
|
|
317
|
+
// The 401 + WWW-Authenticate challenge is the standardized trigger for
|
|
318
|
+
// the client-side OAuth flow; serving any method without a credential
|
|
319
|
+
// would leave clients that treat a successful connect as "signed in"
|
|
320
|
+
// with no way to start authorizing.
|
|
271
321
|
challenge(res, "Authentication is required. Use OAuth 2.1 discovery or provide a Search1API API key as a Bearer token.");
|
|
272
|
-
return
|
|
322
|
+
return { status: "handled" };
|
|
273
323
|
}
|
|
324
|
+
// A presented credential is validated even on a discovery method, so an
|
|
325
|
+
// expired token still draws the OAuth challenge when a client reconnects
|
|
326
|
+
// rather than surfacing as a failed tool call later in the session.
|
|
274
327
|
let authenticated;
|
|
275
328
|
try {
|
|
276
329
|
authenticated = await credentialValidator(credential);
|
|
@@ -285,13 +338,13 @@ async function authenticateMcpRequest(req, res, credentialValidator) {
|
|
|
285
338
|
},
|
|
286
339
|
id: null,
|
|
287
340
|
});
|
|
288
|
-
return
|
|
341
|
+
return { status: "handled" };
|
|
289
342
|
}
|
|
290
343
|
if (!authenticated) {
|
|
291
344
|
challenge(res, "The Bearer credential is invalid or expired.", "invalid_token");
|
|
292
|
-
return
|
|
345
|
+
return { status: "handled" };
|
|
293
346
|
}
|
|
294
|
-
return authenticated;
|
|
347
|
+
return { status: "authenticated", credential: authenticated };
|
|
295
348
|
}
|
|
296
349
|
function installGlobalErrorLogging() {
|
|
297
350
|
process.on("uncaughtException", (error) => {
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
3
3
|
import { API_KEY } from "./config.js";
|
|
4
|
-
import { createMcpServer } from "./server.js";
|
|
4
|
+
import { createMcpServer, unauthenticatedCredential } from "./server.js";
|
|
5
5
|
import { log } from "./utils.js";
|
|
6
6
|
function main() {
|
|
7
|
+
// Serve even without a key: clients and directory tooling routinely probe a
|
|
8
|
+
// freshly installed package for its tool list before any credential is
|
|
9
|
+
// configured, and exiting here leaves them with a dead pipe rather than an
|
|
10
|
+
// answer. Tool calls still refuse until SEARCH1API_KEY is set.
|
|
7
11
|
if (!API_KEY) {
|
|
8
|
-
log("SEARCH1API_KEY
|
|
9
|
-
process.exit(1);
|
|
12
|
+
log("SEARCH1API_KEY is not set; serving tool metadata only. Set it to run searches.");
|
|
10
13
|
}
|
|
11
14
|
log("Starting Search1API MCP server (stdio mode)");
|
|
12
|
-
const handle = serveStdio(() => createMcpServer(API_KEY
|
|
15
|
+
const handle = serveStdio(() => createMcpServer(API_KEY ??
|
|
16
|
+
unauthenticatedCredential("SEARCH1API_KEY is not set. Set it in the server environment to call Search1API tools.")), {
|
|
13
17
|
legacy: "serve",
|
|
14
18
|
onerror: (error) => log("MCP stdio error:", error),
|
|
15
19
|
});
|
package/build/server.js
CHANGED
|
@@ -4,6 +4,21 @@ import { handleToolCall } from "./tools/handlers.js";
|
|
|
4
4
|
import { ALL_TOOLS } from "./tools/index.js";
|
|
5
5
|
import { formatError, log } from "./utils.js";
|
|
6
6
|
import { PACKAGE_VERSION } from "./version.js";
|
|
7
|
+
/** JSON-RPC error code this server uses for a missing or rejected credential. */
|
|
8
|
+
export const UNAUTHENTICATED = -32001;
|
|
9
|
+
/**
|
|
10
|
+
* Build a credential provider that refuses instead of resolving.
|
|
11
|
+
*
|
|
12
|
+
* Both entry points serve tool metadata without a credential, so a tool handler
|
|
13
|
+
* can be reached with nothing to spend. Refusing here keeps makeRequest from
|
|
14
|
+
* falling back to the operator's own SEARCH1API_KEY and billing an
|
|
15
|
+
* unauthenticated caller's search to us.
|
|
16
|
+
*/
|
|
17
|
+
export function unauthenticatedCredential(message) {
|
|
18
|
+
return () => {
|
|
19
|
+
throw new ProtocolError(UNAUTHENTICATED, message);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Create one transport-neutral MCP server instance.
|
|
9
24
|
*
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"url": "https://github.com/superagents-lab/search1api-mcp",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.6.1",
|
|
11
11
|
"remotes": [
|
|
12
12
|
{
|
|
13
13
|
"type": "streamable-http",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
{
|
|
19
19
|
"registryType": "npm",
|
|
20
20
|
"identifier": "search1api-mcp",
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.6.1",
|
|
22
22
|
"transport": {
|
|
23
23
|
"type": "stdio"
|
|
24
24
|
},
|