xhs-mcp 0.6.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 (133) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +122 -0
  3. package/README.md +180 -0
  4. package/dist/cli/xhs-cli.d.ts +6 -0
  5. package/dist/cli/xhs-cli.d.ts.map +1 -0
  6. package/dist/cli/xhs-cli.js +300 -0
  7. package/dist/cli/xhs-cli.js.map +1 -0
  8. package/dist/index.d.ts +6 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +58 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/lib/auth/auth.service.d.ts +12 -0
  13. package/dist/lib/auth/auth.service.d.ts.map +1 -0
  14. package/dist/lib/auth/auth.service.js +138 -0
  15. package/dist/lib/auth/auth.service.js.map +1 -0
  16. package/dist/lib/auth/auth.types.d.ts +17 -0
  17. package/dist/lib/auth/auth.types.d.ts.map +1 -0
  18. package/dist/lib/auth/auth.types.js +5 -0
  19. package/dist/lib/auth/auth.types.js.map +1 -0
  20. package/dist/lib/auth/index.d.ts +6 -0
  21. package/dist/lib/auth/index.d.ts.map +1 -0
  22. package/dist/lib/auth/index.js +6 -0
  23. package/dist/lib/auth/index.js.map +1 -0
  24. package/dist/lib/browser/browser.manager.d.ts +22 -0
  25. package/dist/lib/browser/browser.manager.d.ts.map +1 -0
  26. package/dist/lib/browser/browser.manager.js +196 -0
  27. package/dist/lib/browser/browser.manager.js.map +1 -0
  28. package/dist/lib/browser/browser.types.d.ts +23 -0
  29. package/dist/lib/browser/browser.types.d.ts.map +1 -0
  30. package/dist/lib/browser/browser.types.js +5 -0
  31. package/dist/lib/browser/browser.types.js.map +1 -0
  32. package/dist/lib/browser/index.d.ts +6 -0
  33. package/dist/lib/browser/index.d.ts.map +1 -0
  34. package/dist/lib/browser/index.js +6 -0
  35. package/dist/lib/browser/index.js.map +1 -0
  36. package/dist/lib/feeds/feed.service.d.ts +13 -0
  37. package/dist/lib/feeds/feed.service.d.ts.map +1 -0
  38. package/dist/lib/feeds/feed.service.js +224 -0
  39. package/dist/lib/feeds/feed.service.js.map +1 -0
  40. package/dist/lib/feeds/feed.types.d.ts +26 -0
  41. package/dist/lib/feeds/feed.types.d.ts.map +1 -0
  42. package/dist/lib/feeds/feed.types.js +5 -0
  43. package/dist/lib/feeds/feed.types.js.map +1 -0
  44. package/dist/lib/feeds/index.d.ts +6 -0
  45. package/dist/lib/feeds/index.d.ts.map +1 -0
  46. package/dist/lib/feeds/index.js +6 -0
  47. package/dist/lib/feeds/index.js.map +1 -0
  48. package/dist/lib/index.d.ts +9 -0
  49. package/dist/lib/index.d.ts.map +1 -0
  50. package/dist/lib/index.js +11 -0
  51. package/dist/lib/index.js.map +1 -0
  52. package/dist/lib/publishing/index.d.ts +6 -0
  53. package/dist/lib/publishing/index.d.ts.map +1 -0
  54. package/dist/lib/publishing/index.js +6 -0
  55. package/dist/lib/publishing/index.js.map +1 -0
  56. package/dist/lib/publishing/publish.service.d.ts +39 -0
  57. package/dist/lib/publishing/publish.service.d.ts.map +1 -0
  58. package/dist/lib/publishing/publish.service.js +942 -0
  59. package/dist/lib/publishing/publish.service.js.map +1 -0
  60. package/dist/lib/publishing/publish.types.d.ts +37 -0
  61. package/dist/lib/publishing/publish.types.d.ts.map +1 -0
  62. package/dist/lib/publishing/publish.types.js +5 -0
  63. package/dist/lib/publishing/publish.types.js.map +1 -0
  64. package/dist/lib/shared/base.service.d.ts +22 -0
  65. package/dist/lib/shared/base.service.d.ts.map +1 -0
  66. package/dist/lib/shared/base.service.js +28 -0
  67. package/dist/lib/shared/base.service.js.map +1 -0
  68. package/dist/lib/shared/config.d.ts +17 -0
  69. package/dist/lib/shared/config.d.ts.map +1 -0
  70. package/dist/lib/shared/config.js +133 -0
  71. package/dist/lib/shared/config.js.map +1 -0
  72. package/dist/lib/shared/cookies.d.ts +10 -0
  73. package/dist/lib/shared/cookies.d.ts.map +1 -0
  74. package/dist/lib/shared/cookies.js +79 -0
  75. package/dist/lib/shared/cookies.js.map +1 -0
  76. package/dist/lib/shared/errors.d.ts +51 -0
  77. package/dist/lib/shared/errors.d.ts.map +1 -0
  78. package/dist/lib/shared/errors.js +93 -0
  79. package/dist/lib/shared/errors.js.map +1 -0
  80. package/dist/lib/shared/index.d.ts +11 -0
  81. package/dist/lib/shared/index.d.ts.map +1 -0
  82. package/dist/lib/shared/index.js +18 -0
  83. package/dist/lib/shared/index.js.map +1 -0
  84. package/dist/lib/shared/logger.d.ts +16 -0
  85. package/dist/lib/shared/logger.d.ts.map +1 -0
  86. package/dist/lib/shared/logger.js +41 -0
  87. package/dist/lib/shared/logger.js.map +1 -0
  88. package/dist/lib/shared/types.d.ts +175 -0
  89. package/dist/lib/shared/types.d.ts.map +1 -0
  90. package/dist/lib/shared/types.js +6 -0
  91. package/dist/lib/shared/types.js.map +1 -0
  92. package/dist/lib/shared/utils.d.ts +78 -0
  93. package/dist/lib/shared/utils.d.ts.map +1 -0
  94. package/dist/lib/shared/utils.js +137 -0
  95. package/dist/lib/shared/utils.js.map +1 -0
  96. package/dist/server/handlers/index.d.ts +6 -0
  97. package/dist/server/handlers/index.d.ts.map +1 -0
  98. package/dist/server/handlers/index.js +6 -0
  99. package/dist/server/handlers/index.js.map +1 -0
  100. package/dist/server/handlers/resource.handlers.d.ts +18 -0
  101. package/dist/server/handlers/resource.handlers.d.ts.map +1 -0
  102. package/dist/server/handlers/resource.handlers.js +113 -0
  103. package/dist/server/handlers/resource.handlers.js.map +1 -0
  104. package/dist/server/handlers/tool.handlers.d.ts +64 -0
  105. package/dist/server/handlers/tool.handlers.d.ts.map +1 -0
  106. package/dist/server/handlers/tool.handlers.js +123 -0
  107. package/dist/server/handlers/tool.handlers.js.map +1 -0
  108. package/dist/server/http.server.d.ts +21 -0
  109. package/dist/server/http.server.d.ts.map +1 -0
  110. package/dist/server/http.server.js +310 -0
  111. package/dist/server/http.server.js.map +1 -0
  112. package/dist/server/index.d.ts +7 -0
  113. package/dist/server/index.d.ts.map +1 -0
  114. package/dist/server/index.js +7 -0
  115. package/dist/server/index.js.map +1 -0
  116. package/dist/server/mcp.server.d.ts +15 -0
  117. package/dist/server/mcp.server.d.ts.map +1 -0
  118. package/dist/server/mcp.server.js +61 -0
  119. package/dist/server/mcp.server.js.map +1 -0
  120. package/dist/server/schemas/tool.schemas.d.ts +20 -0
  121. package/dist/server/schemas/tool.schemas.d.ts.map +1 -0
  122. package/dist/server/schemas/tool.schemas.js +178 -0
  123. package/dist/server/schemas/tool.schemas.js.map +1 -0
  124. package/dist/utils/index.d.ts +5 -0
  125. package/dist/utils/index.d.ts.map +1 -0
  126. package/dist/utils/index.js +5 -0
  127. package/dist/utils/index.js.map +1 -0
  128. package/dist/utils/xhs.utils.d.ts +14 -0
  129. package/dist/utils/xhs.utils.d.ts.map +1 -0
  130. package/dist/utils/xhs.utils.js +84 -0
  131. package/dist/utils/xhs.utils.js.map +1 -0
  132. package/docs/HTTP_TRANSPORTS.md +269 -0
  133. package/package.json +59 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.server.js","sourceRoot":"","sources":["../../src/server/mcp.server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEnF,MAAM,OAAO,YAAY;IACf,MAAM,CAAS;IACf,YAAY,CAAe;IAC3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CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;YAC/B,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,2EAA2E;IAC7E,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Tool schemas for XHS MCP Server
