Skip to main content
Glama
ConechoAI

OpenAI WebSearch MCP Server

by ConechoAI

openai_web_search

Perform web searches using AI reasoning models to answer queries, supporting quick iterations or deep research with configurable reasoning effort and context size.

Instructions

OpenAI Web Search with reasoning models.

For quick multi-round searches: Use 'gpt-5-mini' with reasoning_effort='low' for fast iterations.

For deep research: Use 'gpt-5' with reasoning_effort='medium' or 'high'. The result is already multi-round reasoned, so agents don't need continuous iterations.

Supports: gpt-4o (no reasoning), gpt-5/gpt-5-mini/gpt-5-nano, o3/o4-mini (with reasoning).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesThe search query or question to search for
modelNoAI model to use. Defaults to OPENAI_DEFAULT_MODEL env var or gpt-5-mini
reasoning_effortNoReasoning effort level for supported models (gpt-5, o3, o4-mini). Default: low for gpt-5-mini, medium for others
typeNoWeb search API version to useweb_search_preview
search_context_sizeNoAmount of context to include in search resultsmedium
user_locationNoOptional user location for localized search results

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function that implements the 'openai_web_search' tool. It reads environment variables, determines reasoning effort based on model, constructs the API request with web search tools and optional user location, and calls OpenAI's responses.create to get the search result.
    def openai_web_search(
        input: Annotated[str, Field(description="The search query or question to search for")],
        model: Annotated[Optional[Literal["gpt-4o", "gpt-4o-mini", "gpt-5", "gpt-5-mini", "gpt-5-nano", "o3", "o4-mini"]], 
                         Field(description="AI model to use. Defaults to OPENAI_DEFAULT_MODEL env var or gpt-5-mini")] = None,
        reasoning_effort: Annotated[Optional[Literal["low", "medium", "high", "minimal"]], 
                                    Field(description="Reasoning effort level for supported models (gpt-5, o3, o4-mini). Default: low for gpt-5-mini, medium for others")] = None,
        type: Annotated[Literal["web_search_preview", "web_search_preview_2025_03_11"], 
                        Field(description="Web search API version to use")] = "web_search_preview",
        search_context_size: Annotated[Literal["low", "medium", "high"], 
                                       Field(description="Amount of context to include in search results")] = "medium",
        user_location: Annotated[Optional[UserLocation], 
                                Field(description="Optional user location for localized search results")] = None,
    ) -> str:
        # 从环境变量读取默认模型,如果没有则使用 gpt-5-mini
        if model is None:
            model = os.getenv("OPENAI_DEFAULT_MODEL", "gpt-5-mini")
        
        client = OpenAI()
        
        # 判断是否为推理模型
        reasoning_models = ["gpt-5", "gpt-5-mini", "gpt-5-nano", "o3", "o4-mini"]
        
        # 构建请求参数
        request_params = {
            "model": model,
            "tools": [
                {
                    "type": type,
                    "search_context_size": search_context_size,
                    "user_location": user_location.model_dump() if user_location else None,
                }
            ],
            "input": input,
        }
        
        # 对推理模型设置智能默认值
        if model in reasoning_models:
            if reasoning_effort is None:
                # gpt-5-mini 默认使用 low,其他推理模型默认 medium
                if model == "gpt-5-mini":
                    reasoning_effort = "low"  # 快速搜索
                else:
                    reasoning_effort = "medium"  # 深度研究
            request_params["reasoning"] = {"effort": reasoning_effort}
        
        response = client.responses.create(**request_params)
        return response.output_text
  • Tool registration decorator @mcp.tool with name='openai_web_search', detailed description, and input schema defined via Annotated parameters including model, reasoning_effort, type, search_context_size, and user_location.
    @mcp.tool(
        name="openai_web_search",
        description="""OpenAI Web Search with reasoning models. 
    
    For quick multi-round searches: Use 'gpt-5-mini' with reasoning_effort='low' for fast iterations.
    
    For deep research: Use 'gpt-5' with reasoning_effort='medium' or 'high'. 
    The result is already multi-round reasoned, so agents don't need continuous iterations.
    
    Supports: gpt-4o (no reasoning), gpt-5/gpt-5-mini/gpt-5-nano, o3/o4-mini (with reasoning).""",
    )
  • Pydantic model UserLocation used for optional user_location parameter to provide localized search results.
    class UserLocation(BaseModel):
        type: Literal["approximate"] = "approximate"
        city: str
        country: str = None
        region: str = None
        timezone: TimeZoneName
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the reasoning model capabilities and result characteristics ('multi-round reasoned'), but lacks details on rate limits, authentication needs, error handling, or what constitutes a 'search' versus other operations. It adds some context about model behaviors but leaves significant gaps for a tool with multiple parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with clear sections for different use cases and model support. It avoids redundancy and each sentence adds value, though the final 'Supports:' line could be integrated more smoothly. Overall, it's appropriately sized and front-loaded with key information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, reasoning models, web search) and the presence of an output schema, the description is moderately complete. It covers model selection and usage scenarios but lacks context about search result format, limitations, or how parameters like 'search_context_size' and 'user_location' affect outcomes. The output schema reduces the burden, but more operational context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing detailed parameter documentation. The description adds minimal semantic value beyond the schema, mentioning model support and reasoning effort implications but not explaining parameter interactions or search-specific nuances. It meets the baseline for high schema coverage but doesn't significantly enhance understanding of parameter meanings.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs 'OpenAI Web Search with reasoning models', specifying the action (search) and key capability (reasoning models). It distinguishes this as a web search tool with AI reasoning integration, though no sibling tools exist for comparison. The purpose is specific but could be more precise about what 'web search' entails beyond model selection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use different configurations: 'quick multi-round searches' with gpt-5-mini and reasoning_effort='low', and 'deep research' with gpt-5 and reasoning_effort='medium' or 'high'. It also advises that 'agents don't need continuous iterations' for deep research, offering clear usage scenarios despite no sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/ConechoAI/openai-websearch-mcp'

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