@acedatacloud/skills 2026.703.2 → 2026.703.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ These skills drive third-party connectors users wire up at [auth.acedata.cloud/u
|
|
|
70
70
|
| [slack](skills/slack/) | Read Slack channels, messages, and user info via Web API | `slack` |
|
|
71
71
|
| [wechat-official-account](skills/wechat-official-account/) | Manage WeChat MP — drafts, publishing, materials, user tags | `wechat` (BYOC) |
|
|
72
72
|
| [personal-wechat](skills/personal-wechat/) | Operate a personal WeChat account through a self-hosted Wisdom service | `personalwechat` (BYOC) |
|
|
73
|
+
| [didi-ride](skills/didi-ride/) | Book DiDi rides, estimate fares, query/cancel orders, plan routes via the DiDi MCP | `didi` (BYOC) |
|
|
73
74
|
| [wecom](skills/wecom/) | WeCom (企业微信) self-built app — contacts, app messages, WeDoc, schedules, meetings | `wecom` (BYOC) |
|
|
74
75
|
| [tencent-docs](skills/tencent-docs/) | Create / read / list / search / manage Tencent Docs — docs, sheets, slides, mind maps, flowcharts | `tencentdocs` (BYOC) |
|
|
75
76
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acedatacloud/skills",
|
|
3
|
-
"version": "2026.703.
|
|
3
|
+
"version": "2026.703.3",
|
|
4
4
|
"description": "Agent Skills for AceDataCloud AI services — music, image, video generation, LLM chat, web search. Compatible with Claude Code, GitHub Copilot, Gemini CLI, OpenAI Codex, and 30+ AI coding agents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: didi-ride
|
|
3
|
+
description: 通过滴滴出行 MCP 打车、查价、查询订单、取消订单、规划路线(驾车/公交/步行/骑行)和搜索地点。Use when the user mentions 滴滴, 打车, 叫车, 回家/上班要打车, 查一下从 A 到 B 多少钱/怎么走, 查询订单, 司机在哪/多久到, 预约叫车, 路线规划, DiDi, ride-hailing, or booking a taxi.
|
|
4
|
+
when_to_use: |
|
|
5
|
+
Trigger for anything involving the user's DiDi (滴滴出行) account:
|
|
6
|
+
book a ride ("打车去…", "回家", "上班"), get a fare/route estimate,
|
|
7
|
+
query an existing order (driver location, ETA, trip progress), cancel
|
|
8
|
+
an order, plan a driving/transit/walking/cycling route, or search
|
|
9
|
+
places / reverse-geocode. Creating and cancelling orders act on real
|
|
10
|
+
money and a real driver, so those writes are gated behind explicit
|
|
11
|
+
confirmation.
|
|
12
|
+
connections: [didi]
|
|
13
|
+
allowed_tools: [Bash]
|
|
14
|
+
license: Apache-2.0
|
|
15
|
+
metadata:
|
|
16
|
+
author: acedatacloud
|
|
17
|
+
version: "1.0"
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# DiDi Ride (滴滴出行)
|
|
21
|
+
|
|
22
|
+
Drive the user's **DiDi (滴滴出行)** account through the DiDi MCP server:
|
|
23
|
+
book rides, estimate fares, track orders, cancel, and plan routes.
|
|
24
|
+
|
|
25
|
+
The `didi` BYOC connector injects one env var into the sandbox:
|
|
26
|
+
|
|
27
|
+
- `DIDI_MCP_KEY` — the user's DiDi MCP key. **Secret — never echo, print, or log it.**
|
|
28
|
+
|
|
29
|
+
If `DIDI_MCP_KEY` is missing, tell the user to connect the DiDi connector at
|
|
30
|
+
[auth.acedata.cloud/user/connections](https://auth.acedata.cloud/user/connections)
|
|
31
|
+
(they get the key by scanning the QR in the 滴滴出行 App or via
|
|
32
|
+
<https://mcp.didichuxing.com/claw>).
|
|
33
|
+
|
|
34
|
+
## CLI
|
|
35
|
+
|
|
36
|
+
The skill ships a stdlib-only helper that speaks the MCP Streamable-HTTP
|
|
37
|
+
protocol to DiDi. Point at it once:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
DIDI=$SKILL_DIR/scripts/didi.py
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Two commands:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python3 $DIDI list # list tools + their JSON input schemas
|
|
47
|
+
python3 $DIDI call <tool> '<json-args>' # call any tool
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Always check `references/api_references.md` for the exact tool + parameter
|
|
51
|
+
names before calling.** When unsure, run `python3 $DIDI list` — it returns the
|
|
52
|
+
authoritative input schema for every tool straight from DiDi. Do **not** guess
|
|
53
|
+
parameter names (common mistakes: `keyword` → `keywords`, `region` → `city`,
|
|
54
|
+
four coord fields → six `from_name/from_lat/from_lng/to_name/to_lat/to_lng`).
|
|
55
|
+
|
|
56
|
+
All argument **values must be strings** (including coordinates and
|
|
57
|
+
`product_category`), e.g. `{"product_category":"1"}` not `{"product_category":1}`.
|
|
58
|
+
|
|
59
|
+
## Write gating (real money / real driver)
|
|
60
|
+
|
|
61
|
+
`taxi_create_order` and `taxi_cancel_order` are **gated**: without a trailing
|
|
62
|
+
`--confirm` the helper only DRY-RUNS and changes nothing. Run once without
|
|
63
|
+
`--confirm` to preview, then re-run with `--confirm` as the **last** argument
|
|
64
|
+
after the user approves:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python3 $DIDI call taxi_create_order '{"estimate_trace_id":"...","product_category":"1"}' --confirm
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- Even when the user says "打车" / "取消订单", confirm the concrete details
|
|
71
|
+
(起终点、车型 for booking; the order for cancelling) before adding `--confirm`.
|
|
72
|
+
- Cancel intent ≠ cancel confirmation — always ask "确认取消吗?" first.
|
|
73
|
+
|
|
74
|
+
## Booking flow (最小可执行)
|
|
75
|
+
|
|
76
|
+
1. **Resolve addresses** — `maps_textsearch` (never invent coordinates; don't
|
|
77
|
+
reuse coordinates from earlier turns — the user may have moved).
|
|
78
|
+
- If the user references an address alias (家 / 公司 / etc.) that you don't
|
|
79
|
+
have, ask them; this skill has no stored preferences.
|
|
80
|
+
2. **Confirm start/end** — if `maps_textsearch` returns ≥2 candidates, list at
|
|
81
|
+
least the top 3 and let the user pick; a single exact match needs no
|
|
82
|
+
confirmation.
|
|
83
|
+
3. **Estimate** — `taxi_estimate`; record the returned `traceId` /
|
|
84
|
+
`estimate_trace_id`. It expires (`-32021`) — re-estimate if stale.
|
|
85
|
+
4. **Pick car type** — user's current message wins ("叫快车"→`product_category`
|
|
86
|
+
`1`, "专车"→`8`); otherwise ask. Only use categories present in the
|
|
87
|
+
`taxi_estimate` response; never silently substitute a different service level
|
|
88
|
+
(快车 `1` ≠ 特惠快车 `201`).
|
|
89
|
+
5. **Create order** — `taxi_create_order` with the latest `estimate_trace_id`
|
|
90
|
+
(dry-run → confirm → `--confirm`).
|
|
91
|
+
6. **Report** — order id, start/end, car type, estimated fare. Tell the user
|
|
92
|
+
they can send 「查询订单」 to check status.
|
|
93
|
+
|
|
94
|
+
## Query an order
|
|
95
|
+
|
|
96
|
+
Order id comes from (in priority): the user's message → the most recent order
|
|
97
|
+
created this conversation → else ask.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python3 $DIDI call taxi_query_order '{"order_id":"ORDER_ID"}'
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Status codes (`code`):
|
|
104
|
+
|
|
105
|
+
| code | 含义 | 输出 |
|
|
106
|
+
|------|------|------|
|
|
107
|
+
| 0 | 匹配中 | ⏳ 正在为您匹配司机 |
|
|
108
|
+
| 1 | 司机已接单 | 展示司机姓名、车型、车牌、电话、距离与预计到达时间 |
|
|
109
|
+
| 2 | 司机已到达 | 🔔 司机已到达上车点 |
|
|
110
|
+
| 4 | 行程进行中 | 🚗 行程已开始 |
|
|
111
|
+
| 5 | 订单完成 | ✅ 行程结束(展示费用,如有) |
|
|
112
|
+
| 6 | 系统取消 | ❌ 订单已被系统取消 |
|
|
113
|
+
| 7 | 已取消 | ❌ 订单已取消 |
|
|
114
|
+
| 3 / 8-12 | 其他终态 | 显示对应状态描述 |
|
|
115
|
+
|
|
116
|
+
## Routes & places (no order needed)
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
python3 $DIDI call maps_direction_driving '{"from_name":"...","from_lat":"...","from_lng":"...","to_name":"...","to_lat":"...","to_lng":"..."}'
|
|
120
|
+
python3 $DIDI call maps_direction_transit '{...}' # 公交
|
|
121
|
+
python3 $DIDI call maps_direction_walking '{...}' # 步行
|
|
122
|
+
python3 $DIDI call maps_direction_bicycling '{...}' # 骑行
|
|
123
|
+
python3 $DIDI call maps_place_around '{"keywords":"咖啡","lat":"...","lng":"..."}'
|
|
124
|
+
python3 $DIDI call maps_regeocode '{"lat":"...","lng":"..."}'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Gotchas
|
|
128
|
+
|
|
129
|
+
- **Never print the key or the raw endpoint URL** — the helper handles the
|
|
130
|
+
transport and keeps the key internal.
|
|
131
|
+
- `taxi_create_order` takes only `estimate_trace_id`, `product_category`, and
|
|
132
|
+
optional `caller_car_phone`. Don't pass the estimate's coordinate/name fields.
|
|
133
|
+
- No stored preferences: this skill doesn't remember home/work/car type — ask
|
|
134
|
+
the user, or wire richer memory in a higher layer.
|
|
135
|
+
- Auth failure surfaces as `-32002` (or HTTP 401/403): the key is missing/expired
|
|
136
|
+
→ have the user reconnect the connector.
|
|
137
|
+
|
|
138
|
+
> **Setup:** See [authentication](../_shared/authentication.md). This skill uses
|
|
139
|
+
> the `didi` connector's injected `DIDI_MCP_KEY`, not `ACEDATACLOUD_API_TOKEN`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# DiDi MCP — Tool Reference
|
|
2
|
+
|
|
3
|
+
Authoritative schemas come from `python3 $DIDI list` (the DiDi server returns
|
|
4
|
+
each tool's `inputSchema`). This file summarizes the tools and the parameter
|
|
5
|
+
names that are easy to get wrong. **All values are strings.**
|
|
6
|
+
|
|
7
|
+
## Places & geocoding
|
|
8
|
+
|
|
9
|
+
### `maps_textsearch` — search a place by text
|
|
10
|
+
| param | required | notes |
|
|
11
|
+
|-------|----------|-------|
|
|
12
|
+
| `keywords` | yes | search text, e.g. `北京西站` (NOT `keyword`) |
|
|
13
|
+
| `city` | no | city name to scope the search, e.g. `北京` (NOT `region`) |
|
|
14
|
+
|
|
15
|
+
Returns candidate places with names + coordinates. Use these coordinates for
|
|
16
|
+
`taxi_estimate` and the `maps_direction_*` tools.
|
|
17
|
+
|
|
18
|
+
### `maps_regeocode` — coordinates → address
|
|
19
|
+
| param | required |
|
|
20
|
+
|-------|----------|
|
|
21
|
+
| `lat` | yes |
|
|
22
|
+
| `lng` | yes |
|
|
23
|
+
|
|
24
|
+
## Routes
|
|
25
|
+
|
|
26
|
+
`maps_direction_driving` / `maps_direction_transit` / `maps_direction_walking`
|
|
27
|
+
/ `maps_direction_bicycling` — all take the same six fields:
|
|
28
|
+
|
|
29
|
+
| param | required |
|
|
30
|
+
|-------|----------|
|
|
31
|
+
| `from_name` | yes |
|
|
32
|
+
| `from_lat` | yes |
|
|
33
|
+
| `from_lng` | yes |
|
|
34
|
+
| `to_name` | yes |
|
|
35
|
+
| `to_lat` | yes |
|
|
36
|
+
| `to_lng` | yes |
|
|
37
|
+
|
|
38
|
+
### `maps_place_around` — nearby POI search
|
|
39
|
+
| param | required | notes |
|
|
40
|
+
|-------|----------|-------|
|
|
41
|
+
| `keywords` | yes | POI keyword, e.g. `咖啡` |
|
|
42
|
+
| `lat` | yes | center latitude |
|
|
43
|
+
| `lng` | yes | center longitude |
|
|
44
|
+
|
|
45
|
+
## Ride hailing
|
|
46
|
+
|
|
47
|
+
### `taxi_estimate` — price/ETA estimate (do this before ordering)
|
|
48
|
+
Six coordinate/name fields (same as routes):
|
|
49
|
+
`from_name`, `from_lat`, `from_lng`, `to_name`, `to_lat`, `to_lng`.
|
|
50
|
+
|
|
51
|
+
Returns a list of available car types, each with a `productCategory` and price,
|
|
52
|
+
plus a `traceId` / `estimate_trace_id` required by `taxi_create_order`. The
|
|
53
|
+
trace id expires — a stale one returns `-32021`; re-estimate to refresh.
|
|
54
|
+
|
|
55
|
+
Common `product_category` values:
|
|
56
|
+
|
|
57
|
+
| code | 车型 |
|
|
58
|
+
|------|------|
|
|
59
|
+
| `1` | 快车 |
|
|
60
|
+
| `8` | 专车 |
|
|
61
|
+
| `201` | 特惠快车 |
|
|
62
|
+
|
|
63
|
+
> Treat these as hints — always match against the `productCategory` values the
|
|
64
|
+
> live `taxi_estimate` response actually returns. `1` (快车) and `201`
|
|
65
|
+
> (特惠快车) are different service levels; never swap one for the other.
|
|
66
|
+
|
|
67
|
+
### `taxi_create_order` — book the ride ⚠️ WRITE (needs `--confirm`)
|
|
68
|
+
| param | required | notes |
|
|
69
|
+
|-------|----------|-------|
|
|
70
|
+
| `estimate_trace_id` | yes | from the latest `taxi_estimate` |
|
|
71
|
+
| `product_category` | yes | chosen car type code (string) |
|
|
72
|
+
| `caller_car_phone` | no | omit unless the user gives a number |
|
|
73
|
+
|
|
74
|
+
Only these three fields. Do **not** pass coordinate/name fields.
|
|
75
|
+
|
|
76
|
+
### `taxi_query_order` — status + driver location
|
|
77
|
+
| param | required |
|
|
78
|
+
|-------|----------|
|
|
79
|
+
| `order_id` | yes |
|
|
80
|
+
|
|
81
|
+
Status `code`: `0` 匹配中 · `1` 司机已接单 · `2` 司机已到达 · `4` 行程中 ·
|
|
82
|
+
`5` 完成 · `6` 系统取消 · `7` 已取消 · `3`/`8`-`12` 其他终态.
|
|
83
|
+
|
|
84
|
+
### `taxi_cancel_order` — cancel ⚠️ WRITE (needs `--confirm`)
|
|
85
|
+
| param | required |
|
|
86
|
+
|-------|----------|
|
|
87
|
+
| `order_id` | yes |
|
|
88
|
+
|
|
89
|
+
Always ask "确认取消吗?" before adding `--confirm`.
|
|
90
|
+
|
|
91
|
+
## Errors
|
|
92
|
+
|
|
93
|
+
| code | meaning | action |
|
|
94
|
+
|------|---------|--------|
|
|
95
|
+
| `-32002` / HTTP 401 / 403 | auth failed | key missing/expired → reconnect connector |
|
|
96
|
+
| `-32021` | estimate trace expired | re-run `taxi_estimate` |
|
|
97
|
+
| HTTP 400 | bad params | re-check parameter names against `didi.py list` |
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""DiDi ride helper — talks to the DiDi MCP server over the MCP
|
|
3
|
+
Streamable-HTTP transport using only the Python standard library.
|
|
4
|
+
|
|
5
|
+
The `didi` BYOC connector injects one env var:
|
|
6
|
+
|
|
7
|
+
DIDI_MCP_KEY the user's DiDi MCP key (secret — never printed)
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
python3 didi.py list # list available tools + schemas
|
|
11
|
+
python3 didi.py call <tool> '<json-args>' # call any tool
|
|
12
|
+
|
|
13
|
+
State-changing tools (`taxi_create_order`, `taxi_cancel_order`) are
|
|
14
|
+
gated: without a trailing `--confirm` they only DRY-RUN and change
|
|
15
|
+
nothing. `--confirm` is honored only as the LAST argument.
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
python3 didi.py call maps_textsearch '{"keywords":"北京西站","city":"北京"}'
|
|
19
|
+
python3 didi.py call taxi_estimate '{"from_name":"...","from_lat":"39.9","from_lng":"116.3","to_name":"...","to_lat":"39.9","to_lng":"116.4"}'
|
|
20
|
+
python3 didi.py call taxi_create_order '{"estimate_trace_id":"...","product_category":"1"}' --confirm
|
|
21
|
+
python3 didi.py call taxi_query_order '{"order_id":"..."}'
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
import urllib.error
|
|
30
|
+
import urllib.parse
|
|
31
|
+
import urllib.request
|
|
32
|
+
|
|
33
|
+
MCP_ENDPOINT = os.environ.get("DIDI_MCP_URL", "https://mcp.didichuxing.com/mcp-servers")
|
|
34
|
+
MCP_KEY = os.environ.get("DIDI_MCP_KEY", "").strip()
|
|
35
|
+
PROTOCOL_VERSION = "2025-06-18"
|
|
36
|
+
|
|
37
|
+
# Tools that create or cancel a real ride — must be confirmed explicitly.
|
|
38
|
+
WRITE_TOOLS = {"taxi_create_order", "taxi_cancel_order"}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def die(payload: dict, code: int = 1) -> None:
|
|
42
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
43
|
+
sys.exit(code)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class MCPClient:
|
|
47
|
+
"""Minimal MCP Streamable-HTTP client (stdlib only).
|
|
48
|
+
|
|
49
|
+
Never logs or echoes the key; the endpoint URL (which carries the
|
|
50
|
+
key as a query param) is kept internal and never printed.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(self, endpoint: str, key: str) -> None:
|
|
54
|
+
sep = "&" if "?" in endpoint else "?"
|
|
55
|
+
self._url = f"{endpoint}{sep}key={urllib.parse.quote(key, safe='')}"
|
|
56
|
+
self._session_id: str | None = None
|
|
57
|
+
self._rid = 0
|
|
58
|
+
|
|
59
|
+
def _post(self, payload: dict, expect_id):
|
|
60
|
+
body = json.dumps(payload).encode("utf-8")
|
|
61
|
+
req = urllib.request.Request(self._url, data=body, method="POST")
|
|
62
|
+
req.add_header("Content-Type", "application/json")
|
|
63
|
+
req.add_header("Accept", "application/json, text/event-stream")
|
|
64
|
+
req.add_header("MCP-Protocol-Version", PROTOCOL_VERSION)
|
|
65
|
+
if self._session_id:
|
|
66
|
+
req.add_header("Mcp-Session-Id", self._session_id)
|
|
67
|
+
try:
|
|
68
|
+
resp = urllib.request.urlopen(req, timeout=90)
|
|
69
|
+
except urllib.error.HTTPError as exc:
|
|
70
|
+
detail = exc.read().decode("utf-8", "replace")[:600]
|
|
71
|
+
die(
|
|
72
|
+
{
|
|
73
|
+
"error": f"HTTP {exc.code} from DiDi MCP",
|
|
74
|
+
"detail": detail,
|
|
75
|
+
"hint": "If 401/403, the DiDi connector key is missing or expired — "
|
|
76
|
+
"reconnect at https://auth.acedata.cloud/user/connections",
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
except urllib.error.URLError as exc:
|
|
80
|
+
die({"error": "network error reaching DiDi MCP", "detail": str(exc.reason)})
|
|
81
|
+
except Exception as exc: # noqa: BLE001
|
|
82
|
+
# Never let an unexpected traceback surface — self._url carries the
|
|
83
|
+
# key as a query param (DiDi mandates ?key=), so emit only the
|
|
84
|
+
# exception type, never its message or the URL.
|
|
85
|
+
die({"error": "unexpected error calling DiDi MCP", "detail": type(exc).__name__})
|
|
86
|
+
sid = resp.headers.get("Mcp-Session-Id")
|
|
87
|
+
if sid:
|
|
88
|
+
self._session_id = sid
|
|
89
|
+
ctype = (resp.headers.get("Content-Type") or "").lower()
|
|
90
|
+
raw = resp.read().decode("utf-8", "replace")
|
|
91
|
+
return _parse_response(raw, ctype, expect_id)
|
|
92
|
+
|
|
93
|
+
def initialize(self) -> None:
|
|
94
|
+
self._rid += 1
|
|
95
|
+
result = self._post(
|
|
96
|
+
{
|
|
97
|
+
"jsonrpc": "2.0",
|
|
98
|
+
"id": self._rid,
|
|
99
|
+
"method": "initialize",
|
|
100
|
+
"params": {
|
|
101
|
+
"protocolVersion": PROTOCOL_VERSION,
|
|
102
|
+
"capabilities": {},
|
|
103
|
+
"clientInfo": {"name": "acedata-didi-skill", "version": "1.0"},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
expect_id=self._rid,
|
|
107
|
+
)
|
|
108
|
+
if isinstance(result, dict) and result.get("error"):
|
|
109
|
+
die({"error": "DiDi MCP initialize failed", "detail": result["error"]})
|
|
110
|
+
# Fire-and-forget the initialized notification (no response expected).
|
|
111
|
+
self._post({"jsonrpc": "2.0", "method": "notifications/initialized"}, expect_id=None)
|
|
112
|
+
|
|
113
|
+
def list_tools(self):
|
|
114
|
+
self._rid += 1
|
|
115
|
+
return self._post(
|
|
116
|
+
{"jsonrpc": "2.0", "id": self._rid, "method": "tools/list"},
|
|
117
|
+
expect_id=self._rid,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def call_tool(self, name: str, arguments: dict):
|
|
121
|
+
self._rid += 1
|
|
122
|
+
return self._post(
|
|
123
|
+
{
|
|
124
|
+
"jsonrpc": "2.0",
|
|
125
|
+
"id": self._rid,
|
|
126
|
+
"method": "tools/call",
|
|
127
|
+
"params": {"name": name, "arguments": arguments},
|
|
128
|
+
},
|
|
129
|
+
expect_id=self._rid,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _parse_response(raw: str, ctype: str, expect_id):
|
|
134
|
+
"""Return the JSON-RPC envelope for our request id.
|
|
135
|
+
|
|
136
|
+
Handles both plain application/json and text/event-stream (SSE),
|
|
137
|
+
where the response arrives as one or more `data: {...}` lines.
|
|
138
|
+
"""
|
|
139
|
+
messages: list[dict] = []
|
|
140
|
+
if "text/event-stream" in ctype:
|
|
141
|
+
for line in raw.splitlines():
|
|
142
|
+
line = line.strip()
|
|
143
|
+
if not line.startswith("data:"):
|
|
144
|
+
continue
|
|
145
|
+
chunk = line[5:].strip()
|
|
146
|
+
if not chunk or chunk == "[DONE]":
|
|
147
|
+
continue
|
|
148
|
+
try:
|
|
149
|
+
messages.append(json.loads(chunk))
|
|
150
|
+
except json.JSONDecodeError:
|
|
151
|
+
continue
|
|
152
|
+
else:
|
|
153
|
+
raw = raw.strip()
|
|
154
|
+
if not raw:
|
|
155
|
+
return {}
|
|
156
|
+
try:
|
|
157
|
+
messages.append(json.loads(raw))
|
|
158
|
+
except json.JSONDecodeError:
|
|
159
|
+
die({"error": "unparseable response from DiDi MCP", "detail": raw[:600]})
|
|
160
|
+
if expect_id is not None:
|
|
161
|
+
for msg in messages:
|
|
162
|
+
if isinstance(msg, dict) and msg.get("id") == expect_id:
|
|
163
|
+
return msg
|
|
164
|
+
return messages[-1] if messages else {}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def emit(envelope: dict) -> None:
|
|
168
|
+
if not isinstance(envelope, dict):
|
|
169
|
+
print(json.dumps(envelope, ensure_ascii=False, indent=2))
|
|
170
|
+
return
|
|
171
|
+
if envelope.get("error"):
|
|
172
|
+
die({"error": envelope["error"]})
|
|
173
|
+
result = envelope.get("result", envelope)
|
|
174
|
+
# tools/call results wrap text in a content[] array.
|
|
175
|
+
if isinstance(result, dict) and isinstance(result.get("content"), list):
|
|
176
|
+
texts = [
|
|
177
|
+
c.get("text", "")
|
|
178
|
+
for c in result["content"]
|
|
179
|
+
if isinstance(c, dict) and c.get("type") == "text"
|
|
180
|
+
]
|
|
181
|
+
if texts:
|
|
182
|
+
print("\n".join(texts))
|
|
183
|
+
if result.get("isError"):
|
|
184
|
+
sys.exit(1)
|
|
185
|
+
return
|
|
186
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _format_tools(envelope: dict) -> None:
|
|
190
|
+
tools = (envelope.get("result") or {}).get("tools") if isinstance(envelope, dict) else None
|
|
191
|
+
if not tools:
|
|
192
|
+
emit(envelope)
|
|
193
|
+
return
|
|
194
|
+
slim = [
|
|
195
|
+
{
|
|
196
|
+
"name": t.get("name"),
|
|
197
|
+
"description": t.get("description"),
|
|
198
|
+
"inputSchema": t.get("inputSchema"),
|
|
199
|
+
}
|
|
200
|
+
for t in tools
|
|
201
|
+
]
|
|
202
|
+
print(json.dumps(slim, ensure_ascii=False, indent=2))
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def main() -> None:
|
|
206
|
+
if not MCP_KEY:
|
|
207
|
+
die(
|
|
208
|
+
{
|
|
209
|
+
"error": "DIDI_MCP_KEY not set",
|
|
210
|
+
"hint": "Connect the DiDi connector at "
|
|
211
|
+
"https://auth.acedata.cloud/user/connections to inject the key.",
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
argv = sys.argv[1:]
|
|
216
|
+
confirm = bool(argv) and argv[-1] == "--confirm"
|
|
217
|
+
if confirm:
|
|
218
|
+
argv = argv[:-1]
|
|
219
|
+
if not argv:
|
|
220
|
+
die({"error": "usage: didi.py <list|call> ..."})
|
|
221
|
+
|
|
222
|
+
cmd, rest = argv[0], argv[1:]
|
|
223
|
+
client = MCPClient(MCP_ENDPOINT, MCP_KEY)
|
|
224
|
+
|
|
225
|
+
if cmd == "list":
|
|
226
|
+
client.initialize()
|
|
227
|
+
_format_tools(client.list_tools())
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
if cmd == "call":
|
|
231
|
+
if not rest:
|
|
232
|
+
die({"error": "call needs a tool name", "usage": "didi.py call <tool> '<json-args>'"})
|
|
233
|
+
tool = rest[0]
|
|
234
|
+
args_raw = rest[1] if len(rest) > 1 else "{}"
|
|
235
|
+
try:
|
|
236
|
+
arguments = json.loads(args_raw)
|
|
237
|
+
except json.JSONDecodeError as exc:
|
|
238
|
+
die({"error": "arguments must be valid JSON", "detail": str(exc), "got": args_raw})
|
|
239
|
+
if not isinstance(arguments, dict):
|
|
240
|
+
die({"error": "arguments JSON must be an object", "got": args_raw})
|
|
241
|
+
|
|
242
|
+
if tool in WRITE_TOOLS and not confirm:
|
|
243
|
+
print(
|
|
244
|
+
json.dumps(
|
|
245
|
+
{
|
|
246
|
+
"dry_run": True,
|
|
247
|
+
"tool": tool,
|
|
248
|
+
"arguments": arguments,
|
|
249
|
+
"note": "state-changing call — re-run with --confirm as the LAST "
|
|
250
|
+
"argument to actually perform it",
|
|
251
|
+
},
|
|
252
|
+
ensure_ascii=False,
|
|
253
|
+
indent=2,
|
|
254
|
+
)
|
|
255
|
+
)
|
|
256
|
+
return
|
|
257
|
+
|
|
258
|
+
client.initialize()
|
|
259
|
+
emit(client.call_tool(tool, arguments))
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
die({"error": f"unknown command: {cmd}", "usage": "didi.py <list|call> ..."})
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if __name__ == "__main__":
|
|
266
|
+
main()
|