search1api-mcp 0.5.0 → 0.5.2

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
@@ -128,14 +128,17 @@ If you prefer to run the server locally, use Node.js 20 or newer with npx — no
128
128
  For self-hosted HTTP deployments behind a proxy, add any internal hostnames
129
129
  that reach the Node.js process to the comma-separated `MCP_ALLOWED_HOSTS`
130
130
  environment variable. `mcp.search1api.com` and localhost addresses are allowed
131
- by default.
131
+ by default. Browser-based clients that send an `Origin` header must also have
132
+ their trusted origin hostnames added to the comma-separated
133
+ `MCP_ALLOWED_ORIGINS` variable. Requests from server-side MCP clients normally
134
+ omit `Origin` and do not require an entry.
132
135
 
133
136
  ## Tools
134
137
 
135
138
  ### search
136
- Search the web using Search1API. Results use the standard citable
137
- `id`/`title`/`url` shape expected by ChatGPT deep research and company
138
- knowledge.
139
+ Search the web using Search1API. Results include a citable
140
+ `id`/`title`/`url` structure. Pass a result URL to `crawl` when you need the
141
+ full page.
139
142
 
140
143
  | Parameter | Required | Default | Description |
141
144
  |-----------|----------|---------|-------------|
@@ -147,13 +150,6 @@ knowledge.
147
150
  | `exclude_sites` | No | [] | Sites to exclude |
148
151
  | `time_range` | No | - | day, month, year |
149
152
 
150
- ### fetch
151
- Retrieve the full readable contents of a result returned by `search`.
152
-
153
- | Parameter | Required | Description |
154
- |-----------|----------|-------------|
155
- | `id` | Yes | Result ID returned by `search` (the canonical page URL) |
156
-
157
153
  ### news
158
154
  Search for news articles.
159
155
 
@@ -191,8 +187,10 @@ Get trending topics from popular platforms.
191
187
 
192
188
  ## Version History
193
189
 
