#13814: feat(web-search): add ZAI Search (zsearch) provider
agents
stale
Cluster:
Web Search Provider Enhancements
## 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
#12304: feat: add DeSearch as web_search provider
by tatjr13 · 2026-02-09
82.6%
#13370: Tools: rewrite Grok parser, add Tavily provider, multi-provider con...
by a-anand-91119 · 2026-02-10
80.6%
#13386: feat(web-search): add Nimble Web Search API provider
by ilchemla · 2026-02-10
80.5%
#19876: feat(web-search): add SerpAPI search provider support
by nksolar-tianjin · 2026-02-18
80.3%
#10839: feat(web-search): add Bocha as a web search provider
by xiekeyang · 2026-02-07
80.3%
#13075: [Feature]: Add Gemini (Google Search grounding) as web_search provider
by akoscz · 2026-02-10
79.9%
#13366: Add baidu search as web tools provider
by ide-rea · 2026-02-10
79.5%
#14788: feat: Add DuckDuckGo search provider with Tor support
by emadomedher · 2026-02-12
78.7%
#6743: feat(web-search): add Tavily search provider support
by 3927o · 2026-02-02
78.6%
#9337: fix: correct GLM MCP web-search-prime API parameter name and respon...
by shoa-lin · 2026-02-05
77.7%