Skip to main content
Glama

search_web_info

Search and retrieve real-time information from the web using the Tavily API, enabling AI assistants to access relevant data for user queries.

Instructions

从网络搜索用户查询的信息

Input Schema

NameRequiredDescriptionDefault
queryYes

Input Schema (JSON Schema)

{ "properties": { "query": { "title": "Query", "type": "string" } }, "required": [ "query" ], "title": "search_web_infoArguments", "type": "object" }

Implementation Reference

  • The handler function for the 'search_web_info' tool. It is registered via the @mcp.tool() decorator and delegates the search logic to the internal _do_search helper function.
    @mcp.tool() def search_web_info(query: str) -> str: """从网络搜索用户查询的信息""" return _do_search(query)
  • The core helper function that implements the web search logic using TavilyClient. It handles UTF-8 encoding, performs the search, extracts answer and top 3 sources, and formats the result.
    def _do_search(query: str) -> str: """Internal function to handle the search logic with UTF-8 support""" try: # 确保查询字符串是UTF-8编码 query = query.encode('utf-8').decode('utf-8') tavily_client = TavilyClient(api_key=API_KEY) response = tavily_client.search( query=query, search_depth="basic", include_answer=True, include_raw_content=False ) # 确保响应文本是UTF-8编码 answer = response.get('answer', 'No answer found').encode('utf-8').decode('utf-8') sources = response.get('sources', []) result = f"Answer: {answer}\n\nSources:" for source in sources[:3]: title = source.get('title', 'No title').encode('utf-8').decode('utf-8') url = source.get('url', 'No URL') result += f"\n- {title}: {url}" return result except UnicodeError as e: logger.error(f"Encoding error: {str(e)}") return "Error: Unicode encoding issue occurred" except Exception as e: logger.error(f"Search error: {str(e)}") return f"Error performing search: {str(e)}"

Other Tools

Related 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/mcp2everything/mcp2tavily'

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