search1api-mcp 0.13.0 → 0.14.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/build/api.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { API_KEY, API_CONFIG } from './config.js';
2
2
  import { log } from './utils.js';
3
+ import { clientChannelHeaders } from './client-channel.js';
3
4
  /**
4
5
  * A non-2xx answer from the API. `status` and `body` let a caller tell, for
5
6
  * example, a failed deepcrawl task (a task payload sent with HTTP 500) from
@@ -51,6 +52,7 @@ async function request(method, endpoint, data, apiKey) {
51
52
  method,
52
53
  headers: {
53
54
  'Authorization': `Bearer ${key}`,
55
+ ...clientChannelHeaders(),
54
56
  ...(method === 'POST' && { 'Content-Type': 'application/json' }),
55
57
  },
56
58
  ...(method === 'POST' && { body: JSON.stringify(data) }),
@@ -0,0 +1,20 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { PACKAGE_VERSION } from "./version.js";
3
+ const current = new AsyncLocalStorage();
4
+ export function withClientChannel(channel, run) {
5
+ return current.run(channel, run);
6
+ }
7
+ // Printable ASCII only, so the value is always a valid header.
8
+ function headerValue(value) {
9
+ return value.replace(/[^\x20-\x7e]/g, "").trim().slice(0, 100);
10
+ }
11
+ export function clientChannelHeaders() {
12
+ const channel = current.getStore();
13
+ if (!channel)
14
+ return {};
15
+ const app = channel.app ? headerValue(channel.app) : "";
16
+ return {
17
+ "X-Search1API-Client": `${channel.transport}/${PACKAGE_VERSION}`,
18
+ ...(app ? { "X-Search1API-Client-App": app } : {}),
19
+ };
20
+ }
package/build/http.js CHANGED
@@ -24,7 +24,10 @@ const MCP_RESOURCE_METADATA = "https://mcp.search1api.com/.well-known/oauth-prot
24
24
  */
25
25
  export async function validateCredential(credential) {
26
26
  const response = await fetch(`${API_BASE_URL}/usage`, {
27
- headers: { Authorization: `Bearer ${credential}` },
27
+ headers: {
28
+ Authorization: `Bearer ${credential}`,
29
+ "X-Search1API-Client": `mcp-remote/${PACKAGE_VERSION}`,
30
+ },
28
31
  });
29
32
  if (response.status === 401 || response.status === 403) {
30
33
  return null;
@@ -135,7 +138,10 @@ export function createHttpApp(options = {}) {
135
138
  const allowedOriginHostnames = options.allowedOriginHostnames ?? configuredAllowedOriginHostnames();
136
139
  const validateHost = hostHeaderValidation(allowedHostnames);
137
140
  const validateOrigin = originValidation(allowedOriginHostnames);
138
- const mcpHandler = createMcpHandler(({ authInfo }) => createMcpServer(toolCredential(authInfo)), {
141
+ const mcpHandler = createMcpHandler(({ authInfo, requestInfo }) => createMcpServer(toolCredential(authInfo), {
142
+ transport: "mcp-remote",
143
+ userAgent: requestInfo?.headers.get("user-agent") ?? undefined,
144
+ }), {
139
145
  legacy: "stateless",
140
146
  onerror: (error) => log("MCP handler error:", error),
141
147
  });
package/build/server.js CHANGED
@@ -8,6 +8,7 @@ import { handleToolCall } from "./tools/handlers.js";
8
8
  import { ALL_TOOLS } from "./tools/index.js";
9
9
  import { MCP_APP_MIME_TYPE, SEARCH_UI_META, SEARCH_UI_URI, SEARCH_UI_COMPAT_URIS, readSearchUi, } from "./ui.js";
10
10
  import { formatError, log } from "./utils.js";
11
+ import { withClientChannel } from "./client-channel.js";
11
12
  import { PACKAGE_VERSION } from "./version.js";
12
13
  import { SERVER_DESCRIPTION, SERVER_ICONS } from "./branding.js";
13
14
  /** JSON-RPC error code this server uses for a missing or rejected credential. */
@@ -32,7 +33,9 @@ export function unauthenticatedCredential(message) {
32
33
  * once per stateless legacy HTTP request, or once per stdio connection.
33
34
  * All transports expose the same data tools and optional rendering tool.
34
35
  */
35
- export function createMcpServer(credential) {
36
+ export function createMcpServer(credential, channel = {
37
+ transport: "mcp-local",
38
+ }) {
36
39
  log("Creating Search1API MCP server");
37
40
  const server = new McpServer({
38
41
  name: "search1api",
@@ -58,7 +61,11 @@ export function createMcpServer(credential) {
58
61
  try {
59
62
  const bearerCredential = typeof credential === "function" ? credential() : credential;
60
63
  log(`Tool call received: ${tool.name}`);
61
- return await handleToolCall(tool.name, args, bearerCredential);
64
+ // clientInfo is per request on the 2026 era and per connection on
65
+ // stdio; a stateless legacy HTTP call has neither, so the MCP
66
+ // request's User-Agent stands in.
67
+ const app = server.server.getClientVersion()?.name ?? channel.userAgent;
68
+ return await withClientChannel({ transport: channel.transport, app }, () => handleToolCall(tool.name, args, bearerCredential));
62
69
  }
63
70
  catch (error) {
64
71
  throw normalizeProtocolError(`handling tool call ${tool.name}`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.13.0",
3
+ "version": "0.14.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.13.0",
19
+ "version": "0.14.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.13.0",
30
+ "version": "0.14.0",
31
31
  "transport": {
32
32
  "type": "stdio"
33
33
  },