MCP 服务器
网页搜索、网页读取和地理编码,以工具形式供智能体调用,传输方式为 MCP Streamable HTTP。
MCP 服务器把 Web API 以工具的形式交给智能体。它使用 MCP Streamable HTTP 传输,和 REST API 接受同一个 relay.fast 密钥。
| URL | https://api.websearch.fast/mcp |
| 其他地址 | https://api.websearch.fast/v1/web/mcp, https://relay.fast/v1/web/mcp |
| 认证 | 每个请求都带 Authorization: Bearer sk-... 或 X-API-KEY: sk-... |
客户端配置
把密钥放进环境变量 WEBSEARCH_API_KEY,让客户端从那里读取,这样密钥不会写进配置文件。
claude mcp add --transport http websearch https://api.websearch.fast/mcp \
--header "Authorization: Bearer $WEBSEARCH_API_KEY"{
"mcpServers": {
"websearch": {
"url": "https://api.websearch.fast/mcp",
"headers": {"Authorization": "Bearer ${env:WEBSEARCH_API_KEY}"}
}
}
}# ~/.codex/config.toml
[mcp_servers.websearch]
url = "https://api.websearch.fast/mcp"
bearer_token_env_var = "WEBSEARCH_API_KEY"{
"mcpServers": {
"websearch": {
"type": "http",
"url": "https://api.websearch.fast/mcp",
"headers": {"Authorization": "Bearer ${WEBSEARCH_API_KEY}"}
}
}
}Cursor 读取 ~/.cursor/mcp.json 或项目里的 .cursor/mcp.json。只能配置命令、不能填 URL 的客户端,可以运行 mcp-remote 这类本地桥接程序,传入 URL 和请求头。
工具
| 工具 | 作用 | 对应的 REST 接口 | 状态 |
|---|---|---|---|
web_search | 排好序的结果,带标题、URL 和摘要。传入 content_pages 时,还会返回排名靠前网页的正文。 | search | 可用 |
web_fetch | 以 Markdown 返回网页或 PDF 的正文。 | fetch | 可用 |
geocode | 把地址或地名转换成坐标和结构化地址。 | geocode | 可用 |
reverse_geocode | 给出某个经纬度上的地址或地点。 | reverse geocode | 可用 |
autocomplete | 为搜索查询的开头部分给出补全建议。 | autocomplete | 可用 |
knowledge | 人物、地点、机构或事物的知识卡片,附来源。 | knowledge | 可用 |
web_extract | 从一个或多个网页中提取符合 JSON Schema 的数据。 | extract | 计划中 |
places_search | 按文本搜索某个位置附近的地点。 | search, type: places | 计划中 |
research_start, research_get | 启动研究任务并读取报告。 | research | 计划中 |
crawl_start, crawl_get | 启动对一个站点的抓取,并读取抓到的网页。 | crawl | 计划中 |
tools/list 只列出已经上线的工具。所有工具都是只读的。MCP 工具的上限比 REST 小(num 20,content_pages 5),一次工具调用不会产生大额账单。
结果和错误
每个工具都返回 structuredContent(去掉模型用不到的外层字段后的 REST 响应),外加一个 text 块,内容是简短的 Markdown 渲染,因为很多客户端只把文本交给模型。工具出错时返回的仍是普通工具结果,带 isError: true、一段简短文本和 structuredContent.error.code,模型能看到错误并据此处理。密钥缺失或无效时,在进入 JSON-RPC 层之前直接返回 HTTP 401。
每次工具调用的计费与它对应的 REST 调用完全相同。结果的 structuredContent 里带有 usage。
协议
POST 承载 JSON-RPC 消息,响应为 application/json。服务器不保存会话,不发放 Mcp-Session-Id,GET 和 DELETE 返回 405。支持的协议版本为 2025-03-26、2025-06-18、2025-11-25 和 2026-07-28。Origin 来自其他站点的请求返回 403,请求体不是 JSON 返回 415,Accept 请求头不含 application/json 返回 406。
直接调用时的工具定义
直接调用 REST API 的智能体,可以把同样的工具用作函数定义。web_search 对应 POST /v1/web/search(content_pages 改为 content.pages),web_fetch 对应 POST /v1/web/fetch。
[
{"type": "function", "function": {"name": "web_search", "description": "Search the web. Returns ranked results with title, URL and snippet; content_pages adds the cleaned text of the top results.",
"parameters": {
"type": "object",
"required": ["q"],
"additionalProperties": false,
"properties": {
"q": {
"type": "string",
"minLength": 1,
"maxLength": 2048,
"description": "The search query. Operators such as site:, quotes and -term work."
},
"num": {
"type": "integer",
"minimum": 1,
"maximum": 20,
"default": 10,
"description": "Number of results."
},
"page": {
"type": "integer",
"minimum": 1,
"maximum": 10,
"default": 1,
"description": "Result page, starting at 1."
},
"country": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "Country to search from as an ISO 3166-1 alpha-2 code, for example us."
},
"language": {
"type": "string",
"description": "Language of the results as a BCP 47 tag, for example en or de."
},
"location": {
"type": "string",
"minLength": 2,
"maxLength": 256,
"description": "City or region to search from, for example Berlin, Germany."
},
"freshness": {
"type": "string",
"enum": ["day", "week", "month", "year"],
"description": "Only results published within this period."
},
"include_domains": {
"type": "array",
"maxItems": 20,
"items": {"type": "string"},
"description": "Only results from these host names."
},
"exclude_domains": {
"type": "array",
"maxItems": 50,
"items": {"type": "string"},
"description": "No results from these host names."
},
"content_pages": {
"type": "integer",
"minimum": 0,
"maximum": 5,
"default": 0,
"description": "Read the text of this many top results."
}
}
}}},
{"type": "function", "function": {"name": "web_fetch", "description": "Read one web page or PDF and return its main text as Markdown.",
"parameters": {
"type": "object",
"required": ["url"],
"additionalProperties": false,
"properties": {
"url": {
"type": "string",
"format": "uri",
"maxLength": 2048,
"description": "The http or https URL to read."
},
"max_chars": {
"type": "integer",
"minimum": 1000,
"maximum": 100000,
"default": 20000,
"description": "Longest text to return."
},
"query": {
"type": "string",
"maxLength": 512,
"description": "What you look for on the page; the passages that match it are returned too."
},
"include_links": {
"type": "boolean",
"default": false,
"description": "Also return the links of the page."
}
}
}}}
][
{"name": "web_search", "description": "Search the web. Returns ranked results with title, URL and snippet; content_pages adds the cleaned text of the top results.",
"input_schema": {
"type": "object",
"required": ["q"],
"additionalProperties": false,
"properties": {
"q": {
"type": "string",
"minLength": 1,
"maxLength": 2048,
"description": "The search query. Operators such as site:, quotes and -term work."
},
"num": {
"type": "integer",
"minimum": 1,
"maximum": 20,
"default": 10,
"description": "Number of results."
},
"page": {
"type": "integer",
"minimum": 1,
"maximum": 10,
"default": 1,
"description": "Result page, starting at 1."
},
"country": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "Country to search from as an ISO 3166-1 alpha-2 code, for example us."
},
"language": {
"type": "string",
"description": "Language of the results as a BCP 47 tag, for example en or de."
},
"location": {
"type": "string",
"minLength": 2,
"maxLength": 256,
"description": "City or region to search from, for example Berlin, Germany."
},
"freshness": {
"type": "string",
"enum": ["day", "week", "month", "year"],
"description": "Only results published within this period."
},
"include_domains": {
"type": "array",
"maxItems": 20,
"items": {"type": "string"},
"description": "Only results from these host names."
},
"exclude_domains": {
"type": "array",
"maxItems": 50,
"items": {"type": "string"},
"description": "No results from these host names."
},
"content_pages": {
"type": "integer",
"minimum": 0,
"maximum": 5,
"default": 0,
"description": "Read the text of this many top results."
}
}
}},
{"name": "web_fetch", "description": "Read one web page or PDF and return its main text as Markdown.",
"input_schema": {
"type": "object",
"required": ["url"],
"additionalProperties": false,
"properties": {
"url": {
"type": "string",
"format": "uri",
"maxLength": 2048,
"description": "The http or https URL to read."
},
"max_chars": {
"type": "integer",
"minimum": 1000,
"maximum": 100000,
"default": 20000,
"description": "Longest text to return."
},
"query": {
"type": "string",
"maxLength": 512,
"description": "What you look for on the page; the passages that match it are returned too."
},
"include_links": {
"type": "boolean",
"default": false,
"description": "Also return the links of the page."
}
}
}}
]