Skip to content

Refactor (packages/core/src/tool/websearch.ts): Function with many parameters - #32

Open
AlNaimi7 wants to merge 2 commits into
CMU-17313Q:mainfrom
AlNaimi7:refactor/websearch-callmcp-parameters
Open

Refactor (packages/core/src/tool/websearch.ts): Function with many parameters#32
AlNaimi7 wants to merge 2 commits into
CMU-17313Q:mainfrom
AlNaimi7:refactor/websearch-callmcp-parameters

Conversation

@AlNaimi7

@AlNaimi7 AlNaimi7 commented Sep 2, 2026

Copy link
Copy Markdown

1. Issue

Link to the associated GitHub issue:

#29

Full path to the refactored file:

packages/core/src/tool/websearch.ts

What do you think this file does?

It implements opencode's built in 'websearch' tool. It runs a permission check on the query, sends a JSON RPC request to either the Exa or Parallel MCP backend, and returns the search text to the model.

What is the scope of your refactoring within that file?

Only the internal helper callMcp (line 152) and its two call sites inside the tool's execute closure. No schemas, exports or behaviors were modified.

Which Qlty-reported issue did you address?

Function with many parameters on callMcp, previously count = 6 (http, url, tool, args, value, headers).

2. Refactoring

How did the specific issue you chose impact the codebase's maintainability?

Six positional parameters made call sites fragile, since url and tool are both plain strings and swapping them would compile fine but only fail at run time. Any new caller also has to remember the exact order instead of reading named fields.

What changes did you make to resolve the issue?

Added an interface McpCallOptions<F> and replaced the six positional parameters with a single options object { http, url, tool, args, value, headers? }. Both call sites (Exa and Parallel) were updated to send named fields.

How do your changes improve maintainability? Did you consider alternatives?

Named arguments cannot be accidentally swapped, and order stops mattering if an optional field is added later. I considered splitting it into callExa and callParallel, but that would duplicate the shared request building, timeout and response parsing.

3. Validation

How did you validate that the change is correct?

packages/core/test/tool-websearch.test.ts passes 12/12 and exercises callMcp through both providers, asserting the request URL, headers, JSON RPC body, response parsing and failure paths, so a swapped argument would fail the suite. Coverage is 88.00% functions / 95.75% lines with only lines 73-81 (defaultConfigLayer) uncovered, and bunx oxlint on the file reports 0 warnings and 0 errors while the 698 warnings / 2 errors from repo wide bun lint are pre existing elsewhere.

Attach a screenshot of the test coverage showing the lines were executed by the tests.

Screenshot 2026-09-02 at 11 26 16 AM

Attach a screenshot showing the tests that cover the change passing during CI
Screenshot 2026-09-05 at 3 04 37 PM

Attach a screenshot of qlty smells --no-snippets packages/core/src/tool/websearch.ts showing fewer reported issues after the changes.

Screenshot 2026-09-02 at 11 22 50 AM

Local bun lint and bun test:

Screenshot 2026-09-02 at 11 25 53 AM Screenshot 2026-09-02 at 11 26 08 AM

Qlty flagged packages/core/src/tool/websearch.ts:152 as "Function with
many parameters (count = 6): callMcp" (http, url, tool, args, value,
headers). Replace the positional parameter list with a single
McpCallOptions<F> object and update both call sites (Exa and Parallel)
accordingly. Behavior is unchanged.

Validated with `qlty smells --no-snippets packages/core/src/tool/websearch.ts`,
which now reports no smells for the file (was 1 before). Covered by the
existing packages/core/test/tool-websearch.test.ts suite (12/12 passing),
which exercises callMcp indirectly through both providers, including
header/body/URL assembly, byte-limit truncation, and timeout handling.
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.

1 participant