190
+ - 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`
191
+ - v0.5.1: Documentation, LobeHub manifest, and MCP Registry metadata synchronized; `robots.txt` served on the transport host
194
192
  - v0.5.0: MCP 2026-07-28 support with automatic protocol negotiation; stateless compatibility for 2025-era HTTP clients; request-level authentication
195
- - v0.4.0: Standard `search`/`fetch` compatibility, structured output schemas, OAuth security schemes, safety annotations, and Official MCP Registry metadata
193
+ - v0.4.0: Structured output schemas, OAuth security schemes, safety annotations, and Official MCP Registry metadata
196
194
  - v0.3.1: OAuth 2.1 support for Remote MCP; retired reasoning tool removed
197
195
  - v0.3.0: Remote MCP support via Streamable HTTP; per-session API key authentication
198
196
  - v0.2.0: Fallback `.env` support for LibreChat integration
package/build/http.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createHash } from "node:crypto";
3
3
  import { pathToFileURL } from "node:url";
4
- import { hostHeaderValidation, toNodeHandler, } from "@modelcontextprotocol/node";
4
+ import { hostHeaderValidation, originValidation, toNodeHandler, } from "@modelcontextprotocol/node";
5
5
  import { createMcpHandler, } from "@modelcontextprotocol/server";
6
6
  import express from "express";
7
7
  import { createMcpServer } from "./server.js";
@@ -48,7 +48,9 @@ export function createHttpApp(options = {}) {
48
48
  const app = express();
49
49
  const credentialValidator = options.validateCredential ?? validateCredential;
50
50
  const allowedHostnames = options.allowedHostnames ?? configuredAllowedHostnames();
51
+ const allowedOriginHostnames = options.allowedOriginHostnames ?? configuredAllowedOriginHostnames();
51
52
  const validateHost = hostHeaderValidation(allowedHostnames);
53
+ const validateOrigin = originValidation(allowedOriginHostnames);
52
54
  const mcpHandler = createMcpHandler(({ authInfo }) => createMcpServer(authInfo?.token), {
53
55
  legacy: "stateless",
54
56
  onerror: (error) => log("MCP handler error:", error),
@@ -73,6 +75,14 @@ export function createHttpApp(options = {}) {
73
75
  }
74
76
  res.redirect(301, target.toString());
75
77
  });
78
+ // /mcp is a transport endpoint that answers unauthenticated crawlers with
79
+ // 401, so search engines gain nothing from walking this host. Keep the OAuth
80
+ // discovery documents reachable for agents.
81
+ app.get("/robots.txt", (_req, res) => {
82
+ res
83
+ .type("text/plain")
84
+ .send(["User-agent: *", "Disallow: /", "Allow: /.well-known/", ""].join("\n"));
85
+ });
76
86
  const protectedResourceMetadata = {
77
87
  resource: MCP_RESOURCE,
78
88
  authorization_servers: [AUTHORIZATION_SERVER],
@@ -89,6 +99,12 @@ export function createHttpApp(options = {}) {
89
99
  app.get("/.well-known/oauth-authorization-server", (_req, res) => {
90
100
  res.redirect(302, `${AUTHORIZATION_SERVER}/.well-known/oauth-authorization-server`);
91
101
  });
102
+ app.use("/mcp", (req, res, next) => {
103
+ if (!validateOrigin(req, res)) {
104
+ return;
105
+ }
106
+ next();
107
+ });
92
108
  app.use(express.json());
93
109
  app.all("/mcp", async (req, res) => {
94
110
  const authenticated = await authenticateMcpRequest(req, res, credentialValidator);
@@ -124,6 +140,21 @@ function configuredAllowedHostnames() {
124
140
  ]),
125
141
  ];
126
142
  }
143
+ function configuredAllowedOriginHostnames() {
144
+ const configured = (process.env.MCP_ALLOWED_ORIGINS ?? "")
145
+ .split(",")
146
+ .map((hostname) => hostname.trim())
147
+ .filter(Boolean);
148
+ return [
149
+ ...new Set([
150
+ "mcp.search1api.com",
151
+ "localhost",
152
+ "127.0.0.1",
153
+ "[::1]",
154
+ ...configured,
155
+ ]),
156
+ ];
157
+ }
127
158
  /** Start the production HTTP listener. */
128
159
  export function startHttpServer(port = Number.parseInt(process.env.PORT || "3000", 10)) {
129
160
  const httpApp = createHttpApp();
@@ -1,12 +1,11 @@
1
1
  import { INVALID_PARAMS, ProtocolError, } from "@modelcontextprotocol/server";
2
2
  import { log } from "../utils.js";
3
3
  import { handleSearch } from "./search.js";
4
- import { handleFetch } from "./fetch.js";
5
4
  import { handleCrawl } from "./crawl.js";
6
5
  import { handleSitemap } from "./sitemap.js";
7
6
  import { handleNews } from "./news.js";
8
7
  import { handleTrending } from "./trending.js";
9
- import { SEARCH_TOOL, FETCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL, } from "./index.js";
8
+ import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL, } from "./index.js";
10
9
  /**
11
10
  * Dispatch request based on tool name
12
11
  * @param toolName Name of the tool
@@ -19,8 +18,6 @@ export async function handleToolCall(toolName, args, apiKey) {
19
18
  switch (toolName) {
20
19
  case SEARCH_TOOL.name:
21
20
  return await handleSearch(args, apiKey);
22
- case FETCH_TOOL.name:
23
- return await handleFetch(args, apiKey);
24
21
  case CRAWL_TOOL.name:
25
22
  return await handleCrawl(args, apiKey);
26
23
  case SITEMAP_TOOL.name:
@@ -57,25 +57,11 @@ const SEARCH_OUTPUT_SCHEMA = {
57
57
  },
58
58
  required: ["results"],
59
59
  };
60
- const FETCH_OUTPUT_SCHEMA = {
61
- type: "object",
62
- properties: {
63
- id: { type: "string" },
64
- title: { type: "string" },
65
- text: { type: "string" },
66
- url: { type: "string", format: "uri" },
67
- metadata: {
68
- type: "object",
69
- additionalProperties: true,
70
- },
71
- },
72
- required: ["id", "title", "text", "url"],
73
- };
74
60
  // Search tool definition
75
61
  export const SEARCH_TOOL = {
76
62
  name: "search",
77
63
  title: "Search the web",
78
- description: "Search the live public web when the user needs current information, sources, or research. Returns citable results with id, title, URL, and text. Pass a result id to fetch to retrieve the full page.",
64
+ description: "Search the live public web when the user needs current information, sources, or research. Returns citable results with id, title, URL, and text. Pass a result URL to crawl to retrieve the full page.",
79
65
  ...AUTHENTICATED_READ_ONLY_WEB,
80
66
  inputSchema: {
81
67
  type: "object",
@@ -129,24 +115,6 @@ export const SEARCH_TOOL = {
129
115
  },
130
116
  outputSchema: SEARCH_OUTPUT_SCHEMA,
131
117
  };
132
- // Fetch tool definition for ChatGPT deep research and company knowledge.
133
- export const FETCH_TOOL = {
134
- name: "fetch",
135
- title: "Fetch a search result",
136
- description: "Retrieve the full readable contents of a result returned by search. Pass the result id, which is the canonical page URL. Returns id, title, full text, URL, and metadata.",
137
- ...AUTHENTICATED_READ_ONLY_WEB,
138
- inputSchema: {
139
- type: "object",
140
- properties: {
141
- id: {
142
- type: "string",
143
- description: "Result id returned by search; for web results this is the canonical URL",
144
- },
145
- },
146
- required: ["id"],
147
- },
148
- outputSchema: FETCH_OUTPUT_SCHEMA,
149
- };
150
118
  // News tool definition
151
119
  export const NEWS_TOOL = {
152
120
  name: "news",
@@ -209,7 +177,7 @@ export const NEWS_TOOL = {
209
177
  export const CRAWL_TOOL = {
210
178
  name: "crawl",
211
179
  title: "Read a web page",
212
- description: "Extract the readable title and full text from a specific public URL supplied by the user. Use fetch instead when following a result returned by search.",
180
+ description: "Extract the readable title and full text from a public URL supplied by the user or returned by search.",
213
181
  ...AUTHENTICATED_READ_ONLY_WEB,
214
182
  inputSchema: {
215
183
  type: "object",
@@ -307,7 +275,6 @@ export const TRENDING_TOOL = {
307
275
  };
308
276
  export const ALL_TOOLS = [
309
277
  SEARCH_TOOL,
310
- FETCH_TOOL,
311
278
  NEWS_TOOL,
312
279
  CRAWL_TOOL,
313
280
  SITEMAP_TOOL,
package/build/types.js CHANGED
@@ -62,13 +62,6 @@ export function isValidSearchArgs(args) {
62
62
  }
63
63
  return true;
64
64
  }
65
- export function isValidFetchArgs(args) {
66
- if (typeof args !== "object" || args === null) {
67
- return false;
68
- }
69
- const { id } = args;
70
- return typeof id === "string" && id.trim().length > 0;
71
- }
72
65
  export function isValidCrawlArgs(args) {
73
66
  if (typeof args !== 'object' || args === null) {
74
67
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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.5.0",
10
+ "version": "0.5.2",
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.5.0",
21
+ "version": "0.5.2",
22
22
  "transport": {
23
23
  "type": "stdio"
24
24
  },
@@ -1,49 +0,0 @@
1
- import { INVALID_PARAMS, ProtocolError, } from "@modelcontextprotocol/server";
2
- import { makeRequest } from "../api.js";
3
- import { API_CONFIG } from "../config.js";
4
- import { isValidFetchArgs, } from "../types.js";
5
- import { formatError, log } from "../utils.js";
6
- /**
7
- * ChatGPT-compatible fetch implementation. Search result IDs are canonical
8
- * URLs, so fetch can pass the ID directly to the crawl endpoint.
9
- */
10
- export async function handleFetch(args, apiKey) {
11
- if (!isValidFetchArgs(args)) {
12
- throw new ProtocolError(INVALID_PARAMS, "Invalid fetch arguments");
13
- }
14
- const { id } = args;
15
- log("Fetching search result:", id);
16
- try {
17
- const response = await makeRequest(API_CONFIG.ENDPOINTS.CRAWL, { url: id }, apiKey);
18
- const result = {
19
- id,
20
- title: response.results.title,
21
- text: response.results.content,
22
- url: response.results.link || id,
23
- metadata: {
24
- source: "search1api",
25
- },
26
- };
27
- return {
28
- structuredContent: result,
29
- content: [
30
- {
31
- type: "text",
32
- text: JSON.stringify(result),
33
- },
34
- ],
35
- };
36
- }
37
- catch (error) {
38
- log("Fetch error:", error);
39
- return {
40
- content: [
41
- {
42
- type: "text",
43
- text: `Fetch API error: ${formatError(error)}`,
44
- },
45
- ],
46
- isError: true,
47
- };
48
- }
49
- }