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.
- package/LICENSE +21 -0
- package/README.en.md +122 -0
- package/README.md +180 -0
- package/dist/cli/xhs-cli.d.ts +6 -0
- package/dist/cli/xhs-cli.d.ts.map +1 -0
- package/dist/cli/xhs-cli.js +300 -0
- package/dist/cli/xhs-cli.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/auth/auth.service.d.ts +12 -0
- package/dist/lib/auth/auth.service.d.ts.map +1 -0
- package/dist/lib/auth/auth.service.js +138 -0
- package/dist/lib/auth/auth.service.js.map +1 -0
- package/dist/lib/auth/auth.types.d.ts +17 -0
- package/dist/lib/auth/auth.types.d.ts.map +1 -0
- package/dist/lib/auth/auth.types.js +5 -0
- package/dist/lib/auth/auth.types.js.map +1 -0
- package/dist/lib/auth/index.d.ts +6 -0
- package/dist/lib/auth/index.d.ts.map +1 -0
- package/dist/lib/auth/index.js +6 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/browser/browser.manager.d.ts +22 -0
- package/dist/lib/browser/browser.manager.d.ts.map +1 -0
- package/dist/lib/browser/browser.manager.js +196 -0
- package/dist/lib/browser/browser.manager.js.map +1 -0
- package/dist/lib/browser/browser.types.d.ts +23 -0
- package/dist/lib/browser/browser.types.d.ts.map +1 -0
- package/dist/lib/browser/browser.types.js +5 -0
- package/dist/lib/browser/browser.types.js.map +1 -0
- package/dist/lib/browser/index.d.ts +6 -0
- package/dist/lib/browser/index.d.ts.map +1 -0
- package/dist/lib/browser/index.js +6 -0
- package/dist/lib/browser/index.js.map +1 -0
- package/dist/lib/feeds/feed.service.d.ts +13 -0
- package/dist/lib/feeds/feed.service.d.ts.map +1 -0
- package/dist/lib/feeds/feed.service.js +224 -0
- package/dist/lib/feeds/feed.service.js.map +1 -0
- package/dist/lib/feeds/feed.types.d.ts +26 -0
- package/dist/lib/feeds/feed.types.d.ts.map +1 -0
- package/dist/lib/feeds/feed.types.js +5 -0
- package/dist/lib/feeds/feed.types.js.map +1 -0
- package/dist/lib/feeds/index.d.ts +6 -0
- package/dist/lib/feeds/index.d.ts.map +1 -0
- package/dist/lib/feeds/index.js +6 -0
- package/dist/lib/feeds/index.js.map +1 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/publishing/index.d.ts +6 -0
- package/dist/lib/publishing/index.d.ts.map +1 -0
- package/dist/lib/publishing/index.js +6 -0
- package/dist/lib/publishing/index.js.map +1 -0
- package/dist/lib/publishing/publish.service.d.ts +39 -0
- package/dist/lib/publishing/publish.service.d.ts.map +1 -0
- package/dist/lib/publishing/publish.service.js +942 -0
- package/dist/lib/publishing/publish.service.js.map +1 -0
- package/dist/lib/publishing/publish.types.d.ts +37 -0
- package/dist/lib/publishing/publish.types.d.ts.map +1 -0
- package/dist/lib/publishing/publish.types.js +5 -0
- package/dist/lib/publishing/publish.types.js.map +1 -0
- package/dist/lib/shared/base.service.d.ts +22 -0
- package/dist/lib/shared/base.service.d.ts.map +1 -0
- package/dist/lib/shared/base.service.js +28 -0
- package/dist/lib/shared/base.service.js.map +1 -0
- package/dist/lib/shared/config.d.ts +17 -0
- package/dist/lib/shared/config.d.ts.map +1 -0
- package/dist/lib/shared/config.js +133 -0
- package/dist/lib/shared/config.js.map +1 -0
- package/dist/lib/shared/cookies.d.ts +10 -0
- package/dist/lib/shared/cookies.d.ts.map +1 -0
- package/dist/lib/shared/cookies.js +79 -0
- package/dist/lib/shared/cookies.js.map +1 -0
- package/dist/lib/shared/errors.d.ts +51 -0
- package/dist/lib/shared/errors.d.ts.map +1 -0
- package/dist/lib/shared/errors.js +93 -0
- package/dist/lib/shared/errors.js.map +1 -0
- package/dist/lib/shared/index.d.ts +11 -0
- package/dist/lib/shared/index.d.ts.map +1 -0
- package/dist/lib/shared/index.js +18 -0
- package/dist/lib/shared/index.js.map +1 -0
- package/dist/lib/shared/logger.d.ts +16 -0
- package/dist/lib/shared/logger.d.ts.map +1 -0
- package/dist/lib/shared/logger.js +41 -0
- package/dist/lib/shared/logger.js.map +1 -0
- package/dist/lib/shared/types.d.ts +175 -0
- package/dist/lib/shared/types.d.ts.map +1 -0
- package/dist/lib/shared/types.js +6 -0
- package/dist/lib/shared/types.js.map +1 -0
- package/dist/lib/shared/utils.d.ts +78 -0
- package/dist/lib/shared/utils.d.ts.map +1 -0
- package/dist/lib/shared/utils.js +137 -0
- package/dist/lib/shared/utils.js.map +1 -0
- package/dist/server/handlers/index.d.ts +6 -0
- package/dist/server/handlers/index.d.ts.map +1 -0
- package/dist/server/handlers/index.js +6 -0
- package/dist/server/handlers/index.js.map +1 -0
- package/dist/server/handlers/resource.handlers.d.ts +18 -0
- package/dist/server/handlers/resource.handlers.d.ts.map +1 -0
- package/dist/server/handlers/resource.handlers.js +113 -0
- package/dist/server/handlers/resource.handlers.js.map +1 -0
- package/dist/server/handlers/tool.handlers.d.ts +64 -0
- package/dist/server/handlers/tool.handlers.d.ts.map +1 -0
- package/dist/server/handlers/tool.handlers.js +123 -0
- package/dist/server/handlers/tool.handlers.js.map +1 -0
- package/dist/server/http.server.d.ts +21 -0
- package/dist/server/http.server.d.ts.map +1 -0
- package/dist/server/http.server.js +310 -0
- package/dist/server/http.server.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +7 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/mcp.server.d.ts +15 -0
- package/dist/server/mcp.server.d.ts.map +1 -0
- package/dist/server/mcp.server.js +61 -0
- package/dist/server/mcp.server.js.map +1 -0
- package/dist/server/schemas/tool.schemas.d.ts +20 -0
- package/dist/server/schemas/tool.schemas.d.ts.map +1 -0
- package/dist/server/schemas/tool.schemas.js +178 -0
- package/dist/server/schemas/tool.schemas.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/xhs.utils.d.ts +14 -0
- package/dist/utils/xhs.utils.d.ts.map +1 -0
- package/dist/utils/xhs.utils.js +84 -0
- package/dist/utils/xhs.utils.js.map +1 -0
- package/docs/HTTP_TRANSPORTS.md +269 -0
- package/package.json +59 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger for XHS MCP Server
|
|
3
|
+
* Avoids logging to stderr in stdio mode to prevent interference with MCP protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class Logger {
|
|
6
|
+
private static instance;
|
|
7
|
+
private enabled;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): Logger;
|
|
10
|
+
debug(message: string, ...args: any[]): void;
|
|
11
|
+
info(message: string, ...args: any[]): void;
|
|
12
|
+
warn(message: string, ...args: any[]): void;
|
|
13
|
+
error(message: string, ...args: any[]): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const logger: Logger;
|
|
16
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,OAAO,CAAkB;IAEjC,OAAO;WAMO,WAAW,IAAI,MAAM;IAO5B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAKpD;AAED,eAAO,MAAM,MAAM,QAAuB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger for XHS MCP Server
|
|
3
|
+
* Avoids logging to stderr in stdio mode to prevent interference with MCP protocol
|
|
4
|
+
*/
|
|
5
|
+
export class Logger {
|
|
6
|
+
static instance;
|
|
7
|
+
enabled = false;
|
|
8
|
+
constructor() {
|
|
9
|
+
// Only enable logging if not in stdio mode
|
|
10
|
+
// In stdio mode, we suppress all logging to avoid interfering with MCP protocol
|
|
11
|
+
this.enabled = process.env.XHS_ENABLE_LOGGING === 'true';
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (!Logger.instance) {
|
|
15
|
+
Logger.instance = new Logger();
|
|
16
|
+
}
|
|
17
|
+
return Logger.instance;
|
|
18
|
+
}
|
|
19
|
+
debug(message, ...args) {
|
|
20
|
+
if (this.enabled) {
|
|
21
|
+
console.error(`[DEBUG] ${message}`, ...args);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
info(message, ...args) {
|
|
25
|
+
if (this.enabled) {
|
|
26
|
+
console.error(`[INFO] ${message}`, ...args);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
warn(message, ...args) {
|
|
30
|
+
if (this.enabled) {
|
|
31
|
+
console.error(`[WARN] ${message}`, ...args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
error(message, ...args) {
|
|
35
|
+
if (this.enabled) {
|
|
36
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const logger = Logger.getInstance();
|
|
41
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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ACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for XHS MCP Server
|
|
3
|
+
*/
|
|
4
|
+
export interface XHSResponse<T = any> {
|
|
5
|
+
success: boolean;
|
|
6
|
+
data?: T;
|
|
7
|
+
message?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
operation?: string;
|
|
10
|
+
context?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface BrowserConfig {
|
|
13
|
+
defaultTimeout: number;
|
|
14
|
+
loginTimeout: number;
|
|
15
|
+
pageLoadTimeout: number;
|
|
16
|
+
navigationTimeout: number;
|
|
17
|
+
slowmo: number;
|
|
18
|
+
headlessDefault: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ServerConfig {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
description: string;
|
|
24
|
+
defaultHost: string;
|
|
25
|
+
defaultPort: number;
|
|
26
|
+
defaultTransport: 'stdio' | 'sse' | 'streamable-http';
|
|
27
|
+
}
|
|
28
|
+
export interface LoggingConfig {
|
|
29
|
+
level: string;
|
|
30
|
+
format: string;
|
|
31
|
+
fileEnabled: boolean;
|
|
32
|
+
filePath?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface PathsConfig {
|
|
35
|
+
appDataDir: string;
|
|
36
|
+
cookiesFile: string;
|
|
37
|
+
}
|
|
38
|
+
export interface XHSConfig {
|
|
39
|
+
homeUrl: string;
|
|
40
|
+
exploreUrl: string;
|
|
41
|
+
searchUrl: string;
|
|
42
|
+
creatorPublishUrl: string;
|
|
43
|
+
creatorVideoPublishUrl: string;
|
|
44
|
+
loginOkSelector: string;
|
|
45
|
+
requestDelay: number;
|
|
46
|
+
maxRetries: number;
|
|
47
|
+
retryDelay: number;
|
|
48
|
+
}
|
|
49
|
+
export interface Config {
|
|
50
|
+
browser: BrowserConfig;
|
|
51
|
+
server: ServerConfig;
|
|
52
|
+
logging: LoggingConfig;
|
|
53
|
+
paths: PathsConfig;
|
|
54
|
+
xhs: XHSConfig;
|
|
55
|
+
}
|
|
56
|
+
export interface Cookie {
|
|
57
|
+
name: string;
|
|
58
|
+
value: string;
|
|
59
|
+
domain: string;
|
|
60
|
+
path: string;
|
|
61
|
+
expires?: number;
|
|
62
|
+
httpOnly?: boolean;
|
|
63
|
+
secure?: boolean;
|
|
64
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
65
|
+
}
|
|
66
|
+
export interface CookiesInfo {
|
|
67
|
+
filePath: string;
|
|
68
|
+
fileExists: boolean;
|
|
69
|
+
cookieCount: number;
|
|
70
|
+
lastModified?: number;
|
|
71
|
+
}
|
|
72
|
+
export interface LoginResult {
|
|
73
|
+
success: boolean;
|
|
74
|
+
message: string;
|
|
75
|
+
status: 'logged_in' | 'logged_out';
|
|
76
|
+
action: 'none' | 'logged_in' | 'logged_out' | 'failed';
|
|
77
|
+
}
|
|
78
|
+
export interface StatusResult {
|
|
79
|
+
success: boolean;
|
|
80
|
+
loggedIn?: boolean;
|
|
81
|
+
status: 'logged_in' | 'logged_out' | 'unknown';
|
|
82
|
+
method?: string;
|
|
83
|
+
cookiesAvailable?: boolean;
|
|
84
|
+
cookieCount?: number;
|
|
85
|
+
cookiesFile?: string;
|
|
86
|
+
likelyLoggedIn?: boolean;
|
|
87
|
+
urlChecked?: string;
|
|
88
|
+
error?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface FeedItem {
|
|
91
|
+
id: string;
|
|
92
|
+
type: string;
|
|
93
|
+
title: string;
|
|
94
|
+
desc: string;
|
|
95
|
+
images: string[];
|
|
96
|
+
user: {
|
|
97
|
+
id: string;
|
|
98
|
+
nickname: string;
|
|
99
|
+
avatar: string;
|
|
100
|
+
};
|
|
101
|
+
interact_info: {
|
|
102
|
+
liked: boolean;
|
|
103
|
+
liked_count: string;
|
|
104
|
+
collected: boolean;
|
|
105
|
+
collected_count: string;
|
|
106
|
+
comment_count: string;
|
|
107
|
+
share_count: string;
|
|
108
|
+
};
|
|
109
|
+
time: number;
|
|
110
|
+
last_update_time: number;
|
|
111
|
+
}
|
|
112
|
+
export interface FeedListResult {
|
|
113
|
+
success: boolean;
|
|
114
|
+
feeds: FeedItem[];
|
|
115
|
+
count: number;
|
|
116
|
+
source: string;
|
|
117
|
+
url: string;
|
|
118
|
+
}
|
|
119
|
+
export interface SearchResult {
|
|
120
|
+
success: boolean;
|
|
121
|
+
keyword: string;
|
|
122
|
+
feeds: FeedItem[];
|
|
123
|
+
count: number;
|
|
124
|
+
searchUrl: string;
|
|
125
|
+
}
|
|
126
|
+
export interface FeedDetailResult {
|
|
127
|
+
success: boolean;
|
|
128
|
+
feedId: string;
|
|
129
|
+
detail: any;
|
|
130
|
+
url: string;
|
|
131
|
+
}
|
|
132
|
+
export interface CommentResult {
|
|
133
|
+
success: boolean;
|
|
134
|
+
message: string;
|
|
135
|
+
feedId: string;
|
|
136
|
+
note: string;
|
|
137
|
+
url: string;
|
|
138
|
+
}
|
|
139
|
+
export interface PublishResult {
|
|
140
|
+
success: boolean;
|
|
141
|
+
message: string;
|
|
142
|
+
title: string;
|
|
143
|
+
content: string;
|
|
144
|
+
imageCount: number;
|
|
145
|
+
tags: string;
|
|
146
|
+
url: string;
|
|
147
|
+
}
|
|
148
|
+
export interface ServerStatus {
|
|
149
|
+
server: {
|
|
150
|
+
status: string;
|
|
151
|
+
name: string;
|
|
152
|
+
version: string;
|
|
153
|
+
framework: string;
|
|
154
|
+
};
|
|
155
|
+
authentication: StatusResult;
|
|
156
|
+
cookies: {
|
|
157
|
+
fileExists: boolean;
|
|
158
|
+
cookieCount: number;
|
|
159
|
+
};
|
|
160
|
+
capabilities: {
|
|
161
|
+
toolsAvailable: number;
|
|
162
|
+
promptsAvailable: number;
|
|
163
|
+
resourcesAvailable: number;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export interface XHSErrorContext {
|
|
167
|
+
operation?: string;
|
|
168
|
+
url?: string;
|
|
169
|
+
feedId?: string;
|
|
170
|
+
keyword?: string;
|
|
171
|
+
timeout?: number;
|
|
172
|
+
attempts?: number;
|
|
173
|
+
[key: string]: any;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,OAAO,GAAG,KAAK,GAAG,iBAAiB,CAAC;CACvD;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAA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AChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/shared/types.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAgMH,qCAAqC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common utility functions for XHS MCP Server
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sleep utility function
|
|
6
|
+
* @param ms - Milliseconds to sleep
|
|
7
|
+
* @returns Promise that resolves after the specified time
|
|
8
|
+
*/
|
|
9
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Safe error handler that logs errors without throwing
|
|
12
|
+
* @param error - Error to handle
|
|
13
|
+
* @param context - Additional context for the error
|
|
14
|
+
* @param logger - Logger instance to use
|
|
15
|
+
*/
|
|
16
|
+
export declare function safeErrorHandler(error: unknown, context: string, logger: {
|
|
17
|
+
error: (message: string, ...args: any[]) => void;
|
|
18
|
+
}): void;
|
|
19
|
+
/**
|
|
20
|
+
* Validate required parameters
|
|
21
|
+
* @param params - Object containing parameters to validate
|
|
22
|
+
* @param requiredKeys - Array of required parameter keys
|
|
23
|
+
* @throws Error if any required parameter is missing
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateRequiredParams(params: Record<string, any>, requiredKeys: string[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Validate publish note parameters with length constraints
|
|
28
|
+
* @param title - Note title
|
|
29
|
+
* @param note - Note content
|
|
30
|
+
* @param imagePaths - Array of image paths
|
|
31
|
+
* @throws Error if any parameter violates constraints
|
|
32
|
+
*/
|
|
33
|
+
export declare function validatePublishNoteParams(title: string, note: string, imagePaths: string[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Create a standardized response object
|
|
36
|
+
* @param success - Whether the operation was successful
|
|
37
|
+
* @param data - Optional data to include
|
|
38
|
+
* @param message - Optional message
|
|
39
|
+
* @param error - Optional error information
|
|
40
|
+
* @returns Standardized response object
|
|
41
|
+
*/
|
|
42
|
+
export declare function createResponse<T = any>(success: boolean, data?: T, message?: string, error?: string): {
|
|
43
|
+
success: boolean;
|
|
44
|
+
data?: T;
|
|
45
|
+
message?: string;
|
|
46
|
+
error?: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Retry a function with exponential backoff
|
|
50
|
+
* @param fn - Function to retry
|
|
51
|
+
* @param maxRetries - Maximum number of retries
|
|
52
|
+
* @param baseDelay - Base delay in milliseconds
|
|
53
|
+
* @returns Promise that resolves with the function result
|
|
54
|
+
*/
|
|
55
|
+
export declare function retryWithBackoff<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Create a standardized MCP tool response
|
|
58
|
+
* @param data - Data to include in the response
|
|
59
|
+
* @returns Standardized MCP response format
|
|
60
|
+
*/
|
|
61
|
+
export declare function createToolResponse<T = any>(data: T): {
|
|
62
|
+
content: Array<{
|
|
63
|
+
type: string;
|
|
64
|
+
text: string;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Create a standardized MCP error response
|
|
69
|
+
* @param error - Error to format
|
|
70
|
+
* @returns Standardized MCP error response format
|
|
71
|
+
*/
|
|
72
|
+
export declare function createErrorResponse(error: unknown): {
|
|
73
|
+
content: Array<{
|
|
74
|
+
type: string;
|
|
75
|
+
text: string;
|
|
76
|
+
}>;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/utils.ts"],"names":[],"mappings":"AAAA;;GAE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;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CASvG;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAoBtG"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common utility functions for XHS MCP Server
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sleep utility function
|
|
6
|
+
* @param ms - Milliseconds to sleep
|
|
7
|
+
* @returns Promise that resolves after the specified time
|
|
8
|
+
*/
|
|
9
|
+
export function sleep(ms) {
|
|
10
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Safe error handler that logs errors without throwing
|
|
14
|
+
* @param error - Error to handle
|
|
15
|
+
* @param context - Additional context for the error
|
|
16
|
+
* @param logger - Logger instance to use
|
|
17
|
+
*/
|
|
18
|
+
export function safeErrorHandler(error, context, logger) {
|
|
19
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
20
|
+
logger.error(`${context}: ${errorMessage}`);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate required parameters
|
|
24
|
+
* @param params - Object containing parameters to validate
|
|
25
|
+
* @param requiredKeys - Array of required parameter keys
|
|
26
|
+
* @throws Error if any required parameter is missing
|
|
27
|
+
*/
|
|
28
|
+
export function validateRequiredParams(params, requiredKeys) {
|
|
29
|
+
const missingKeys = requiredKeys.filter(key => params[key] === undefined || params[key] === null || params[key] === '');
|
|
30
|
+
if (missingKeys.length > 0) {
|
|
31
|
+
throw new Error(`Missing required parameters: ${missingKeys.join(', ')}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate publish note parameters with length constraints
|
|
36
|
+
* @param title - Note title
|
|
37
|
+
* @param note - Note content
|
|
38
|
+
* @param imagePaths - Array of image paths
|
|
39
|
+
* @throws Error if any parameter violates constraints
|
|
40
|
+
*/
|
|
41
|
+
export function validatePublishNoteParams(title, note, imagePaths) {
|
|
42
|
+
// Validate title length (max 20 characters)
|
|
43
|
+
if (title && title.length > 20) {
|
|
44
|
+
throw new Error(`Title length cannot exceed 20 characters. Current length: ${title.length}`);
|
|
45
|
+
}
|
|
46
|
+
// Validate note content length (max 1000 characters)
|
|
47
|
+
if (note && note.length > 1000) {
|
|
48
|
+
throw new Error(`Note content length cannot exceed 1000 characters. Current length: ${note.length}`);
|
|
49
|
+
}
|
|
50
|
+
// Validate image count (max 18 images)
|
|
51
|
+
if (imagePaths && imagePaths.length > 18) {
|
|
52
|
+
throw new Error(`Maximum 18 images allowed. Current count: ${imagePaths.length}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a standardized response object
|
|
57
|
+
* @param success - Whether the operation was successful
|
|
58
|
+
* @param data - Optional data to include
|
|
59
|
+
* @param message - Optional message
|
|
60
|
+
* @param error - Optional error information
|
|
61
|
+
* @returns Standardized response object
|
|
62
|
+
*/
|
|
63
|
+
export function createResponse(success, data, message, error) {
|
|
64
|
+
const response = { success };
|
|
65
|
+
if (data !== undefined)
|
|
66
|
+
response.data = data;
|
|
67
|
+
if (message !== undefined)
|
|
68
|
+
response.message = message;
|
|
69
|
+
if (error !== undefined)
|
|
70
|
+
response.error = error;
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retry a function with exponential backoff
|
|
75
|
+
* @param fn - Function to retry
|
|
76
|
+
* @param maxRetries - Maximum number of retries
|
|
77
|
+
* @param baseDelay - Base delay in milliseconds
|
|
78
|
+
* @returns Promise that resolves with the function result
|
|
79
|
+
*/
|
|
80
|
+
export async function retryWithBackoff(fn, maxRetries = 3, baseDelay = 1000) {
|
|
81
|
+
let lastError;
|
|
82
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
83
|
+
try {
|
|
84
|
+
return await fn();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
lastError = error;
|
|
88
|
+
if (attempt === maxRetries) {
|
|
89
|
+
throw lastError;
|
|
90
|
+
}
|
|
91
|
+
const delay = baseDelay * Math.pow(2, attempt);
|
|
92
|
+
await sleep(delay);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw lastError;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a standardized MCP tool response
|
|
99
|
+
* @param data - Data to include in the response
|
|
100
|
+
* @returns Standardized MCP response format
|
|
101
|
+
*/
|
|
102
|
+
export function createToolResponse(data) {
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: 'text',
|
|
107
|
+
text: JSON.stringify(data, null, 2),
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a standardized MCP error response
|
|
114
|
+
* @param error - Error to format
|
|
115
|
+
* @returns Standardized MCP error response format
|
|
116
|
+
*/
|
|
117
|
+
export function createErrorResponse(error) {
|
|
118
|
+
const errorData = error instanceof Error ? {
|
|
119
|
+
success: false,
|
|
120
|
+
error: 'UnknownError',
|
|
121
|
+
message: error.message,
|
|
122
|
+
stack: error.stack,
|
|
123
|
+
} : {
|
|
124
|
+
success: false,
|
|
125
|
+
error: 'UnknownError',
|
|
126
|
+
message: String(error),
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
type: 'text',
|
|
132
|
+
text: JSON.stringify(errorData, null, 2),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 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AAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,MAAM,SAAU,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAU,IAAO;IACjD,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;aACpC;SACF;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,SAAS,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC;QACzC,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,cAAc;QACrB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC,CAAC;QACF,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,cAAc;QACrB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;KACvB,CAAC;IAEF,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;aACzC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/handlers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource request handlers for XHS MCP Server
|
|
3
|
+
*/
|
|
4
|
+
export declare class ResourceHandlers {
|
|
5
|
+
private authService;
|
|
6
|
+
constructor();
|
|
7
|
+
getCookiesResource(): Promise<string>;
|
|
8
|
+
getConfigResource(): Promise<string>;
|
|
9
|
+
getStatusResource(): Promise<string>;
|
|
10
|
+
handleResourceRequest(uri: string): Promise<{
|
|
11
|
+
contents: {
|
|
12
|
+
uri: string;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
text: string;
|
|
15
|
+
}[];
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=resource.handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.handlers.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/resource.handlers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAc;;IAO3B,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IASrC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAcpC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAyCpC,qBAAqB,CAAC,GAAG,EAAE,MAAM;;;;;;;CA0CxC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource request handlers for XHS MCP Server
|
|
3
|
+
*/
|
|
4
|
+
import { AuthService } from '../../lib/auth/auth.service.js';
|
|
5
|
+
import { getConfig, getCookiesInfo } from '../../lib/shared/index.js';
|
|
6
|
+
export class ResourceHandlers {
|
|
7
|
+
authService;
|
|
8
|
+
constructor() {
|
|
9
|
+
const config = getConfig();
|
|
10
|
+
this.authService = new AuthService(config);
|
|
11
|
+
}
|
|
12
|
+
async getCookiesResource() {
|
|
13
|
+
try {
|
|
14
|
+
const cookiesInfo = getCookiesInfo();
|
|
15
|
+
return JSON.stringify(cookiesInfo, null, 2);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return JSON.stringify({ error: String(error) }, null, 2);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async getConfigResource() {
|
|
22
|
+
try {
|
|
23
|
+
const configDict = getConfig();
|
|
24
|
+
const configWithFramework = {
|
|
25
|
+
...configDict,
|
|
26
|
+
framework: 'MCP TypeScript',
|
|
27
|
+
version: configDict.server.version,
|
|
28
|
+
};
|
|
29
|
+
return JSON.stringify(configWithFramework, null, 2);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return JSON.stringify({ error: String(error) }, null, 2);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async getStatusResource() {
|
|
36
|
+
try {
|
|
37
|
+
// Quick status check (but don't fail if it errors)
|
|
38
|
+
let authStatus = { status: 'unknown', error: 'Status check not performed' };
|
|
39
|
+
try {
|
|
40
|
+
authStatus = await this.authService.checkStatus();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
authStatus = { status: 'error', error: String(error) };
|
|
44
|
+
}
|
|
45
|
+
const cookiesInfo = getCookiesInfo();
|
|
46
|
+
const config = getConfig();
|
|
47
|
+
const statusData = {
|
|
48
|
+
server: {
|
|
49
|
+
status: 'running',
|
|
50
|
+
name: config.server.name,
|
|
51
|
+
version: config.server.version,
|
|
52
|
+
framework: 'MCP TypeScript',
|
|
53
|
+
},
|
|
54
|
+
authentication: authStatus,
|
|
55
|
+
cookies: {
|
|
56
|
+
fileExists: cookiesInfo.fileExists,
|
|
57
|
+
cookieCount: cookiesInfo.cookieCount,
|
|
58
|
+
},
|
|
59
|
+
capabilities: {
|
|
60
|
+
toolsAvailable: 8,
|
|
61
|
+
promptsAvailable: 0,
|
|
62
|
+
resourcesAvailable: 3,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return JSON.stringify(statusData, null, 2);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return JSON.stringify({
|
|
69
|
+
server: { status: 'error', error: String(error) },
|
|
70
|
+
framework: 'MCP TypeScript',
|
|
71
|
+
}, null, 2);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async handleResourceRequest(uri) {
|
|
75
|
+
try {
|
|
76
|
+
let content;
|
|
77
|
+
switch (uri) {
|
|
78
|
+
case 'xhs://cookies':
|
|
79
|
+
content = await this.getCookiesResource();
|
|
80
|
+
break;
|
|
81
|
+
case 'xhs://config':
|
|
82
|
+
content = await this.getConfigResource();
|
|
83
|
+
break;
|
|
84
|
+
case 'xhs://status':
|
|
85
|
+
content = await this.getStatusResource();
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unknown resource: ${uri}`);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
contents: [
|
|
92
|
+
{
|
|
93
|
+
uri,
|
|
94
|
+
mimeType: 'application/json',
|
|
95
|
+
text: content,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
contents: [
|
|
103
|
+
{
|
|
104
|
+
uri,
|
|
105
|
+
mimeType: 'application/json',
|
|
106
|
+
text: JSON.stringify({ error: String(error) }, null, 2),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=resource.handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.handlers.js","sourceRoot":"","sources":["../../../src/server/handlers/resource.handlers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAA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