← Back to PRs

#13814: feat(web-search): add ZAI Search (zsearch) provider

by strelov1 open 2026-02-11 02:28 View on GitHub →
agents stale
## Summary - Add ZAI Search (`zsearch`) as a new `web_search` provider alongside Brave, Perplexity, and Grok - Implements the two-step MCP Streamable HTTP protocol: `initialize` to obtain `Mcp-Session-Id`, then `tools/call` with that session header - Supports freshness filters (mapped from Brave format), content size (`medium`/`high`), location (`cn`/`us`), and `baseUrl` override via config or `ZAI_SEARCH_BASE_URL` env var - API key resolved from config `tools.web.search.zsearch.apiKey` or `ZAI_API_KEY` / `Z_AI_API_KEY` env vars ## Changed files - `src/agents/tools/web-search.ts` — provider implementation, MCP session init, search execution - `src/config/types.tools.ts` — `zsearch` config type definition - `src/config/zod-schema.agent-runtime.ts` — Zod validation schema for `zsearch` config - `src/agents/tools/web-search.test.ts` — tests for freshness mapping - `src/config/config.web-search-provider.test.ts` — config validation tests - `.gitignore` — add `.idea/` ## Test plan - [x] Unit tests pass (34 tests across 2 files) - [x] Manual verification: MCP init + search call returns valid results - [ ] Integration test with live ZAI API key <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Added ZAI Search (`zsearch`) as a new web search provider alongside Brave, Perplexity, and Grok. The implementation follows the two-step MCP Streamable HTTP protocol with session initialization and subsequent search calls. **Key changes:** - Implemented MCP session management with `initialize` handshake to obtain session ID - Added freshness filter mapping from Brave format to ZAI format (`pd` → `oneDay`, etc.) - Supports content size (`medium`/`high`), location (`cn`/`us`), and custom `baseUrl` configuration - API key resolution from config or `ZAI_API_KEY`/`Z_AI_API_KEY` environment variables - Comprehensive test coverage for freshness mapping and config validation - Cache key includes provider-specific parameters (contentSize, location, freshness) - Proper error handling for JSON-RPC responses and tool errors The implementation is well-structured and follows existing patterns in the codebase for other search providers. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk - The implementation follows established patterns for other search providers, includes comprehensive tests, and handles errors properly. The only minor issue is a schema description that should be updated to reflect ZAI Search support for freshness filtering. The code is well-structured with proper session management, timeout handling, and cache invalidation. - No files require special attention <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs