maoyan-mcp
# maoyan-mcp(猫眼 + 大麦票务查询 MCP)
一个只读的 MCP(模型上下文协议)服务器:让 AI 助手查询猫眼电影排片、
猫眼演出和大麦演出信息。只做查询,不下单、不抢票、不支付。
> **English summary**: A read-only MCP server (FastMCP, stdio) for querying
> Maoyan movie showtimes and performance listings and Damai performance
> listings in China. Query-only — no ordering, no ticket grabbing, no
> payments. See NOTES.md for endpoint research (kept out of git by default).
## 功能
### 猫眼
| 工具 | 说明 | 需要登录 |
|---|---|---|
| `get_hot_movies` | 正在热映(全国热映榜) | 否 |
| `get_coming_movies` | 即将上映(按城市) | 否 |
| `search_movies` | 按片名搜索电影 | 否 |
| `get_movie_detail` | 电影详情:类型、导演、时长、评分、简介 | 否 |
| `list_cinemas` | 某城市影院列表,可按名/地址筛选 | 否 |
| `get_cinema_showtimes` | 某影院排片:场次时间、影厅、版本、语言 | 否 |
| `get_hot_performances` | 某城市热门演出列表 | 否 |
| `search_performances` | 在热门演出列表内按关键词/分类筛选 | 否 |
| `get_performance_detail` | 演出详情:时间、城市、场馆、票价档、开售时间 | 否 |
| `get_performance_tickets` | 演出场次与票档:时间、票档名、票面价/实售价、余票、限购(预售和已开售都已实测) | **是** |
| `auth_status` / `import_cookie` / `logout` | 登录状态 / Cookie 导入 / 退出 | — |
| `send_sms_code` / `login_with_sms` | **暂未实现**(见下) | — |
### 大麦
大麦没有电影排片,只有演出。工具名都带 `damai_` 前缀。
| 工具 | 说明 | 需要登录 |
|---|---|---|
| `damai_get_hot_performances` | 大麦热门演出列表,可按城市/分类筛选 | 否 |
| `damai_search_performances` | 在热门榜内按关键词(片名/艺人/场馆)筛选 | 否 |
| `damai_get_performance_detail` | 演出详情:时间、城市、场馆、票价区间、开售时间、艺人 | 否 |
| `damai_get_performance_tickets` | 演出场次与票档(见“已知限制”:目前场次不可用) | 部分 |
| `damai_auth_status` / `damai_import_cookie` / `damai_logout` | 大麦登录状态 / Cookie 导入 / 退出 | — |
| `damai_send_sms_code` / `damai_login_with_sms` | **暂未实现**(见下) | — |
## 安装
```bash
git clone https://github.com/<you>/maoyan-mcp.git
cd maoyan-mcp
python3 -m venv .venv
.venv/bin/pip install -e .
```
Python ≥ 3.10。依赖只有 `fastmcp` 和 `httpx`。
## 在 MCP 客户端里使用
以 Claude Desktop / Cursor 等为例,在 MCP 配置里加:
```json
{
"mcpServers": {
"maoyan": {
"command": "/path/to/maoyan-mcp/.venv/bin/maoyan-mcp"
}
}
}
```
也可以直接跑:`.venv/bin/python -m maoyan_mcp`(stdio 传输)。
冒烟测试(无需登录,真实联网查询):
```bash
.venv/bin/python scripts/smoke.py # 猫眼电影 + 演出
.venv/bin/python scripts/smoke_damai.py # 大麦热门 / 搜索 / 详情
```
演出票档冒烟测试(需要先 `import_cookie` 登录,真实联网查询):
```bash
.venv/bin/python scripts/smoke_tickets.py [演出编号 ...]
# 默认查 518642([第25小时]跨年演唱会)和 509000(话剧《茶馆》)
.venv/bin/python scripts/smoke_damai_tickets.py [演出编号 ...]
# 默认查 1095761949422(周传雄深圳站)和 1101026106334(回春丹佛山站)
```
大麦登录单独验证(不保存凭证,Cookie 只从 stdin 读):
```bash
printf '%s' 'cookie2=...; tb_token_=...; ...' \
| .venv/bin/python scripts/test_damai_auth.py
```
## 登录
**绝大多数查询不需要登录。** 只有演出场次与票档(`get_performance_tickets`)
需要登录,因为猫眼的场次接口未登录会返回“请先登录”。
### 短信验证码登录:暂未实现
`send_sms_code` / `login_with_sms` 调用时会明确返回不可用,不会假装成功。
原因是美团/大众点评的登录流程必须先通过滑块验证(verify.meituan.com,
yoda),其 `behavior` / `_token` 参数与真实浏览器里的滑动轨迹绑定,
没有纯接口的短信登录流程。详见 NOTES.md。
### 可用的后备方式:导入 Cookie
1. 在浏览器里登录[大众点评](https://www.dianping.com),用和猫眼同一个手机号。
注意:只登录猫眼演出拿不到这个 Cookie,实测猫眼演出站本身没有 `.dianping.com` 的 Cookie,只有登录大众点评后才有 `dper`;
2. 开发者工具 → Application → Cookies → `.dianping.com`,复制 `dper` 的值;
3. 调 `import_cookie`,传入 `dper=<值>`。
工具会先拿这个凭证去猫眼校验,通过后才保存在本机
`~/.maoyan-mcp/auth.json`(文件权限 0600),凭证只存本机、不上传、
不写入代码或日志。`logout` 可删除它。
> 大众点评 App 扫码登录是另一条已验证可行的路(catbus 项目在用),
> 但它需要 H5guard 的 JS 签名,本项目 MVP 未实现,见 NOTES.md。
### 大麦登录:导入淘宝登录 Cookie(没有 SESSION)
大麦的登录是淘宝/支付宝账号体系,短信登录同样需要先过滑块验证
或 App 扫码,没有纯接口流程,所以 `damai_send_sms_code` /
`damai_login_with_sms` 也明确返回不可用。
后备方式与猫眼相同,只是 Cookie 不同:**大麦现在的登录里没有
`SESSION` 这个 Cookie**(2026-12-03 用真实登录验证过:已登录
的浏览器里,passport.damai.cn 和 www.damai.cn 的 `.damai.cn`
Cookie 列表里都没有 `SESSION` 这一行)。登录校验用的是淘宝的
登录 Cookie 组合,必须带上:
- 必需:`cookie2`(淘宝登录会话)+ `tb_token_`(Damai H5 里
叫这个名字,淘宝侧也写作 `_tb_token_`);
- 一起导入更好:`cna`、`t`、`_hvn_login`、`damai.cn_user`、
`damai.cn_nickName`、`isg`、`sgcookie` 等其余 `.damai.cn`
登录 Cookie;`_m_h5_tk` / `_m_h5_tk_enc` 不用复制,程序每次
调用时会自己向网关领新的。
步骤:
1. 在浏览器里登录[大麦](https://www.damai.cn);
2. 开发者工具 → Application → Cookies → `.damai.cn`,在列表里
找到 `cookie2`、`tb_token_` 等,双击 Value 单元格复制完整值
(值很长,单击只选中一部分,必须双击复制);
3. 调 `damai_import_cookie`,传入整串
`cookie2=<值>; tb_token_=<值>; cna=<值>; ...`。
工具会先拿这组凭证去大麦的登录接口校验(未通过则不保存),通过后
保存在本机 `~/.maoyan-mcp/damai_auth.json`(文件权限 0600),与猫眼
的凭证分开存。登录 Cookie 会过期,过期后需重新登录、重新导入。
**注意:这条登录链路尚未用真实登录验证过**(构建时没有可用的
大麦登录),见“已知限制”。想先单独验证登录而不保存凭证,可跑
`scripts/test_damai_auth.py`(Cookie 只从 stdin 读,不会打印出来)。
## 已知限制(诚实说明,不伪造数据)
### 大麦
- **按场次查票档目前不可用**:大麦公开的 H5 详情接口目前不返回
场次列表(`performBases` 为空,多个项目、多种参数都试过),且按
场次查票档的接口本身也需要登录。`damai_get_performance_tickets`
因此只返回演出的时间范围与票价区间,并如实说明场次不可用,
不编造场次和票价。等大麦恢复返回场次列表后,代码里已留好
按场次查票档的路径(需配合 `damai_import_cookie` 的登录 Cookie)。
- **没有公开的关键词搜索接口**:`damai_search_performances` 是在
热门榜(最多 150 条)内按关键词筛选,不是全库搜索;查指定演出
请用演出编号调 `damai_get_performance_detail`。
- **热门榜是全国榜**:大麦的榜单接口忽略城市参数,城市筛选是在
本地按场馆城市做的;小城市(如东莞、惠州)在前 150 条热门里
可能一条都没有,这不代表当地没有演出,只是榜单覆盖不到。
- **大麦登录链路未实测**:`damai_import_cookie` 的校验逻辑是按
上游接口的返回码写的,但构建时没有真实的大麦登录 Cookie 可用,
没有验证通过;用真实登录导入后请先跑
`scripts/test_damai_auth.py`(只从 stdin 读 Cookie,不保存)
或 `scripts/smoke_damai_tickets.py` 验证。另:大麦现在的登录
里没有 `SESSION` 这个 Cookie,见“大麦登录”一节,不要只传
`SESSION`。
### 猫眼
- **售价不完整**:电影场次的售价是猫眼“石墨字体”加密的,接口返回的是
自定义字体码位而非数字,无法直接解析。本项目不猜价格,
`sell_price` 返回空,只返回明文的影城卡价 `vip_price`(如有),
并在结果里注明原因。影院列表里的起售价是明文的,可以正常看。
- **排片只覆盖今天起 3 天**:这是猫眼接口本身的范围,更远的日期暂无排片。
- **演出没有公开的关键词搜索接口**:`search_performances` 是在该城市
热门演出列表内筛选,不是全库搜索;查指定演出请用演出编号调
`get_performance_detail`。
- **热门演出榜不是严格的本地表**:`cityId` 确实会改变榜单(深圳、东莞、
惠州三城返回的编号完全不同),但榜单是按城市精选的“热门” feed,个别
条目是巡演项目、在其他城市开售(条目里的 `on_sale_text` 会注明,如
“哈尔滨已开售”)。想确认演出到底在哪个城市演,请看
`get_performance_detail` / `get_performance_tickets` 返回的城市和场馆。
- **个别票档没有名字**:上游对某些座位区票档只给价格和颜色,不给名字
(如话剧《茶馆》的 380/280/180/100 四档),本项目返回 `name: null`,
不编造名字。
- **演出详情接口不稳定**:`get_performance_detail` 在 2026-12-03 实测时
成功过一次,随后持续返回 403(疑似上游风控)。工具会如实返回上游
错误,不编造数据;热门演出列表本身稳定可用。
- **12 月 5 日的排片可能还没放出来**:以 2026-12-03 实测为例,东莞石龙
的影院里《饥饿游戏:收获日出》只排到 12 月 4 日,12 月 5 日尚无场次,
这是真实数据,不是接口故障。
## 平台结构
`src/maoyan_mcp/providers/` 是按平台拆的:`maoyan.py` 实现猫眼,
`damai.py` 实现大麦,`__init__.py` 里是 provider 的最小约定
(`TicketProvider`)。新平台照此加一个 provider 文件,在 `server.py`
里按平台分发即可。
## 免责声明
- 本项目与猫眼、大麦无关,是非官方的个人学习/研究项目。
- 请遵守猫眼、大麦的服务条款;仅以普通浏览的频率查询,不要高频抓取,
不要用于批量爬取或抢票。
- 两家接口都未公开,随时可能变更或加风控;接口失效时工具会返回明确的
上游错误,而不是假数据。
## License
MIT
TDQS
Scored across 24 tools
The maoyan vs damai_ prefixed tools are mostly separable, but the parallel performance tools (search_performances vs get_hot_performances, and the four damai equivalents) blur together, and search_performances is described as a hot list rather than a keyword search. Four tools are explicitly marked 【暂未实现】 (send_sms_code, login_with_sms, damai_send_sms_code, damai_login_with_sms), which are dead ends an agent may still pick. The login story (import_cookie vs SMS login vs auth_status) also has overlapping intent.
The verb_noun pattern is followed consistently (get_, list_, search_, import_, send_, login_with_), which is good. However, the namespace is asymmetric: damai tools carry a damai_ prefix while the equivalent Maoyan tools have no prefix, so identical concepts look like different families. The suffix naming (search_performances vs damai_search_performances) makes the pairing readable but not predictable.
24 tools is heavy for a read-only discovery server, and four of them are unimplemented stubs that consume slots without adding capability. The movie/cinema/performance/damai breakdown is logical, but trimming the non-functional auth tools would make the set much tighter.
Discovery coverage is solid for movies (hot, coming, search, detail, cinemas, showtimes) and performances (hot, search, detail, tickets) across both Maoyan and Damai. But the surface stops at browsing: no seat maps, no order/booking flow, and get_cinema_showtimes returns empty prices due to encryption, leaving a dead end. The auth lifecycle is half-finished since SMS login paths are declared unavailable.