Skip to main content
Glama
lroolle

OpenAI Agents MCP Server

by lroolle

web_search_agent

Find accurate, up-to-date information from the internet using an AI agent specialized in web searching. Provide a search query to get relevant online results.

Instructions

Use an AI agent specialized in web searching to find accurate, up-to-date information from the internet.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationNoOptional location context for location-specific searches (e.g., 'New York').
queryYesThe search query or question you want to find information about online.

Implementation Reference

  • The primary handler for the 'web_search_agent' MCP tool. It runs the web_search_agent (or a location-specific variant) using the Runner to execute web searches via WebSearchTool.
    @mcp.tool(
        name="web_search_agent",
        description="Use an AI agent specialized in web searching to find accurate, up-to-date information from the internet.",
    )
    async def web_search(
        query: str = Field(
            ..., description="The search query or question you want to find information about online."
        ),
        location: Optional[str] = Field(
            None,
            description="Optional location context for location-specific searches (e.g., 'New York').",
        ),
    ) -> AgentResponse:
        """Use a specialized web search agent powered by OpenAI to find information on the internet."""
        try:
            agent = web_search_agent
            if location:
                agent = Agent(
                    name="Web Search Assistant",
                    instructions=web_search_agent.instructions,
                    tools=[WebSearchTool(user_location={"type": "approximate", "city": location})],
                )
    
            with trace("Web search agent execution"):
                result = await Runner.run(agent, query)
    
            return AgentResponse(
                response=result.final_output,
                raw_response={"items": [str(item) for item in result.new_items]},
            )
    
        except Exception as e:
            print(f"Error running web search agent: {e}")
            return AgentResponse(
                response=f"An error occurred while searching the web: {str(e)}", raw_response=None
            )
  • Defines the core web_search_agent Agent instance with specialized instructions and WebSearchTool, used by the handler.
    web_search_agent = Agent(
        name="Web Search Assistant",
        instructions="""You are a web search assistant. Your primary goal is to search the web for accurate,
        up-to-date information based on the user's query.
    
        Guidelines:
        1. Always use the web search tool to find information
        2. Cite your sources when providing information
        3. If information seems outdated or contradictory, acknowledge this
        4. Summarize information in a clear, concise manner
        5. For complex topics, break down information into digestible parts
        """,
        tools=[WebSearchTool()],
    )
  • Pydantic schema for the output of the web_search_agent tool (and other agents).
    class AgentResponse(BaseModel):
        """Response from an OpenAI agent."""
    
        response: str = Field(..., description="The response from the agent")
        raw_response: Optional[Dict[str, Any]] = Field(
            None, description="The raw response data from the agent, if available"
        )
  • Secondary registration of web_search_agent as a sub-tool ('search_web') within the multi_tool_agent for orchestration.
    tools.append(
        web_search_agent.as_tool(
            tool_name="search_web", tool_description="Search the web for information"
        )
    )
  • Helper code to create a location-specific variant of the web_search_agent when location parameter is provided.
    if location:
        agent = Agent(
            name="Web Search Assistant",
            instructions=web_search_agent.instructions,
            tools=[WebSearchTool(user_location={"type": "approximate", "city": location})],
        )

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/lroolle/openai-agents-mcp-server'

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