search1api-mcp 0.6.0 → 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 CHANGED
@@ -11,7 +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
- - Tool calls always require a credential. Tool discovery (`initialize`, `tools/list`) is answered without one, so clients and directories can inspect the server before signing in.
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)
17
17
 
@@ -197,6 +197,7 @@ Get trending topics from popular platforms.
197
197
 
198
198
  ## Version History
199
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
200
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
201
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
202
203
  - v0.5.3: OAuth resource and tool metadata no longer require OIDC session scopes; Smithery and Glama registry badges added
package/build/http.js CHANGED
@@ -13,26 +13,6 @@ const DEFAULT_AUTHORIZATION_SERVER = "https://clerk.s1.dev";
13
13
  const OAUTH_DISCOVERY_CACHE_CONTROL = "public, max-age=60, s-maxage=60";
14
14
  const MCP_RESOURCE = "https://mcp.search1api.com/mcp";
15
15
  const MCP_RESOURCE_METADATA = "https://mcp.search1api.com/.well-known/oauth-protected-resource/mcp";
16
- /**
17
- * JSON-RPC methods that only return static server metadata.
18
- *
19
- * The tool and resource descriptors are already published in the repository
20
- * manifests, the server card, and the MCP registry, so answering them for an
21
- * anonymous caller discloses nothing new and lets directory scanners enumerate
22
- * the server without first completing an OAuth exchange. Every method that
23
- * spends credits or reaches the Search1API backend is deliberately absent.
24
- */
25
- const PUBLIC_MCP_METHODS = new Set([
26
- "initialize",
27
- "notifications/initialized",
28
- "ping",
29
- "server/discover",
30
- "tools/list",
31
- "prompts/list",
32
- "resources/list",
33
- "resources/templates/list",
34
- "resources/read",
35
- ]);
36
16
  /**
37
17
  * Validate both Clerk OAuth tokens and legacy Search1API API keys at the API.
38
18
  */
@@ -66,8 +46,11 @@ export async function validateCredential(credential) {
66
46
  * A single v2 handler serves the 2026-07-28 protocol and the SDK's default
67
47
  * stateless 2025 fallback. Every presented credential is validated per
68
48
  * exchange, so no credential or principal is retained in a server-side MCP
69
- * session. An exchange that presents no credential at all reaches only the
70
- * metadata methods in PUBLIC_MCP_METHODS.
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.
71
54
  */
72
55
  export function createHttpApp(options = {}) {
73
56
  const app = express();
@@ -103,9 +86,9 @@ export function createHttpApp(options = {}) {
103
86
  }
104
87
  res.redirect(301, target.toString());
105
88
  });
106
- // /mcp is a transport endpoint whose only anonymous answers are static
107
- // descriptors, so search engines gain nothing from walking this host. Keep
108
- // the OAuth discovery documents reachable for agents.
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
91
+ // discovery documents reachable for agents.
109
92
  app.get("/robots.txt", (_req, res) => {
110
93
  res
111
94
  .type("text/plain")
@@ -129,9 +112,10 @@ export function createHttpApp(options = {}) {
129
112
  .json(protectedResourceMetadata);
130
113
  });
131
114
  // A single static document for directories that read one URL rather than
132
- // speak MCP. /mcp now answers tools/list anonymously too, so this card is a
133
- // convenience rather than the only pre-connection description. It is built
134
- // from ALL_TOOLS, so neither surface can drift from the real tool set.
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.
135
119
  app.get("/.well-known/mcp/server-card.json", (_req, res) => {
136
120
  res
137
121
  .set("Cache-Control", OAUTH_DISCOVERY_CACHE_CONTROL)
@@ -182,7 +166,7 @@ export function createHttpApp(options = {}) {
182
166
  });
183
167
  app.use(express.json());
184
168
  app.all("/mcp", async (req, res) => {
185
- const outcome = await authenticateMcpRequest(req, res, credentialValidator, isPublicDiscovery(req));
169
+ const outcome = await authenticateMcpRequest(req, res, credentialValidator);
186
170
  if (outcome.status === "handled") {
187
171
  return;
188
172
  }
@@ -315,10 +299,11 @@ function challenge(res, message, error) {
315
299
  /**
316
300
  * Resolve the credential a tool handler is allowed to spend.
317
301
  *
318
- * Anonymous exchanges only ever reach metadata methods, so no tool handler
319
- * should observe one. Should a future routing change let a call through, fail
320
- * loudly here rather than let makeRequest fall back to the operator's own
321
- * SEARCH1API_KEY and bill an unauthenticated caller to us.
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.
322
307
  */
323
308
  function toolCredential(authInfo) {
324
309
  if (authInfo?.token) {
@@ -326,48 +311,13 @@ function toolCredential(authInfo) {
326
311
  }
327
312
  return unauthenticatedCredential("Authentication is required to call Search1API tools.");
328
313
  }
329
- /**
330
- * Collect every JSON-RPC method named by one HTTP exchange.
331
- *
332
- * The 2026-07-28 transport routes on the mcp-method header while the body
333
- * repeats the method, and a legacy batch names one per array entry; all of them
334
- * have to be public for the exchange to be. Returns null when any part of the
335
- * request names no method, so an unrecognised shape falls through to the
336
- * authenticated path instead of being mistaken for discovery.
337
- */
338
- function requestedMcpMethods(req) {
339
- const methods = [];
340
- const headerMethod = req.headers["mcp-method"];
341
- if (typeof headerMethod === "string" && headerMethod.trim()) {
342
- methods.push(headerMethod.trim());
343
- }
344
- const entries = Array.isArray(req.body) ? req.body : [req.body];
345
- for (const entry of entries) {
346
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
347
- return null;
348
- }
349
- const method = entry.method;
350
- if (typeof method !== "string" || !method) {
351
- return null;
352
- }
353
- methods.push(method);
354
- }
355
- return methods.length > 0 ? methods : null;
356
- }
357
- /** Whether this exchange may be served without any credential at all. */
358
- function isPublicDiscovery(req) {
359
- if (req.method !== "POST") {
360
- return false;
361
- }
362
- const methods = requestedMcpMethods(req);
363
- return (methods !== null && methods.every((method) => PUBLIC_MCP_METHODS.has(method)));
364
- }
365
- async function authenticateMcpRequest(req, res, credentialValidator, allowAnonymous) {
314
+ async function authenticateMcpRequest(req, res, credentialValidator) {
366
315
  const credential = extractCredential(req);
367
316
  if (!credential) {
368
- if (allowAnonymous) {
369
- return { status: "anonymous" };
370
- }
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.
371
321
  challenge(res, "Authentication is required. Use OAuth 2.1 discovery or provide a Search1API API key as a Bearer token.");
372
322
  return { status: "handled" };
373
323
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/superagents-lab/search1api-mcp",
8
8
  "source": "github"
9
9
  },
10
- "version": "0.6.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.6.0",
21
+ "version": "0.6.1",
22
22
  "transport": {
23
23
  "type": "stdio"
24
24
  },