Skip to content

fix: change safesearch parameter type from string to number - #48

Merged
ihor-sokoliuk merged 2 commits into
mainfrom
copilot/fix-searxng-parameter-issue
Feb 18, 2026
Merged

fix: change safesearch parameter type from string to number#48
ihor-sokoliuk merged 2 commits into
mainfrom
copilot/fix-searxng-parameter-issue

Conversation

Copilot AI commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

MCP SDK validates tool arguments against the JSON schema before the handler runs. safesearch was defined as type: "string" with enum: ["0", "1", "2"], but LLMs send numeric values, causing schema validation to fail:

Failed to parse arguments for tool "searxng_web_search": params.safesearch is not of a type(s) string params.safesearch is not one of enum values: 0,1,2

Changed safesearch to type: "number" with enum: [0, 1, 2] across the stack:

  • src/types.ts — Schema type stringnumber, enum ["0","1","2"][0,1,2], TypeScript type updated
  • src/search.ts — Function signature safesearch?: stringnumber, validation against numeric enum, .toString() for URL param serialization
  • src/resources.ts — Help text updated to reflect numeric values
  • __tests__/unit/search.test.ts — Test passes numeric 1 instead of string '1'
// before
safesearch: { type: "string", enum: ["0", "1", "2"], default: "0" }

// after
safesearch: { type: "number", enum: [0, 1, 2], default: 0 }

This aligns with the SearXNG API (which accepts numeric safesearch) and the README (which already documented it as number).

Original prompt

This section details on the original issue you should resolve

<issue_title>Issue with parameters</issue_title>
<issue_description>> Failed to parse arguments for tool "searxng_web_search": params.safesearch is not of a type(s) string params.safesearch is not one of enum values: 0,1,2

<tool_call>searxng_web_search <arg_key>query</arg_key> <arg_value>top headlines</arg_value> <arg_key>pageno</arg_key> <arg_value>1</arg_value> <arg_key>time_range</arg_key> <arg_value>day</arg_value> <arg_key>language</arg_key> <arg_value>en</arg_value> <arg_key>safesearch</arg_key> <arg_value>1</arg_value> </tool_call>

Looks like there is a casting issue with the MCP server.</issue_description>

<agent_instructions>Probably a parameter validation or an API call issue. Please check SearXNG API call documentation for details</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The safesearch parameter was defined as type "string" with enum ["0", "1", "2"]
in the JSON schema. LLMs naturally send numeric values (0, 1, 2) which caused
MCP SDK schema validation to fail with: "params.safesearch is not of a type(s)
string params.safesearch is not one of enum values: 0,1,2"

Changed to type "number" with enum [0, 1, 2] to match what LLMs send and
what the SearXNG API expects.

Co-authored-by: ihor-sokoliuk <17313213+ihor-sokoliuk@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parameter parsing issue for searxng_web_search tool fix: change safesearch parameter type from string to number Feb 18, 2026
Copilot AI requested a review from ihor-sokoliuk February 18, 2026 23:06
@ihor-sokoliuk

Copy link
Copy Markdown
Owner

@copilot, what parameter type does the SearXNG server API endpoint expect to receive? Is it a number or a string?

Copilot AI commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, what parameter type does the SearXNG server API endpoint expect to receive? Is it a number or a string?

The SearXNG /search API expects safesearch as an integer value (0, 1, or 2) per the official docs. Since it's sent as an HTTP query parameter (e.g., ?safesearch=1), it's technically a string on the wire, but the API semantically treats it as a number.

Our code handles the conversion correctly at search.ts:72 — we accept a number from the LLM via the MCP schema, then call .toString() when setting the URL search parameter. This matches how pageno (also a number) is already handled on line 58.

@ihor-sokoliuk
ihor-sokoliuk marked this pull request as ready for review February 18, 2026 23:09
Copilot AI review requested due to automatic review settings February 18, 2026 23:09
@ihor-sokoliuk
ihor-sokoliuk merged commit e084e96 into main Feb 18, 2026
1 check passed
@ihor-sokoliuk
ihor-sokoliuk deleted the copilot/fix-searxng-parameter-issue branch February 18, 2026 23:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MCP tool argument schema validation failures by changing the safesearch parameter from a string enum ("0" | "1" | "2") to a numeric enum (0 | 1 | 2) throughout the SDK surface and implementation, aligning with typical LLM outputs and the SearXNG API.

Changes:

  • Update searxng_web_search input schema and TS types to treat safesearch as a number enum.
  • Update performWebSearch to accept numeric safesearch, validate it against [0,1,2], and serialize it for URL query params.
  • Update help text and unit test to use numeric safesearch.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/types.ts Switches schema/type for safesearch to numeric enum in the tool input schema and TS arg typing.
src/search.ts Updates performWebSearch signature and URL param construction for numeric safesearch.
src/resources.ts Updates usage/help text to document numeric safesearch values.
__tests__/unit/search.test.ts Adjusts test callsite to pass numeric safesearch and still assert correct URL serialization.
Comments suppressed due to low confidence (1)

src/types.ts:24

  • isSearXNGWebSearchArgs now advertises safesearch?: number, but the guard only validates query and will return true even if safesearch is provided with a non-number type. This makes the type predicate unsound and can lead to silently ignoring user-provided safesearch values at runtime. Consider extending this guard to validate (and ideally range-check) optional fields like pageno, time_range, language, and safesearch when they are present.
export function isSearXNGWebSearchArgs(args: unknown): args is {
  query: string;
  pageno?: number;
  time_range?: string;
  language?: string;
  safesearch?: number;
} {
  return (
    typeof args === "object" &&
    args !== null &&
    "query" in args &&
    typeof (args as { query: string }).query === "string"
  );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/search.ts
Comment on lines 18 to 22
pageno: number = 1,
time_range?: string,
language: string = "all",
safesearch?: string
safesearch?: number
) {

Copilot AI Feb 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing safesearch to a number, the existing logging code inside this function uses a truthiness check (safesearch ? ...) when building searchParams, which will treat the valid value 0 as “not set” and omit it from logs. Use an explicit safesearch !== undefined check so 0 is logged correctly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with parameters

3 participants