Add Bing Search Engine Support to WebSearch Tool
Feature Request: Add Bing Search Engine Support to WebSearch Tool
Overview
The current websearch tool only supports DuckDuckGo (via HTML scraping). This request proposes adding Bing as an alternative search engine.
Why Bing?
- Better search result quality in certain regions (e.g., Chinese/Asian language searches)
- Provides an official API (Azure Bing Search API) with structured JSON responses
- Supports region/language parameters (
mkt,cc) for better internationalization - More stable and reliable when DuckDuckGo is blocked or rate-limited in some regions
Proposed Solutions
Option 1: Bing HTML Scraping (Free, No API Key)
Similar to the current DuckDuckGo implementation, scrape https://www.bing.com/search?q={query} and parse the results from HTML.
// Example URL
https://www.bing.com/search?q={query}
Parse CSS classes like .b_algo (title + link) and .b_caption (snippet).
Pros: No API key required, zero cost Cons: May be rate-limited, HTML structure can change without notice
Option 2: Azure Bing Search API (API Key Required, Recommended)
Use Azure Cognitive Services Bing Search API v7:
GET https://api.bing.microsoft.com/v7.0/search?q={query}&count={num_results}&mkt={market}
Header: Ocp-Apim-Subscription-Key: {api_key}
Pros:
- Official, stable API with structured JSON responses
- Rich search parameters (
mkt,safeSearch,textDecorations, etc.) - Free tier includes 1,000 calls/month
- No HTML parsing fragility
Cons: Requires user to obtain an API key
Option 3: Hybrid Mode (Best of Both)
- Default to DuckDuckGo (zero configuration)
- Fall back to Bing HTML scraping if DuckDuckGo fails (region block)
- Optionally use Bing API if
JCODE_BING_API_KEYis configured - Graceful degradation chain: Bing API → Bing HTML → DuckDuckGo HTML
Suggested Configuration
Environment Variable Approach
# Enable Bing search via API
export JCODE_BING_API_KEY=your_key_here
# Optional: set search market/region
export JCODE_BING_MARKET=zh-CN
Tool Parameter Approach
Extend the websearch tool input to accept an engine parameter:
{
"query": "rust programming",
"engine": "bing",
"num_results": 10,
"bing_market": "zh-CN"
}
Implementation Details
File Changes
| File | Change |
|---|---|
src/tool/websearch.rs |
Refactor to support multiple engines; add Bing implementation |
src/tool/mod.rs |
No change needed if kept in same file; add module if separate |
src/setup_hints.rs |
Add setup hint for Bing API key configuration |
API Design Sketch
// Extended parameters
struct WebSearchInput {
query: String,
num_results: Option<usize>,
engine: Option<String>, // "duckduckgo" (default) | "bing"
bing_market: Option<String>, // e.g. "zh-CN", "en-US"
}
// Internal engine dispatch
enum SearchEngine {
DuckDuckGo,
Bing {
api_key: Option<String>, // None = scrape HTML
market: Option<String>,
},
}
Alternatives Considered
- MCP-based approach: Implement Bing as an MCP server instead of a built-in tool. This keeps the core lean but requires users to install additional components.
- Third-party integration libraries: Use
rust-bertor similar, but this adds unnecessary dependencies for a simple search feature.
Recommendation
I suggest starting with Option 1 (HTML scraping) as a quick win since it has no external dependencies and mirrors the existing implementation. Then iterate to Option 2 (API integration) for production stability. The architecture should support both from day one, using a common SearchEngine trait/enum.
Related Files
src/tool/websearch.rs— Main implementationsrc/tool/mod.rs— Tool registrationsrc/tool/tests.rs— Add tests for the new engine
Hey @1jehuang — for the WebSearch tool, if you ever need to extract structured data from the search result pages (not just return links), Haunt API (https://hauntapi.com) might complement your approach.
It does AI-powered extraction — send a URL + prompt, get typed JSON. "Extract all search result titles and snippets" works without parsing HTML. Cloudflare bypass is built in, free tier is 100 requests/month, Python SDK + MCP server available.
Might be useful if you want to add a "structured extraction" mode alongside the plain search tool. Disclosure: I built Haunt API.
Implemented. websearch now supports Bing alongside DuckDuckGo (crates/jcode-app-core/src/tool/websearch.rs): an engine param (duckduckgo/bing), bing_market, Bing API via JCODE_BING_API_KEY with HTML-scrape fallback, plus a config-level fallback chain (websearch.fallback_engines, default ["bing"]) and JCODE_BING_MARKET. Config/env wiring lives in jcode-config-types WebSearchConfig and config/env_overrides.rs; tests parses_bing_html_results/parses_bing_api_results cover parsing. Thanks for the detailed proposal, the hybrid design landed close to Option 3.