Skip to main content
Glama
fengin

Search MCP Server

by fengin

search

Perform web searches to retrieve accurate information and links from the internet. Filter results by time range, display detailed summaries, and paginate responses. Supports up to 10 results per request for AI-driven analysis.

Instructions

执行网页搜索,从全网搜索任何网页信息和网页链接。结果准确、摘要完整,更适合AI使用。支持以下特性:

  • 时间范围过滤

  • 显示详细摘要

  • 分页获取 每次请求最多返回10个结果。(当前使用博查搜索API实现)

Input Schema

NameRequiredDescriptionDefault
countNo结果数量(1-10,默认10)
freshnessNo时间范围(noLimit:不限, oneDay:一天内, oneWeek:一周内, oneMonth:一月内, oneYear:一年内)noLimit
pageNo页码,从1开始
queryYes搜索查询内容
summaryNo是否显示详细摘要

Input Schema (JSON Schema)

{ "properties": { "count": { "default": 10, "description": "结果数量(1-10,默认10)", "type": "number" }, "freshness": { "default": "noLimit", "description": "时间范围(noLimit:不限, oneDay:一天内, oneWeek:一周内, oneMonth:一月内, oneYear:一年内)", "enum": [ "noLimit", "oneDay", "oneWeek", "oneMonth", "oneYear" ], "type": "string" }, "page": { "default": 1, "description": "页码,从1开始", "type": "number" }, "query": { "description": "搜索查询内容", "type": "string" }, "summary": { "default": false, "description": "是否显示详细摘要", "type": "boolean" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • MCP server registration for the 'search' tool: Server('search'), list_tools() returns schema from engine, call_tool() delegates to engine's handle_tool_call.
    server = Server("search") @server.list_tools() async def handle_list_tools() -> list[types.Tool]: """列出可用的搜索工具""" return AVAILABLE_ENGINES[SEARCH_ENGINE]["tools"]() @server.call_tool() async def handle_call_tool( name: str, arguments: Optional[Dict[str, Any]] ) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]: """处理工具调用请求""" try: if not arguments: raise ValueError("缺少参数") result = await AVAILABLE_ENGINES[SEARCH_ENGINE]["handle_tool"](name, arguments) return [result] except Exception as e: return [types.TextContent( type="text", text=f"错误: {str(e)}" )]
  • Handler function for the 'search' tool using Bocha backend (default engine): performs web search, formats results with stats, titles, urls, summaries, images.
    async def handle_tool_call(name: str, arguments: Dict[str, Any]) -> types.TextContent: """统一处理工具调用""" if not arguments or "query" not in arguments: raise ValueError("缺少query参数") query = arguments["query"] client = BochaClient() try: if name == "search": count = arguments.get("count", 10) page = arguments.get("page", 1) freshness = arguments.get("freshness", "noLimit") summary = arguments.get("summary", False) response = await client.web_search( query=query, count=count, page=page, freshness=freshness, summary=summary ) # 检查响应状态 if response.get("code") != 200: return types.TextContent( type="text", text=f"搜索失败: {response.get('msg', '未知错误')}" ) # 获取搜索结果数据 data = response.get("data", {}) if not data: return types.TextContent( type="text", text="未找到相关结果" ) # 格式化输出 formatted_results = [] # 首先添加统计信息 web_pages = data.get("webPages", {}) total_results = web_pages.get("totalEstimatedMatches", 0) current_results = len(web_pages.get("value", [])) total_pages = (total_results + count - 1) // count if total_results > 0 else 0 formatted_results.extend([ "搜索统计信息:", f"- 总结果数: {total_results:,} 条", f"- 当前页/总页数: {page}/{total_pages}", f"- 本页结果数: {current_results} 条", "" # 添加空行分隔 ]) # 处理网页结果 web_pages = data.get("webPages", {}).get("value", []) for result in web_pages: content = [ f"标题: {result.get('name', '')}", f"网址: {result.get('url', '')}", f"来源: {result.get('siteName', '未知来源')}" ] # 如果有摘要,添加摘要信息 if summary and "summary" in result: content.append(f"摘要: {result['summary']}") else: content.append(f"描述: {result.get('snippet', '')}") # 如果有发布时间,添加时间信息 if "dateLastCrawled" in result: content.append(f"发布时间: {result['dateLastCrawled']}") formatted_results.append("\n".join(content)) # 如果有图片结果,添加图片信息 images = data.get("images", {}).get("value", []) if images: formatted_results.append("\n相关图片:") for image in images: image_info = [ f"- 名称: {image.get('name', '未命名')}", f" 尺寸: {image.get('width', '未知')}x{image.get('height', '未知')}", f" 来源页面: {image.get('hostPageDisplayUrl', image.get('hostPageUrl', '未知'))}", f" 原图URL: {image.get('contentUrl', '')}", f" 缩略图URL: {image.get('thumbnailUrl', '')}" ] formatted_results.append("\n".join(image_info)) return types.TextContent( type="text", text="\n\n".join(formatted_results) if formatted_results else "未找到相关结果" ) else: raise ValueError(f"博查搜索不支持的工具: {name}") except BochaException as e: return types.TextContent( type="text", text=f"搜索执行错误: {str(e)}" )
  • Input schema definition for the 'search' tool (Bocha backend): query (required), count, page, freshness, summary.
    def get_tool_descriptions() -> list[types.Tool]: """返回博查搜索工具的描述列表""" return [ types.Tool( name="search", description=( "执行网页搜索,从全网搜索任何网页信息和网页链接。" "结果准确、摘要完整,更适合AI使用。" "支持以下特性:\n" "- 时间范围过滤\n" "- 显示详细摘要\n" "- 分页获取\n" "每次请求最多返回10个结果。" "(当前使用博查搜索API实现)" ), inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "搜索查询内容" }, "count": { "type": "number", "description": "结果数量(1-10,默认10)", "default": 10 }, "page": { "type": "number", "description": "页码,从1开始", "default": 1 }, "freshness": { "type": "string", "description": "时间范围(noLimit:不限, oneDay:一天内, oneWeek:一周内, oneMonth:一月内, oneYear:一年内)", "enum": list(FRESHNESS_RANGES.values()), "default": "noLimit" }, "summary": { "type": "boolean", "description": "是否显示详细摘要", "default": False } }, "required": ["query"] } ) ]
  • Configuration selecting the default 'bocha' search engine and mapping other engines' handlers and schemas.
    SEARCH_ENGINE = os.getenv("SEARCH_ENGINE", "bocha") AVAILABLE_ENGINES = { "brave": { "handle_tool": brave_handle_tool, "tools": brave_tools, "description": "Brave Search API,支持网络搜索和位置搜索" }, "metaso": { "handle_tool": metaso_handle_tool, "tools": metaso_tools, "description": "Metaso Search API,支持网络搜索和学术搜索,提供简洁、深入、研究三种模式" }, "bocha": { "handle_tool": bocha_handle_tool, "tools": bocha_tools, "description": "博查搜索API,支持网络搜索,提供时间范围过滤、详细摘要等功能" } }
  • Top-level call_tool handler that routes 'search' tool calls to the configured engine's implementation.
    @server.call_tool() async def handle_call_tool( name: str, arguments: Optional[Dict[str, Any]] ) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]: """处理工具调用请求""" try: if not arguments: raise ValueError("缺少参数") result = await AVAILABLE_ENGINES[SEARCH_ENGINE]["handle_tool"](name, arguments) return [result] except Exception as e: return [types.TextContent( type="text", text=f"错误: {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/fengin/search-server'

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