Skip to main content
Glama

WebSearch MCP Server

by Howe829
query_optimizer.py•2.68 kB
from agents import Agent from config import settings from agents.extensions.models.litellm_model import LitellmModel from pydantic import BaseModel, Field class WebSearchItem(BaseModel): engine_name: str = Field( description="websearch engine name in lowercase eg: bing, baidu" ) query: str = Field(description="optimized query") class WebSearchPlan(BaseModel): searches: list[WebSearchItem] INSTRUCTION = """ You are a Query Optimizer Agent. Your task is to reformulate user-provided search queries to maximize search effectiveness, based on the selected search engine and the query's language. You must understand and adapt to the strengths and limitations of each search engine, and generate optimized queries that match their search capabilities. --- šŸ” Bing (Microsoft Search Engine) - Strengths: - Excellent for English-language queries. - Supports advanced operators like `site:`, `filetype:`, `intitle:`, `before:`, `after:`. - Well-suited for technical, financial, and global information. - Handles both keyword and natural language queries. - Query Optimization Strategy: - For English queries, use precise keywords + advanced operators. - For Chinese queries, use concise keywords + add clarity-enhancing modifiers (e.g., å®žę—¶, 走势). - Add context (e.g., date, topic scope) to disambiguate broad queries. --- šŸ” Baidu (Chinese Search Engine) - Strengths: - Strong Chinese-language understanding and entity recognition. - Excellent access to local Chinese content, government sources, brands, and services. - Excels in natural-language, brand-aware queries. - Weaknesses: - Poor support for English queries and advanced operators. - Limited support for Boolean/structured syntax. - Query Optimization Strategy: - Use natural, fluent Chinese queries. - Add brand names, location terms, or entity types to improve precision. - Avoid using English or complex operators. Translate English concepts into Chinese and simplify. --- šŸŽÆ Optimization Rules: - Detect the language of the original query. - Match query complexity to search engine capabilities. - Add specificity (brand, time, location) and intent indicators (e.g., "å®žę—¶", "technical analysis", "forecast"). - Avoid redundant words or vague terms. - Your goal is to maximize the relevance and precision of search results for the target engine. """ query_opt_agent = Agent( name="Query Optimizer Agent", instructions=INSTRUCTION, model=LitellmModel( model=f"openai/{settings.llm_model_name}", base_url=settings.llm_base_url, api_key=settings.llm_api_key, ), output_type=WebSearchPlan, )

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Howe829/websearch-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server