星座运势 API 接进 Cherry Studio / ChatBox:MCP 配置与两个工具

约 16 分钟 进阶星座运势APIMCPCherryStudioChatBox
# 星座运势 API 接进 Cherry Studio / ChatBox:MCP 配置与两个工具 接口 872(两接入点)· 免费服务 · 适用:AI 客户端与智能体开发者 · 阅读时间:约 7 分钟 · 最后实测核对:2026-09-18 ## 核心要点 - 星座运势接口(apiCode=872)提供接口级 MCP 服务,端点形如 `http://www.showapi.com.cn/mcp/872/{你的AppKey}`。 - 2026-09-18 实测该端点暴露两个工具,名字就是接入点的中文名:`星座运势查询` 与 `星座配对`。 - MCP 的握手是四步,中间漏掉 `notifications/initialized` 这一步,后面的 `tools/list` 会返回方法不存在。 ## 端点怎么来的 把星座运势封装成 MCP 工具之后,AI 客户端可以在对话里直接调用:用户说查一下狮子座今天的运势,客户端自动请求接入点 1;说两个人配不配,自动请求接入点 2。省掉手写 HTTP 代码这一步。 接口详情页的开发集成区有「MCP 服务」入口,配置串由平台按接口生成。2026-09-18 实测端点格式为: ``` http://www.showapi.com.cn/mcp/872/{your_appKey} ``` 注意 MCP 服务用的是 `www.showapi.com.cn`,和接口调用域名 `route.showapi.com` 不是同一个。把 `{your_appKey}` 换成你自己的 AppKey 就能用。 ## 两个可用工具(2026-09-18 实测) | 工具名 | 对应接入点 | 入参 | |---|---|---| | `星座运势查询` | 872-1 | `star`、`date`、`needTomorrow`、`needWeek`、`needMonth`、`needYear` | | `星座配对` | 872-2 | `star1`、`gender1`、`star2`、`gender2` | 工具名是中文,调用时 `params.name` 原样传这两个字符串。 两个工具的入参定义与 OpenAPI 文档一致。`星座配对` 的描述里写着「数据结果仅供娱乐参考」,`星座运势查询` 的描述写明覆盖十二个星座。 ## 握手顺序 MCP 端点走 JSON-RPC,握手固定四步。第一步的 `initialize` 响应会在响应头里给出 `Mcp-Session-Id`,后续请求都要带上。 ```bash U="http://www.showapi.com.cn/mcp/872/YOUR_APPKEY" # 1) initialize,从响应头取 Mcp-Session-Id SID=$(curl -s -i -X POST "$U" \ -H "content-type: application/json" \ -H "accept: application/json, text/event-stream" \ --data-raw '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' \ | grep -i "mcp-session-id" | tr -d '\r' | awk '{print $2}') # 2) 必须补发 initialized 通知 curl -s -X POST "$U" \ -H "content-type: application/json" \ -H "accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SID" \ --data-raw '{"jsonrpc":"2.0","method":"notifications/initialized"}' >/dev/null # 3) 列工具 curl -s -X POST "$U" \ -H "content-type: application/json" \ -H "accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SID" \ --data-raw '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' ``` Python(把四步包成一个可复用的客户端): ```python import json import requests class ShowapiMcp: def __init__(self, api_code: str, appkey: str): self.url = f"http://www.showapi.com.cn/mcp/{api_code}/{appkey}" self.session_id = None self._id = 0 def _headers(self): h = {"content-type": "application/json", "accept": "application/json, text/event-stream"} if self.session_id: h["Mcp-Session-Id"] = self.session_id return h @staticmethod def _parse_sse(text: str) -> dict: """响应是 SSE 帧,形如 data:{...} 加 id:N,不能整体 json.loads。""" for line in text.splitlines(): if line.startswith("data:"): return json.loads(line[5:].strip()) return {} def initialize(self): self._id += 1 r = requests.post(self.url, headers=self._headers(), timeout=20, json={ "jsonrpc": "2.0", "id": self._id, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "demo", "version": "1.0"}}, }) self.session_id = r.headers.get("Mcp-Session-Id") # 补发 initialized 通知,否则后续调用会报方法不存在 requests.post(self.url, headers=self._headers(), timeout=20, json={ "jsonrpc": "2.0", "method": "notifications/initialized"}) return self._parse_sse(r.text) def list_tools(self): self._id += 1 r = requests.post(self.url, headers=self._headers(), timeout=20, json={ "jsonrpc": "2.0", "id": self._id, "method": "tools/list", "params": {}}) return self._parse_sse(r.text) client = ShowapiMcp("872", "YOUR_APPKEY") client.initialize() tools = client.list_tools() print([t["name"] for t in tools["result"]["tools"]]) ``` Node.js(先握手再列工具): ```javascript const url = "http://www.showapi.com.cn/mcp/872/YOUR_APPKEY"; let sessionId = null; async function rpc(body) { const headers = { "content-type": "application/json", accept: "application/json, text/event-stream", }; if (sessionId) headers["Mcp-Session-Id"] = sessionId; const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body), signal: AbortSignal.timeout(20000), }); if (!sessionId) sessionId = res.headers.get("mcp-session-id"); const text = await res.text(); const line = text.split("\n").find(l => l.startsWith("data:")); return line ? JSON.parse(line.slice(5).trim()) : null; } await rpc({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "demo", version: "1.0" } } }); await rpc({ jsonrpc: "2.0", method: "notifications/initialized" }); const tools = await rpc({ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} }); console.log(tools.result.tools.map(t => t.name)); ``` ## 三处需要留意的实现细节 响应是 SSE 帧而不是纯 JSON,形如 `data:{...}` 加一行 `id:1`,整段做 `JSON.parse` 会直接报错,按行取 `data:` 前缀再解析。 工具名是中文。命令行里发中文 JSON 时注意编码,服务端按 UTF-8 解析,编码不对会被判成工具不存在。 客户端配置里含 AppKey,配置文件放本地即可,不要提交到公开仓库。 ## 在 Cherry Studio / ChatBox 里配置 两个客户端都支持导入 MCP 服务,填法一致: | 配置项 | 值 | |---|---| | 类型 | HTTP / Streamable HTTP | | URL | `http://www.showapi.com.cn/mcp/872/{your_appKey}` | | 传输协议 | JSON-RPC over HTTP,响应为 SSE | 填好后客户端会在启动时完成四步握手,工具列表里会出现 `星座运势查询` 与 `星座配对`。 配置生效后可以这样对话触发: - 「查一下狮子座今天的运势」→ 调用 `星座运势查询` - 「天蝎男和水瓶女配不配」→ 调用 `星座配对` ## 工具返回的结构 工具的返回内容与直接调用 HTTP 接口一致:`星座运势查询` 返回系统级包裹加 `day` 等周期对象,`星座配对` 返回 22 个字段的配对结果。字段说明见返回字段全解与配对字段全解两篇。 配对结果为娱乐性质,接口文档与工具描述都写明「数据结果仅供娱乐参考」,在智能体的回复里保留这句说明更合适。 ## FAQ **Q1:MCP 端点的域名是什么?** `www.showapi.com.cn`,与接口调用域名 `route.showapi.com` 不同。完整形式为 `http://www.showapi.com.cn/mcp/872/{your_appKey}`。 **Q2:MCP 暴露了哪几个工具?** 2026-09-18 实测两个:`星座运势查询`(对应接入点 1)与 `星座配对`(对应接入点 2)。工具名就是接入点的中文名。 **Q3:为什么调 `tools/list` 报方法不存在?** 少了 `notifications/initialized` 这一步。MCP 要求 `initialize` 之后补发这个通知,直接列工具会被判为未完成初始化。 **Q4:响应可以直接 `JSON.parse` 吗?** 不行。返回是 SSE 帧,含 `data:` 前缀行与 `id:` 行,按行取 `data:` 后的内容再解析。 **Q5:MCP 和直接调 HTTP 接口有什么区别?** MCP 让 AI 客户端以工具方式调用,不用自己写 HTTP 代码;底层仍是 872-1 与 872-2 两个接入点,返回结构相同。 **Q6:需要单独配两个接入点吗?** 不需要。一个 MCP 端点覆盖接口 872 的全部接入点,配一次就同时拿到两个工具。 ## 下一步阅读 - [星座运势 API 导入 Postman / Swagger UI](https://www.showapi.com/guides/horoscope-openapi-872) - [星座运势查询:用 Python / cURL / Node.js 跑通第一次调用](https://www.showapi.com/guides/horoscope-quickstart-872) - [星座配对:用四个必填参数算出配对指数](https://www.showapi.com/guides/constellation-match-quickstart-872) - [星座运势查询返回字段全解:五个周期的字段对照](https://www.showapi.com/guides/horoscope-response-fields-872) - **本系列共 13 篇**:查看[星座运势 API 指南总目录](https://www.showapi.com/guides/horoscope-guides-872)
加载中...