xiaohongshu-mcp-node 1.0.0

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.
Files changed (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +306 -0
  3. package/dist/actions/comment.action.d.ts +9 -0
  4. package/dist/actions/comment.action.d.ts.map +1 -0
  5. package/dist/actions/comment.action.js +38 -0
  6. package/dist/actions/comment.action.js.map +1 -0
  7. package/dist/actions/feed-detail.action.d.ts +17 -0
  8. package/dist/actions/feed-detail.action.d.ts.map +1 -0
  9. package/dist/actions/feed-detail.action.js +166 -0
  10. package/dist/actions/feed-detail.action.js.map +1 -0
  11. package/dist/actions/interaction.action.d.ts +12 -0
  12. package/dist/actions/interaction.action.d.ts.map +1 -0
  13. package/dist/actions/interaction.action.js +75 -0
  14. package/dist/actions/interaction.action.js.map +1 -0
  15. package/dist/actions/login.action.d.ts +12 -0
  16. package/dist/actions/login.action.d.ts.map +1 -0
  17. package/dist/actions/login.action.js +52 -0
  18. package/dist/actions/login.action.js.map +1 -0
  19. package/dist/actions/publish-video.action.d.ts +17 -0
  20. package/dist/actions/publish-video.action.d.ts.map +1 -0
  21. package/dist/actions/publish-video.action.js +139 -0
  22. package/dist/actions/publish-video.action.js.map +1 -0
  23. package/dist/actions/publish.action.d.ts +19 -0
  24. package/dist/actions/publish.action.d.ts.map +1 -0
  25. package/dist/actions/publish.action.js +157 -0
  26. package/dist/actions/publish.action.js.map +1 -0
  27. package/dist/actions/search.action.d.ts +23 -0
  28. package/dist/actions/search.action.d.ts.map +1 -0
  29. package/dist/actions/search.action.js +121 -0
  30. package/dist/actions/search.action.js.map +1 -0
  31. package/dist/config/index.d.ts +4 -0
  32. package/dist/config/index.d.ts.map +1 -0
  33. package/dist/config/index.js +15 -0
  34. package/dist/config/index.js.map +1 -0
  35. package/dist/config/schema.d.ts +34 -0
  36. package/dist/config/schema.d.ts.map +1 -0
  37. package/dist/config/schema.js +18 -0
  38. package/dist/config/schema.js.map +1 -0
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +31 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/mcp/server.d.ts +22 -0
  44. package/dist/mcp/server.d.ts.map +1 -0
  45. package/dist/mcp/server.js +251 -0
  46. package/dist/mcp/server.js.map +1 -0
  47. package/dist/mcp/tools/index.d.ts +3 -0
  48. package/dist/mcp/tools/index.d.ts.map +1 -0
  49. package/dist/mcp/tools/index.js +264 -0
  50. package/dist/mcp/tools/index.js.map +1 -0
  51. package/dist/services/browser.service.d.ts +15 -0
  52. package/dist/services/browser.service.d.ts.map +1 -0
  53. package/dist/services/browser.service.js +67 -0
  54. package/dist/services/browser.service.js.map +1 -0
  55. package/dist/services/cookie.service.d.ts +9 -0
  56. package/dist/services/cookie.service.d.ts.map +1 -0
  57. package/dist/services/cookie.service.js +49 -0
  58. package/dist/services/cookie.service.js.map +1 -0
  59. package/dist/services/xiaohongshu.service.d.ts +32 -0
  60. package/dist/services/xiaohongshu.service.d.ts.map +1 -0
  61. package/dist/services/xiaohongshu.service.js +194 -0
  62. package/dist/services/xiaohongshu.service.js.map +1 -0
  63. package/dist/types/xiaohongshu.types.d.ts +55 -0
  64. package/dist/types/xiaohongshu.types.d.ts.map +1 -0
  65. package/dist/types/xiaohongshu.types.js +2 -0
  66. package/dist/types/xiaohongshu.types.js.map +1 -0
  67. package/dist/utils/image-processor.d.ts +11 -0
  68. package/dist/utils/image-processor.d.ts.map +1 -0
  69. package/dist/utils/image-processor.js +75 -0
  70. package/dist/utils/image-processor.js.map +1 -0
  71. package/dist/utils/logger.d.ts +2 -0
  72. package/dist/utils/logger.d.ts.map +1 -0
  73. package/dist/utils/logger.js +14 -0
  74. package/dist/utils/logger.js.map +1 -0
  75. package/dist/utils/title-validator.d.ts +3 -0
  76. package/dist/utils/title-validator.d.ts.map +1 -0
  77. package/dist/utils/title-validator.js +39 -0
  78. package/dist/utils/title-validator.js.map +1 -0
  79. package/dist/utils/wait-helper.d.ts +5 -0
  80. package/dist/utils/wait-helper.d.ts.map +1 -0
  81. package/dist/utils/wait-helper.js +46 -0
  82. package/dist/utils/wait-helper.js.map +1 -0
  83. package/package.json +75 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # 🌸 xiaohongshu-mcp-node
2
+
3
+ > 基于 Model Context Protocol 的小红书自动化工具 - 让 AI 助手轻松操作小红书
4
+
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
6
+ [![Node.js](https://img.shields.io/badge/Node.js-20+-green?style=flat-square&logo=node.js)](https://nodejs.org/)
7
+ [![Playwright](https://img.shields.io/badge/Playwright-1.40-orange?style=flat-square&logo=playwright)](https://playwright.dev/)
8
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue?style=flat-square)](LICENSE)
9
+
10
+ **xiaohongshu-mcp-node** 是 [xiaohongshu-mcp](https://github.com/xpzouying/xiaohongshu-mcp) 的 Node.js/TypeScript 重写版本,提供了更现代化的开发体验和更强大的浏览器自动化能力。
11
+
12
+ ## ✨ 核心特性
13
+
14
+ - 🎯 **完整的 MCP 协议支持** - 13 个精心设计的工具,与 Claude Desktop、Cline 等 AI 客户端无缝集成
15
+ - 🚀 **现代化技术栈** - TypeScript + Playwright + Zod,类型安全、开发高效
16
+ - 🔐 **安全的登录机制** - 官方二维码登录,Cookie 自动持久化
17
+ - 📝 **强大的发布能力** - 支持图文/视频发布、多图上传、标签管理、定时发布、原创声明
18
+ - 🔍 **智能内容获取** - 搜索、筛选、详情抓取、评论加载,一应俱全
19
+ - 💬 **完善的互动功能** - 评论、回复、点赞、收藏,全方位互动支持
20
+ - 🛠️ **开发者友好** - 清晰的分层架构、完整的类型定义、详细的日志输出
21
+
22
+ ## 🚀 快速开始
23
+
24
+ ### 📦 安装
25
+
26
+ ```bash
27
+ # 克隆项目
28
+ git clone https://github.com/yourusername/xiaohongshu-mcp-node.git
29
+ cd xiaohongshu-mcp-node
30
+
31
+ # 安装依赖
32
+ npm install
33
+
34
+ # 安装 Playwright 浏览器
35
+ npx playwright install chromium
36
+ ```
37
+
38
+ ### 🔑 首次登录
39
+
40
+ 在使用任何功能前,需要先登录小红书账号:
41
+
42
+ ```bash
43
+ npm run login
44
+ ```
45
+
46
+ 这将打开浏览器窗口,显示小红书登录二维码。使用**小红书 App** 扫码登录后,Cookie 会自动保存到本地,后续操作无需重复登录。
47
+
48
+ ### ▶️ 运行服务
49
+
50
+ ```bash
51
+ # 开发模式(支持热重载)
52
+ npm run dev
53
+
54
+ # 生产模式
55
+ npm run build
56
+ npm start
57
+ ```
58
+
59
+ ## 📁 项目结构
60
+
61
+ ```
62
+ xiaohongshu-mcp-node/
63
+ ├── src/
64
+ │ ├── config/ # 📋 配置管理
65
+ │ │ ├── schema.ts # Zod 配置模式定义
66
+ │ │ └── index.ts # 配置加载器
67
+ │ ├── services/ # 🔧 业务服务层
68
+ │ │ ├── browser.service.ts # Playwright 浏览器管理
69
+ │ │ ├── cookie.service.ts # Cookie 持久化
70
+ │ │ └── xiaohongshu.service.ts # 业务逻辑封装
71
+ │ ├── actions/ # 🎬 小红书操作层
72
+ │ │ ├── login.action.ts # 登录操作
73
+ │ │ ├── publish.action.ts # 图文发布
74
+ │ │ ├── publish-video.action.ts # 视频发布
75
+ │ │ ├── search.action.ts # 搜索功能
76
+ │ │ ├── feed-detail.action.ts # 内容详情
77
+ │ │ ├── comment.action.ts # 评论功能
78
+ │ │ └── interaction.action.ts # 互动操作
79
+ │ ├── mcp/ # 🔌 MCP 协议层
80
+ │ │ ├── server.ts # MCP Server 实现
81
+ │ │ └── tools/ # 工具定义
82
+ │ ├── utils/ # 🛠️ 工具函数
83
+ │ │ ├── logger.ts # Pino 日志系统
84
+ │ │ ├── image-processor.ts # 图片处理
85
+ │ │ ├── title-validator.ts # 标题验证
86
+ │ │ └── wait-helper.ts # 等待辅助
87
+ │ ├── types/ # 📝 TypeScript 类型定义
88
+ │ └── index.ts # 🚪 主入口
89
+ ├── scripts/
90
+ │ └── login.ts # 登录脚本
91
+ ├── examples/ # 💡 使用示例
92
+ │ ├── publish-image.ts
93
+ │ └── search.ts
94
+ └── package.json
95
+ ```
96
+
97
+ ## ⚙️ 配置说明
98
+
99
+ ### 环境变量
100
+
101
+ 复制 `.env.example` 为 `.env` 并根据需要修改:
102
+
103
+ ```bash
104
+ cp .env.example .env
105
+ ```
106
+
107
+ | 配置项 | 说明 | 默认值 | 必填 |
108
+ |--------|------|--------|------|
109
+ | `PORT` | 服务端口 | `18060` | ❌ |
110
+ | `HOST` | 服务地址 | `0.0.0.0` | ❌ |
111
+ | `HEADLESS` | 无头模式 | `true` | ❌ |
112
+ | `BROWSER_BIN_PATH` | 浏览器路径 | 自动检测 | ❌ |
113
+ | `XHS_PROXY` | 代理服务器 | - | ❌ |
114
+ | `COOKIES_PATH` | Cookie 文件路径 | `./cookies.json` | ❌ |
115
+ | `LOG_LEVEL` | 日志级别 | `info` | ❌ |
116
+ | `PAGE_TIMEOUT` | 页面超时(毫秒) | `300000` | ❌ |
117
+ | `UPLOAD_TIMEOUT` | 上传超时(毫秒) | `60000` | ❌ |
118
+
119
+ ## 📝 功能特性
120
+
121
+ ### ✅ 已实现功能
122
+
123
+ #### 登录管理
124
+ - ✅ 登录状态检查
125
+ - ✅ 二维码登录
126
+ - ✅ Cookie 管理
127
+
128
+ #### 内容发布
129
+ - ✅ 发布图文内容(支持多图、标签、定时发布、原创声明)
130
+ - ✅ 发布视频内容(支持标签、定时发布)
131
+ - ✅ 图片自动下载(支持 URL)
132
+ - ✅ 标题验证(20字限制)
133
+
134
+ #### 内容获取
135
+ - ✅ 搜索内容(支持筛选)
136
+ - ✅ 获取推荐列表
137
+ - ✅ 获取内容详情
138
+ - ✅ 加载评论
139
+
140
+ #### 互动功能
141
+ - ✅ 发表评论
142
+ - ✅ 回复评论
143
+ - ✅ 点赞/取消点赞
144
+ - ✅ 收藏/取消收藏
145
+
146
+ #### MCP 协议
147
+ - ✅ 完整的 MCP Server 实现
148
+ - ✅ 13 个 MCP 工具
149
+ - ✅ 与 AI 客户端集成(Claude Desktop、Cline 等)
150
+
151
+ ## 🔌 MCP 集成指南
152
+
153
+ ### 与 Claude Desktop 集成
154
+
155
+ 1. **构建项目**
156
+ ```bash
157
+ npm run build
158
+ ```
159
+
160
+ 2. **配置 Claude Desktop**
161
+
162
+ 编辑配置文件(根据操作系统选择):
163
+
164
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
165
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
166
+ - **Linux**: `~/.config/Claude/claude_desktop_config.json`
167
+
168
+ ```json
169
+ {
170
+ "mcpServers": {
171
+ "xiaohongshu": {
172
+ "command": "node",
173
+ "args": ["/absolute/path/to/xiaohongshu-mcp-node/dist/index.js"],
174
+ "env": {
175
+ "HEADLESS": "true",
176
+ "COOKIES_PATH": "/absolute/path/to/cookies.json"
177
+ }
178
+ }
179
+ }
180
+ }
181
+ ```
182
+
183
+ 3. **重启 Claude Desktop**
184
+
185
+ 配置完成后,重启 Claude Desktop 即可在对话中使用小红书功能。
186
+
187
+ ### 📚 可用的 MCP 工具
188
+
189
+ | 工具名称 | 功能描述 | 主要参数 |
190
+ |---------|---------|---------|
191
+ | `check_login_status` | 检查登录状态 | - |
192
+ | `get_login_qrcode` | 获取登录二维码 | - |
193
+ | `delete_cookies` | 删除 cookies | - |
194
+ | `publish_content` | 发布图文内容 | title, content, images, tags |
195
+ | `publish_video` | 发布视频内容 | title, content, video, tags |
196
+ | `search_feeds` | 搜索内容 | keyword, filters |
197
+ | `list_feeds` | 获取推荐列表 | - |
198
+ | `get_feed_detail` | 获取内容详情 | feedId, xsecToken |
199
+ | `post_comment` | 发表评论 | feedId, xsecToken, content |
200
+ | `reply_comment` | 回复评论 | feedId, xsecToken, commentId, content |
201
+ | `like_feed` | 点赞/取消点赞 | feedId, xsecToken, unlike |
202
+ | `favorite_feed` | 收藏/取消收藏 | feedId, xsecToken, unfavorite |
203
+
204
+ ### 💡 使用示例
205
+
206
+ 在 Claude Desktop 中,你可以这样使用:
207
+
208
+ ```
209
+ 帮我发布一篇小红书笔记,标题是"Node.js 开发技巧",
210
+ 内容是"分享一些实用的 Node.js 开发经验...",
211
+ 使用这三张图片:[图片路径],添加标签:Node.js、编程、技术分享
212
+ ```
213
+
214
+ Claude 会自动调用 `publish_content` 工具完成发布。
215
+
216
+ ## �️ 开发
217
+
218
+ ```bash
219
+ # 开发模式
220
+ npm run dev
221
+
222
+ # 类型检查
223
+ npm run build
224
+
225
+ # 代码格式化
226
+ npm run format
227
+
228
+ # 代码检查
229
+ npm run lint
230
+ ```
231
+
232
+ ## 📂 项目架构
233
+
234
+ ```
235
+ src/
236
+ ├── config/ # 配置管理(Zod 验证)
237
+ ├── services/ # 业务服务层
238
+ │ ├── browser.service.ts # 浏览器管理(Playwright)
239
+ │ ├── cookie.service.ts # Cookie 持久化
240
+ │ └── xiaohongshu.service.ts # 业务逻辑封装
241
+ ├── actions/ # 小红书操作层
242
+ │ ├── login.action.ts # 登录操作
243
+ │ ├── publish.action.ts # 发布图文
244
+ │ ├── publish-video.action.ts # 发布视频
245
+ │ ├── search.action.ts # 搜索
246
+ │ ├── feed-detail.action.ts # 详情
247
+ │ ├── comment.action.ts # 评论
248
+ │ └── interaction.action.ts # 互动
249
+ ├── mcp/ # MCP 协议层
250
+ │ ├── server.ts # MCP Server
251
+ │ └── tools/ # 工具定义
252
+ ├── utils/ # 工具函数
253
+ │ ├── logger.ts # 日志(Pino)
254
+ │ ├── image-processor.ts # 图片处理
255
+ │ ├── title-validator.ts # 标题验证
256
+ │ └── wait-helper.ts # 等待辅助
257
+ └── types/ # TypeScript 类型定义
258
+ ```
259
+
260
+ ## 🎯 为什么选择 Node.js 版本?
261
+
262
+ 相比 Go 原版,Node.js 版本提供了:
263
+
264
+ - ✅ **更快的开发迭代** - TypeScript 热重载,无需编译等待
265
+ - ✅ **更成熟的浏览器自动化** - Playwright 生态完善,文档丰富
266
+ - ✅ **更好的调试体验** - Chrome DevTools 原生支持
267
+ - ✅ **更丰富的生态系统** - npm 海量包,开箱即用
268
+ - ✅ **更低的学习曲线** - JavaScript/TypeScript 开发者友好
269
+
270
+ ## 🤝 贡献
271
+
272
+ 欢迎提交 Issue 和 Pull Request!
273
+
274
+ 在提交 PR 前,请确保:
275
+ - 代码通过 ESLint 检查:`npm run lint`
276
+ - 代码格式符合规范:`npm run format`
277
+ - TypeScript 编译无错误:`npm run build`
278
+
279
+ ## 📄 开源协议
280
+
281
+ 本项目采用 [Apache-2.0](LICENSE) 协议开源。
282
+
283
+ ## 🙏 致谢与声明
284
+
285
+ ### 致谢
286
+
287
+ 本项目是 [xiaohongshu-mcp](https://github.com/xpzouying/xiaohongshu-mcp) 的 Node.js/TypeScript 重写版本。
288
+
289
+ 特别感谢:
290
+ - [xpzouying](https://github.com/xpzouying) - 原项目作者,提供了优秀的设计思路
291
+ - [Anthropic](https://www.anthropic.com/) - Model Context Protocol 的创建者
292
+ - [Playwright](https://playwright.dev/) - 强大的浏览器自动化框架
293
+
294
+ ### 免责声明
295
+
296
+ 本项目仅供学习和研究使用,请勿用于任何商业用途或违反小红书服务条款的行为。使用本工具产生的任何后果由使用者自行承担。
297
+
298
+ ---
299
+
300
+ <div align="center">
301
+
302
+ **如果这个项目对你有帮助,请给它一个 ⭐️ Star!**
303
+
304
+ Made with ❤️ by the community
305
+
306
+ </div>
@@ -0,0 +1,9 @@
1
+ import type { Page } from 'playwright';
2
+ export declare class CommentAction {
3
+ private page;
4
+ constructor(page: Page);
5
+ postComment(feedId: string, xsecToken: string, content: string): Promise<void>;
6
+ replyComment(feedId: string, xsecToken: string, commentId: string, content: string): Promise<void>;
7
+ private navigateToFeed;
8
+ }
9
+ //# sourceMappingURL=comment.action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment.action.d.ts","sourceRoot":"","sources":["../../src/actions/comment.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,qBAAa,aAAa;IACZ,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI;IAExB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe9E,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;YAqBF,cAAc;CAK7B"}
@@ -0,0 +1,38 @@
1
+ import { logger } from '../utils/logger.js';
2
+ import { waitForElement, clickWithRetry } from '../utils/wait-helper.js';
3
+ export class CommentAction {
4
+ page;
5
+ constructor(page) {
6
+ this.page = page;
7
+ }
8
+ async postComment(feedId, xsecToken, content) {
9
+ await this.navigateToFeed(feedId, xsecToken);
10
+ const commentInput = await waitForElement(this.page, '.comment-input textarea');
11
+ await commentInput.fill(content);
12
+ await this.page.waitForTimeout(500);
13
+ const submitButton = this.page.locator('.comment-submit-button').first();
14
+ await clickWithRetry(submitButton);
15
+ await this.page.waitForTimeout(2000);
16
+ logger.info('Comment posted', { feedId, contentLength: content.length });
17
+ }
18
+ async replyComment(feedId, xsecToken, commentId, content) {
19
+ await this.navigateToFeed(feedId, xsecToken);
20
+ const commentElement = this.page.locator(`[data-id="${commentId}"]`).first();
21
+ const replyButton = commentElement.locator('.reply-button').first();
22
+ await clickWithRetry(replyButton);
23
+ await this.page.waitForTimeout(500);
24
+ const replyInput = await waitForElement(this.page, '.reply-input textarea');
25
+ await replyInput.fill(content);
26
+ await this.page.waitForTimeout(500);
27
+ const submitButton = this.page.locator('.reply-submit-button').first();
28
+ await clickWithRetry(submitButton);
29
+ await this.page.waitForTimeout(2000);
30
+ logger.info('Reply posted', { feedId, commentId, contentLength: content.length });
31
+ }
32
+ async navigateToFeed(feedId, xsecToken) {
33
+ const url = `https://www.xiaohongshu.com/explore/${feedId}?xsec_token=${xsecToken}`;
34
+ await this.page.goto(url, { waitUntil: 'domcontentloaded' });
35
+ await this.page.waitForTimeout(2000);
36
+ }
37
+ }
38
+ //# sourceMappingURL=comment.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment.action.js","sourceRoot":"","sources":["../../src/actions/comment.action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IAElC,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,SAAiB,EAAE,OAAe;QAClE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QAChF,MAAM,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAEpC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,KAAK,EAAE,CAAC;QACzE,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC;QAEnC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAErC,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,MAAc,EACd,SAAiB,EACjB,SAAiB,EACjB,OAAe;QAEf,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE7C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,SAAS,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAC7E,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,KAAK,EAAE,CAAC;QACpE,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC;QAElC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAEpC,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;QAC5E,MAAM,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAEpC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,KAAK,EAAE,CAAC;QACvE,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC;QAEnC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAErC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACpF,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,SAAiB;QAC5D,MAAM,GAAG,GAAG,uCAAuC,MAAM,eAAe,SAAS,EAAE,CAAC;QACpF,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import type { Page } from 'playwright';
2
+ import type { FeedDetail } from '../types/xiaohongshu.types.js';
3
+ export declare class FeedDetailAction {
4
+ private page;
5
+ constructor(page: Page);
6
+ getFeedDetail(feedId: string, xsecToken: string, loadAllComments?: boolean): Promise<FeedDetail>;
7
+ private navigateToFeed;
8
+ private extractFeedDetail;
9
+ private extractUserId;
10
+ private extractImages;
11
+ private extractComments;
12
+ private extractCommentData;
13
+ private extractSubComments;
14
+ private loadAllComments;
15
+ private clickLoadMore;
16
+ }
17
+ //# sourceMappingURL=feed-detail.action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed-detail.action.d.ts","sourceRoot":"","sources":["../../src/actions/feed-detail.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,+BAA+B,CAAC;AAEzE,qBAAa,gBAAgB;IACf,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI;IAExB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,CAAC;YAe/F,cAAc;YAQd,iBAAiB;YA+BjB,aAAa;YAUb,aAAa;YAkBb,eAAe;YAuBf,kBAAkB;YAyBlB,kBAAkB;YAkBlB,eAAe;YAkBf,aAAa;CAe5B"}