3
+ */
4
+ export interface ToolSchema {
5
+ name: string;
6
+ description: string;
7
+ inputSchema: {
8
+ type: 'object';
9
+ properties: Record<string, any>;
10
+ required?: string[];
11
+ };
12
+ }
13
+ export declare const XHS_TOOL_SCHEMAS: ToolSchema[];
14
+ export declare const XHS_RESOURCE_SCHEMAS: {
15
+ uri: string;
16
+ name: string;
17
+ description: string;
18
+ mimeType: string;
19
+ }[];
20
+ //# sourceMappingURL=tool.schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.schemas.d.ts","sourceRoot":"","sources":["../../../src/server/schemas/tool.schemas.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,eAAO,MAAM,gBAAgB,EAAE,UAAU,EAyJxC,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;GAmBhC,CAAC"}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Tool schemas for XHS MCP Server
3
+ */
4
+ export const XHS_TOOL_SCHEMAS = [
5
+ {
6
+ name: 'xhs_auth_login',
7
+ description: 'Start XiaoHongShu login process.',
8
+ inputSchema: {
9
+ type: 'object',
10
+ properties: {
11
+ browser_path: {
12
+ type: 'string',
13
+ description: 'Optional custom browser binary path',
14
+ },
15
+ },
16
+ },
17
+ },
18
+ {
19
+ name: 'xhs_auth_logout',
20
+ description: 'Logout from XiaoHongShu (clears saved cookies).',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {},
24
+ },
25
+ },
26
+ {
27
+ name: 'xhs_auth_status',
28
+ description: 'Check XiaoHongShu login status (fast check with browser).',
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ browser_path: {
33
+ type: 'string',
34
+ description: 'Optional custom browser binary path',
35
+ },
36
+ },
37
+ },
38
+ },
39
+ {
40
+ name: 'xhs_discover_feeds',
41
+ description: 'Get home page feed list.',
42
+ inputSchema: {
43
+ type: 'object',
44
+ properties: {
45
+ browser_path: {
46
+ type: 'string',
47
+ description: 'Optional custom browser binary path',
48
+ },
49
+ },
50
+ },
51
+ },
52
+ {
53
+ name: 'xhs_search_note',
54
+ description: 'Search for notes by keyword.',
55
+ inputSchema: {
56
+ type: 'object',
57
+ properties: {
58
+ keyword: {
59
+ type: 'string',
60
+ description: 'Search keyword (required)',
61
+ },
62
+ browser_path: {
63
+ type: 'string',
64
+ description: 'Optional custom browser binary path',
65
+ },
66
+ },
67
+ required: ['keyword'],
68
+ },
69
+ },
70
+ {
71
+ name: 'xhs_get_note_detail',
72
+ description: 'Get detailed information about a specific note.',
73
+ inputSchema: {
74
+ type: 'object',
75
+ properties: {
76
+ feed_id: {
77
+ type: 'string',
78
+ description: 'Feed ID (required)',
79
+ },
80
+ xsec_token: {
81
+ type: 'string',
82
+ description: 'Security token for the feed (required)',
83
+ },
84
+ browser_path: {
85
+ type: 'string',
86
+ description: 'Optional custom browser binary path',
87
+ },
88
+ },
89
+ required: ['feed_id', 'xsec_token'],
90
+ },
91
+ },
92
+ {
93
+ name: 'xhs_comment_on_note',
94
+ description: 'Comment on a note.',
95
+ inputSchema: {
96
+ type: 'object',
97
+ properties: {
98
+ feed_id: {
99
+ type: 'string',
100
+ description: 'Feed ID (required)',
101
+ },
102
+ xsec_token: {
103
+ type: 'string',
104
+ description: 'Security token for the feed (required)',
105
+ },
106
+ note: {
107
+ type: 'string',
108
+ description: 'Comment note (required)',
109
+ },
110
+ browser_path: {
111
+ type: 'string',
112
+ description: 'Optional custom browser binary path',
113
+ },
114
+ },
115
+ required: ['feed_id', 'xsec_token', 'note'],
116
+ },
117
+ },
118
+ {
119
+ name: 'xhs_publish_content',
120
+ description: 'Publish content to XiaoHongShu (supports both images and videos).',
121
+ inputSchema: {
122
+ type: 'object',
123
+ properties: {
124
+ type: {
125
+ type: 'string',
126
+ enum: ['image', 'video'],
127
+ description: 'Content type: "image" for images, "video" for videos (required)',
128
+ },
129
+ title: {
130
+ type: 'string',
131
+ description: 'Content title (required, max 20 characters)',
132
+ maxLength: 20,
133
+ },
134
+ content: {
135
+ type: 'string',
136
+ description: 'Content description (required, max 1000 characters)',
137
+ maxLength: 1000,
138
+ },
139
+ media_paths: {
140
+ type: 'array',
141
+ items: { type: 'string' },
142
+ description: 'List of media file paths (required, non-empty). For images: 1-18 image files. For videos: exactly 1 video file.',
143
+ maxItems: 18,
144
+ },
145
+ tags: {
146
+ type: 'string',
147
+ description: 'Comma-separated tags (optional)',
148
+ },
149
+ browser_path: {
150
+ type: 'string',
151
+ description: 'Optional custom browser binary path',
152
+ },
153
+ },
154
+ required: ['type', 'title', 'content', 'media_paths'],
155
+ },
156
+ },
157
+ ];
158
+ export const XHS_RESOURCE_SCHEMAS = [
159
+ {
160
+ uri: 'xhs://cookies',
161
+ name: 'XHS Authentication Cookies',
162
+ description: 'Current XiaoHongShu authentication cookies and info',
163
+ mimeType: 'application/json',
164
+ },
165
+ {
166
+ uri: 'xhs://config',
167
+ name: 'XHS Server Configuration',
168
+ description: 'XHS MCP server configuration',
169
+ mimeType: 'application/json',
170
+ },
171
+ {
172
+ uri: 'xhs://status',
173
+ name: 'XHS Server Status',
174
+ description: 'Current server and authentication status',
175
+ mimeType: 'application/json',
176
+ },
177
+ ];
178
+ //# sourceMappingURL=tool.schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.schemas.js","sourceRoot":"","sources":["../../../src/server/schemas/tool.schemas.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,MAAM,CAAC,MAAM,gBAAgB,GAAiB;IAC5C;QACE,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,kCAAkC;QAC/C,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qCAAqC;iBACnD;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,iDAAiD;QAC9D,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;SACf;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,2DAA2D;QACxE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qCAAqC;iBACnD;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qCAAqC;iBACnD;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,8BAA8B;QAC3C,WAAW,EAAE;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ions for XHS MCP Server
3
+ */
4
+ export * from './xhs.utils.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utility functions for XHS MCP Server
3
+ */
4
+ export * from './xhs.utils.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Utility functions for XHS operations
3
+ */
4
+ import { Page } from 'puppeteer';
5
+ export declare const XHS_HOME_URL = "https://www.xiaohongshu.com";
6
+ export declare const XHS_EXPLORE_URL = "https://www.xiaohongshu.com/explore";
7
+ export declare const XHS_SEARCH_URL = "https://www.xiaohongshu.com/search_result";
8
+ export declare const XHS_CREATOR_PUBLISH_URL = "https://creator.xiaohongshu.com/publish/publish?source=official";
9
+ export declare const LOGIN_OK_SELECTOR = ".main-container .user .link-wrapper .channel";
10
+ export declare function makeSearchUrl(keyword: string): string;
11
+ export declare function makeFeedDetailUrl(feedId: string, xsecToken: string): string;
12
+ export declare function extractInitialState(page: Page): Promise<Record<string, unknown> | null>;
13
+ export declare function isLoggedIn(page: Page): Promise<boolean>;
14
+ //# sourceMappingURL=xhs.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhs.utils.d.ts","sourceRoot":"","sources":["../../src/utils/xhs.utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,eAAO,MAAM,YAAY,gCAAgC,CAAC;AAC1D,eAAO,MAAM,eAAe,wCAA4B,CAAC;AACzD,eAAO,MAAM,cAAc,8CAAkC,CAAC;AAC9D,eAAO,MAAM,uBAAuB,oEAAoE,CAAC;AACzG,eAAO,MAAM,iBAAiB,iDAAiD,CAAC;AAEhF,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAoD7F;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAO7D"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Utility functions for XHS operations
3
+ */
4
+ export const XHS_HOME_URL = 'https://www.xiaohongshu.com';
5
+ export const XHS_EXPLORE_URL = `${XHS_HOME_URL}/explore`;
6
+ export const XHS_SEARCH_URL = `${XHS_HOME_URL}/search_result`;
7
+ export const XHS_CREATOR_PUBLISH_URL = 'https://creator.xiaohongshu.com/publish/publish?source=official';
8
+ export const LOGIN_OK_SELECTOR = '.main-container .user .link-wrapper .channel';
9
+ export function makeSearchUrl(keyword) {
10
+ const params = new URLSearchParams({
11
+ keyword,
12
+ source: 'web_explore_feed',
13
+ });
14
+ return `${XHS_SEARCH_URL}?${params.toString()}`;
15
+ }
16
+ export function makeFeedDetailUrl(feedId, xsecToken) {
17
+ const params = new URLSearchParams({
18
+ xsec_token: xsecToken,
19
+ xsec_source: 'pc_feed',
20
+ });
21
+ return `${XHS_EXPLORE_URL}/${feedId}?${params.toString()}`;
22
+ }
23
+ export async function extractInitialState(page) {
24
+ try {
25
+ // Wait for page to be fully loaded - Puppeteer doesn't have waitForLoadState
26
+ // We'll just wait a bit for the page to settle
27
+ await new Promise(resolve => setTimeout(resolve, 1000));
28
+ }
29
+ catch {
30
+ // Ignore load state errors
31
+ }
32
+ try {
33
+ const result = await page.evaluate(`
34
+ (() => {
35
+ // Try multiple possible state objects
36
+ const possibleStates = [
37
+ window.__INITIAL_STATE__,
38
+ window.__INITIAL_SSR_STATE__,
39
+ window.__NEXT_DATA__,
40
+ window.__NUXT__,
41
+ window.__VUE__,
42
+ window.__REACT_QUERY_STATE__
43
+ ];
44
+
45
+ for (const state of possibleStates) {
46
+ if (state && typeof state === 'object') {
47
+ return JSON.stringify(state);
48
+ }
49
+ }
50
+
51
+ // If no state found, try to find any global state
52
+ const globalKeys = Object.keys(window).filter(key =>
53
+ key.includes('STATE') || key.includes('DATA') || key.includes('INITIAL')
54
+ );
55
+
56
+ for (const key of globalKeys) {
57
+ const value = window[key];
58
+ if (value && typeof value === 'object') {
59
+ return JSON.stringify(value);
60
+ }
61
+ }
62
+
63
+ return '';
64
+ })()
65
+ `);
66
+ if (!result) {
67
+ return null;
68
+ }
69
+ return JSON.parse(result);
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ }
75
+ export async function isLoggedIn(page) {
76
+ try {
77
+ const elements = await page.$$(LOGIN_OK_SELECTOR);
78
+ return elements.length > 0;
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ //# sourceMappingURL=xhs.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhs.utils.js","sourceRoot":"","sources":["../../src/utils/xhs.utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,CAAC,MAAM,YAAY,GAAG,6BAA6B,CAAC;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,YAAY,UAAU,CAAC;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,YAAY,gBAAgB,CAAC;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,iEAAiE,CAAC;AACzG,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AAEhF,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,MAAM,GAAG,IAAI,eAAe,C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,CAAC"}
@@ -0,0 +1,269 @@
1
+ ---
2
+ noteId: "aa57c8c098f311f0a8e11dcb3e2fc94e"
3
+ tags: []
4
+ ---
5
+ # HTTP Transports Support
6
+
7
+ XHS MCP Server now supports both SSE (Server-Sent Events) and Streamable HTTP transports, in addition to the traditional stdio transport.
8
+
9
+ ## Transport Options
10
+
11
+ ### 1. Streamable HTTP (Recommended)
12
+
13
+ - **Protocol Version**: 2025-03-26
14
+ - **Endpoint**: `/mcp`
15
+ - **Methods**: GET, POST, DELETE
16
+ - **Features**:
17
+ - Unified endpoint for all operations
18
+ - Session management with resumability
19
+ - On-demand streaming
20
+ - Stateless server support
21
+
22
+ ### 2. HTTP + SSE (Legacy)
23
+
24
+ - **Protocol Version**: 2024-11-05
25
+ - **Endpoints**:
26
+ - `/sse` (GET) - Establish SSE stream
27
+ - `/messages` (POST) - Send messages
28
+ - **Features**:
29
+ - Traditional SSE implementation
30
+ - Backward compatibility
31
+
32
+ ### 3. Stdio (Default)
33
+
34
+ - **Protocol**: Standard MCP stdio transport
35
+ - **Usage**: Direct process communication
36
+ - **Features**:
37
+ - Zero configuration
38
+ - Process-based communication
39
+
40
+ ## Usage
41
+
42
+ ### Starting the HTTP Server
43
+
44
+ ```bash
45
+ # Start HTTP server on default port 3000
46
+ npm run start:http
47
+
48
+ # Start HTTP server on custom port
49
+ npm run start:http -- --port 8080
50
+
51
+ # Development mode with HTTP server
52
+ npm run dev:http
53
+
54
+ # Development mode with custom port
55
+ npm run dev:http -- --port 8080
56
+ ```
57
+
58
+ ### Command Line Options
59
+
60
+ ```bash
61
+ # Show help
62
+ node dist/index.js --help
63
+
64
+ # Start in stdio mode (default)
65
+ node dist/index.js --mode stdio
66
+
67
+ # Start in HTTP mode
68
+ node dist/index.js --mode http --port 3000
69
+ ```
70
+
71
+ ## API Endpoints
72
+
73
+ ### Health Check
74
+
75
+ ```
76
+ GET /health
77
+ ```
78
+
79
+ Returns server status and supported transports.
80
+
81
+ **Response:**
82
+
83
+ ```json
84
+ {
85
+ "status": "healthy",
86
+ "server": "xhs-mcp",
87
+ "version": "0.2.10",
88
+ "transports": ["streamable-http", "sse"]
89
+ }
90
+ ```
91
+
92
+ ### Streamable HTTP Transport
93
+
94
+ #### Initialize Session
95
+
96
+ ```
97
+ POST /mcp
98
+ Content-Type: application/json
99
+
100
+ {
101
+ "jsonrpc": "2.0",
102
+ "id": 1,
103
+ "method": "initialize",
104
+ "params": {
105
+ "protocolVersion": "2025-03-26",
106
+ "capabilities": {},
107
+ "clientInfo": {
108
+ "name": "client-name",
109
+ "version": "1.0.0"
110
+ }
111
+ }
112
+ }
113
+ ```
114
+
115
+ **Response Headers:**
116
+
117
+ ```
118
+ Mcp-Session-Id: <session-id>
119
+ ```
120
+
121
+ #### Send Requests
122
+
123
+ ```
124
+ POST /mcp
125
+ Content-Type: application/json
126
+ Mcp-Session-Id: <session-id>
127
+
128
+ {
129
+ "jsonrpc": "2.0",
130
+ "id": 2,
131
+ "method": "tools/list"
132
+ }
133
+ ```
134
+
135
+ #### Establish SSE Stream
136
+
137
+ ```
138
+ GET /mcp
139
+ Mcp-Session-Id: <session-id>
140
+ ```
141
+
142
+ #### Terminate Session
143
+
144
+ ```
145
+ DELETE /mcp
146
+ Mcp-Session-Id: <session-id>
147
+ ```
148
+
149
+ ### SSE Transport (Legacy)
150
+
151
+ #### Establish SSE Stream
152
+
153
+ ```
154
+ GET /sse
155
+ ```
156
+
157
+ #### Send Messages
158
+
159
+ ```
160
+ POST /messages?sessionId=<session-id>
161
+ Content-Type: application/json
162
+
163
+ {
164
+ "jsonrpc": "2.0",
165
+ "id": 1,
166
+ "method": "initialize",
167
+ "params": {
168
+ "protocolVersion": "2024-11-05",
169
+ "capabilities": {},
170
+ "clientInfo": {
171
+ "name": "client-name",
172
+ "version": "1.0.0"
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ ## Testing
179
+
180
+ A test script is provided to verify the HTTP server functionality:
181
+
182
+ ```bash
183
+ # Start the HTTP server in one terminal
184
+ npm run dev:http
185
+
186
+ # Run tests in another terminal
187
+ node test-http-server.js
188
+ ```
189
+
190
+ ## Configuration
191
+
192
+ ### Environment Variables
193
+
194
+ - `XHS_ENABLE_LOGGING=true` - Enable detailed logging
195
+ - `PORT` - HTTP server port (default: 3000)
196
+
197
+ ### CORS Configuration
198
+
199
+ The HTTP server is configured with permissive CORS settings for development:
200
+
201
+ ```javascript
202
+ app.use(cors({
203
+ origin: '*', // Allow all origins
204
+ exposedHeaders: ['Mcp-Session-Id']
205
+ }));
206
+ ```
207
+
208
+ For production, you should restrict the `origin` to specific domains.
209
+
210
+ ## Security Considerations
211
+
212
+ ### DNS Rebinding Protection
213
+
214
+ Both SSE and Streamable HTTP transports support DNS rebinding protection:
215
+
216
+ ```javascript
217
+ const transport = new SSEServerTransport('/messages', res, {
218
+ allowedHosts: ['localhost', '127.0.0.1'],
219
+ allowedOrigins: ['http://localhost:3000'],
220
+ enableDnsRebindingProtection: true
221
+ });
222
+ ```
223
+
224
+ ### Session Management
225
+
226
+ - Session IDs are generated using cryptographically secure UUIDs
227
+ - Sessions are automatically cleaned up when connections close
228
+ - Invalid session IDs are rejected with appropriate error responses
229
+
230
+ ## Migration Guide
231
+
232
+ ### From Stdio to HTTP
233
+
234
+ 1. **Update client configuration** to use HTTP endpoints instead of stdio
235
+ 2. **Handle session management** for stateful operations
236
+ 3. **Implement proper error handling** for HTTP-specific errors
237
+ 4. **Consider CORS requirements** for browser-based clients
238
+
239
+ ### From SSE to Streamable HTTP
240
+
241
+ 1. **Update protocol version** from `2024-11-05` to `2025-03-26`
242
+ 2. **Use unified `/mcp` endpoint** instead of separate `/sse` and `/messages`
243
+ 3. **Implement session ID handling** in request headers
244
+ 4. **Update client to handle** both streaming and direct responses
245
+
246
+ ## Troubleshooting
247
+
248
+ ### Common Issues
249
+
250
+ 1. **Port already in use**: Change the port using `--port` option
251
+ 2. **CORS errors**: Configure allowed origins in production
252
+ 3. **Session not found**: Ensure session ID is properly included in headers
253
+ 4. **Connection timeouts**: Check network configuration and firewall
254
+
255
+ ### Debug Mode
256
+
257
+ Enable detailed logging:
258
+
259
+ ```bash
260
+ XHS_ENABLE_LOGGING=true npm run dev:http
261
+ ```
262
+
263
+ ### Health Check
264
+
265
+ Always verify server status:
266
+
267
+ ```bash
268
+ curl http://localhost:3000/health
269
+ ```
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "xhs-mcp",
3
+ "version": "0.6.0",
4
+ "description": "XiaoHongShu CLI and MCP Server",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "xhs-cli": "dist/cli/xhs-cli.js"
9
+ },
10
+ "type": "module",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "docs"
15
+ ],
16
+ "scripts": {
17
+ "build": "npm run clean && tsc",
18
+ "start:cli": "node dist/cli/xhs-cli.js --help",
19
+ "dev:cli": "tsx src/cli/xhs-cli.ts --help",
20
+ "dev:mcp:stdio": "tsx src/cli/xhs-cli.ts mcp --mode stdio",
21
+ "dev:mcp:http": "tsx src/cli/xhs-cli.ts mcp --mode http",
22
+ "clean": "rm -rf dist temp_images/*",
23
+ "lint": "eslint src/**/*.ts",
24
+ "lint:fix": "eslint src/**/*.ts --fix",
25
+ "format": "prettier --write src/**/*.ts",
26
+ "format:check": "prettier --check src/**/*.ts"
27
+ },
28
+ "keywords": [
29
+ "xiaohongshu",
30
+ "mcp",
31
+ "model-context-protocol",
32
+ "automation",
33
+ "puppeteer"
34
+ ],
35
+ "author": "",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@modelcontextprotocol/sdk": "^1.0.0",
39
+ "@types/cors": "^2.8.19",
40
+ "@types/express": "^5.0.3",
41
+ "commander": "^12.0.0",
42
+ "cors": "^2.8.5",
43
+ "express": "^5.1.0",
44
+ "node-fetch": "^3.3.2",
45
+ "puppeteer": "^22.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^22.0.0",
49
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
50
+ "@typescript-eslint/parser": "^8.0.0",
51
+ "eslint": "^9.0.0",
52
+ "prettier": "^3.0.0",
53
+ "tsx": "^4.0.0",
54
+ "typescript": "^5.0.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=18.0.0"
58
+ }
59
+ }