mcp-wordpress 1.5.2 → 2.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.
- package/README.md +332 -61
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +4 -4
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/client/MockWordPressClient.d.ts +55 -0
- package/dist/client/MockWordPressClient.d.ts.map +1 -0
- package/dist/client/MockWordPressClient.js +369 -0
- package/dist/client/MockWordPressClient.js.map +1 -0
- package/dist/client/api.d.ts +1 -0
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +26 -60
- package/dist/client/api.js.map +1 -1
- package/dist/client/managers/AuthenticationManager.d.ts.map +1 -1
- package/dist/client/managers/AuthenticationManager.js +4 -3
- package/dist/client/managers/AuthenticationManager.js.map +1 -1
- package/dist/config/ConfigurationSchema.d.ts +3 -3
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +7 -24
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +8 -0
- package/dist/config/ServerConfiguration.d.ts.map +1 -1
- package/dist/config/ServerConfiguration.js +80 -31
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +5 -7
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -29
- package/dist/index.js.map +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +3 -11
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +4 -0
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +71 -8
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +8 -3
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +287 -20
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +47 -9
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/users.d.ts.map +1 -1
- package/dist/tools/users.js +113 -10
- package/dist/tools/users.js.map +1 -1
- package/dist/utils/enhancedError.d.ts +61 -0
- package/dist/utils/enhancedError.d.ts.map +1 -0
- package/dist/utils/enhancedError.js +221 -0
- package/dist/utils/enhancedError.js.map +1 -0
- package/dist/utils/streaming.d.ts +104 -0
- package/dist/utils/streaming.d.ts.map +1 -0
- package/dist/utils/streaming.js +312 -0
- package/dist/utils/streaming.js.map +1 -0
- package/dist/utils/validation.d.ts +19 -3
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +174 -24
- package/dist/utils/validation.js.map +1 -1
- package/docs/ARCHITECTURE.md +850 -0
- package/docs/CACHING.md +20 -17
- package/docs/CONFIGURATION.md +660 -0
- package/docs/DOCKER.md +61 -60
- package/docs/EVALUATION.md +397 -0
- package/docs/INSTALLATION.md +423 -0
- package/docs/PERFORMANCE_MONITORING.md +17 -15
- package/docs/SECURITY.md +621 -0
- package/docs/SECURITY_TESTING.md +22 -26
- package/docs/TEST_SITE_SETUP.md +136 -0
- package/docs/TROUBLESHOOTING.md +578 -0
- package/docs/api/README.md +76 -91
- package/docs/api/categories/auth.md +0 -2
- package/docs/api/categories/cache.md +0 -2
- package/docs/api/categories/comment.md +0 -2
- package/docs/api/categories/media.md +0 -2
- package/docs/api/categories/page.md +0 -2
- package/docs/api/categories/performance.md +0 -2
- package/docs/api/categories/post.md +0 -2
- package/docs/api/categories/site.md +0 -2
- package/docs/api/categories/taxonomy.md +0 -2
- package/docs/api/categories/user.md +0 -2
- package/docs/api/summary.json +1 -1
- package/docs/api/tools/wp_approve_comment.md +11 -3
- package/docs/api/tools/wp_cache_clear.md +14 -5
- package/docs/api/tools/wp_cache_info.md +14 -5
- package/docs/api/tools/wp_cache_stats.md +14 -5
- package/docs/api/tools/wp_cache_warm.md +14 -5
- package/docs/api/tools/wp_create_application_password.md +11 -3
- package/docs/api/tools/wp_create_category.md +11 -3
- package/docs/api/tools/wp_create_comment.md +14 -5
- package/docs/api/tools/wp_create_page.md +13 -5
- package/docs/api/tools/wp_create_post.md +14 -7
- package/docs/api/tools/wp_create_tag.md +11 -3
- package/docs/api/tools/wp_create_user.md +13 -5
- package/docs/api/tools/wp_delete_application_password.md +11 -3
- package/docs/api/tools/wp_delete_category.md +11 -3
- package/docs/api/tools/wp_delete_comment.md +11 -3
- package/docs/api/tools/wp_delete_media.md +10 -3
- package/docs/api/tools/wp_delete_page.md +10 -3
- package/docs/api/tools/wp_delete_post.md +11 -5
- package/docs/api/tools/wp_delete_tag.md +11 -3
- package/docs/api/tools/wp_delete_user.md +10 -3
- package/docs/api/tools/wp_get_application_passwords.md +11 -3
- package/docs/api/tools/wp_get_auth_status.md +11 -3
- package/docs/api/tools/wp_get_category.md +11 -3
- package/docs/api/tools/wp_get_comment.md +11 -3
- package/docs/api/tools/wp_get_current_user.md +11 -3
- package/docs/api/tools/wp_get_media.md +11 -3
- package/docs/api/tools/wp_get_page.md +11 -3
- package/docs/api/tools/wp_get_page_revisions.md +11 -3
- package/docs/api/tools/wp_get_post.md +12 -5
- package/docs/api/tools/wp_get_post_revisions.md +11 -3
- package/docs/api/tools/wp_get_site_settings.md +10 -3
- package/docs/api/tools/wp_get_tag.md +11 -3
- package/docs/api/tools/wp_get_user.md +11 -3
- package/docs/api/tools/wp_list_categories.md +11 -3
- package/docs/api/tools/wp_list_comments.md +11 -3
- package/docs/api/tools/wp_list_media.md +14 -5
- package/docs/api/tools/wp_list_pages.md +14 -5
- package/docs/api/tools/wp_list_posts.md +15 -7
- package/docs/api/tools/wp_list_tags.md +11 -3
- package/docs/api/tools/wp_list_users.md +11 -3
- package/docs/api/tools/wp_performance_alerts.md +17 -7
- package/docs/api/tools/wp_performance_benchmark.md +17 -7
- package/docs/api/tools/wp_performance_export.md +17 -7
- package/docs/api/tools/wp_performance_history.md +17 -7
- package/docs/api/tools/wp_performance_optimize.md +17 -7
- package/docs/api/tools/wp_performance_stats.md +17 -7
- package/docs/api/tools/wp_search_site.md +11 -3
- package/docs/api/tools/wp_spam_comment.md +11 -3
- package/docs/api/tools/wp_switch_auth_method.md +14 -5
- package/docs/api/tools/wp_test_auth.md +11 -3
- package/docs/api/tools/wp_update_category.md +11 -3
- package/docs/api/tools/wp_update_comment.md +14 -5
- package/docs/api/tools/wp_update_media.md +14 -5
- package/docs/api/tools/wp_update_page.md +13 -5
- package/docs/api/tools/wp_update_post.md +14 -7
- package/docs/api/tools/wp_update_site_settings.md +14 -5
- package/docs/api/tools/wp_update_tag.md +11 -3
- package/docs/api/tools/wp_update_user.md +13 -5
- package/docs/api/tools/wp_upload_media.md +13 -5
- package/docs/api/types/WordPressPost.md +2 -0
- package/docs/code-improvements.md +40 -0
- package/docs/contract-testing.md +1 -1
- package/docs/developer/API_REFERENCE.md +19 -59
- package/docs/developer/ARCHITECTURE.md +8 -11
- package/docs/developer/BUILD_SYSTEM.md +2 -2
- package/docs/developer/CONTRIBUTING.md +3 -5
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +2 -2
- package/docs/developer/MIGRATION_GUIDE.md +5 -6
- package/docs/developer/README.md +2 -1
- package/docs/developer/REFACTORING.md +9 -15
- package/docs/developer/RELEASE_PROCESS.md +4 -3
- package/docs/developer/TESTING.md +2 -2
- package/docs/examples/claude-desktop-config.md +8 -0
- package/docs/integrations/claude-desktop.md +426 -0
- package/docs/integrations/cline.md +537 -0
- package/docs/integrations/vs-code.md +515 -0
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +30 -23
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +7 -6
- package/docs/testing-configurations.md +11 -0
- package/docs/user-guides/DOCKER_NPM_DTX_SETUP.md +3 -2
- package/docs/user-guides/DOCKER_SETUP.md +3 -2
- package/docs/user-guides/DTX_SETUP.md +6 -5
- package/docs/user-guides/DXT_INSTALLATION.md +4 -4
- package/docs/user-guides/NPM_SETUP.md +4 -2
- package/docs/user-guides/NPX_SETUP.md +4 -2
- package/docs/user-guides/SMITHERY_SETUP.md +402 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +45 -42
- package/package.json +12 -2
- package/src/cache/CacheInvalidation.ts +7 -18
- package/src/client/MockWordPressClient.ts +398 -0
- package/src/client/api.ts +77 -237
- package/src/client/managers/AuthenticationManager.ts +19 -56
- package/src/config/ConfigurationSchema.ts +14 -45
- package/src/config/ServerConfiguration.ts +98 -71
- package/src/docs/DocumentationGenerator.ts +39 -123
- package/src/dxt-entry.cjs +4 -1
- package/src/index.ts +35 -54
- package/src/security/InputValidator.ts +15 -57
- package/src/server/ToolRegistry.ts +88 -17
- package/src/tools/auth.ts +15 -22
- package/src/tools/posts.ts +347 -64
- package/src/tools/site.ts +69 -46
- package/src/tools/users.ts +142 -44
- package/src/utils/enhancedError.ts +248 -0
- package/src/utils/streaming.ts +428 -0
- package/src/utils/validation.ts +253 -92
- package/dist/mcp-wordpress-1.5.2.tgz +0 -0
package/src/tools/site.ts
CHANGED
|
@@ -21,8 +21,7 @@ export class SiteTools {
|
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
name: "wp_update_site_settings",
|
|
24
|
-
description:
|
|
25
|
-
"Updates one or more general settings for a WordPress site.",
|
|
24
|
+
description: "Updates one or more general settings for a WordPress site.",
|
|
26
25
|
parameters: [
|
|
27
26
|
{
|
|
28
27
|
name: "title",
|
|
@@ -37,15 +36,21 @@ export class SiteTools {
|
|
|
37
36
|
{
|
|
38
37
|
name: "timezone",
|
|
39
38
|
type: "string",
|
|
40
|
-
description:
|
|
41
|
-
"A city in the same timezone, e.g., 'America/New_York'.",
|
|
39
|
+
description: "A city in the same timezone, e.g., 'America/New_York'.",
|
|
42
40
|
},
|
|
43
41
|
],
|
|
44
42
|
handler: this.handleUpdateSiteSettings.bind(this),
|
|
45
43
|
},
|
|
46
44
|
{
|
|
47
45
|
name: "wp_search_site",
|
|
48
|
-
description:
|
|
46
|
+
description:
|
|
47
|
+
"Performs a site-wide search for content across posts, pages, and media with comprehensive results and metadata.\n\n" +
|
|
48
|
+
"**Usage Examples:**\n" +
|
|
49
|
+
'• Search everything: `wp_search_site --term="WordPress"`\n' +
|
|
50
|
+
'• Search posts only: `wp_search_site --term="tutorial" --type="posts"`\n' +
|
|
51
|
+
'• Search pages: `wp_search_site --term="about" --type="pages"`\n' +
|
|
52
|
+
'• Search media: `wp_search_site --term="logo" --type="media"`\n' +
|
|
53
|
+
'• Find specific content: `wp_search_site --term="contact form"`',
|
|
49
54
|
parameters: [
|
|
50
55
|
{
|
|
51
56
|
name: "term",
|
|
@@ -116,35 +121,70 @@ export class SiteTools {
|
|
|
116
121
|
];
|
|
117
122
|
}
|
|
118
123
|
|
|
119
|
-
public async handleGetSiteSettings(
|
|
120
|
-
client: WordPressClient,
|
|
121
|
-
params: any,
|
|
122
|
-
): Promise<any> {
|
|
124
|
+
public async handleGetSiteSettings(client: WordPressClient, params: any): Promise<any> {
|
|
123
125
|
try {
|
|
124
126
|
const settings = await client.getSiteSettings();
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
const siteUrl = client.getSiteUrl();
|
|
128
|
+
|
|
129
|
+
// Enhanced site settings with comprehensive details
|
|
130
|
+
const weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
131
|
+
const startOfWeek = settings.start_of_week !== undefined ? weekDays[settings.start_of_week] : "Not set";
|
|
132
|
+
|
|
133
|
+
// Get additional site information
|
|
134
|
+
const currentTime = new Date().toLocaleString("en-US", {
|
|
135
|
+
timeZone: settings.timezone || "UTC",
|
|
136
|
+
weekday: "long",
|
|
137
|
+
year: "numeric",
|
|
138
|
+
month: "long",
|
|
139
|
+
day: "numeric",
|
|
140
|
+
hour: "2-digit",
|
|
141
|
+
minute: "2-digit",
|
|
142
|
+
second: "2-digit",
|
|
143
|
+
timeZoneName: "short",
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
let content = `**🌐 Site Settings for ${siteUrl}**\n\n`;
|
|
147
|
+
|
|
148
|
+
content += `**📋 Basic Information:**\n`;
|
|
149
|
+
content += `- **Title:** ${settings.title || "Not set"}\n`;
|
|
150
|
+
content += `- **Description:** ${settings.description || "Not set"}\n`;
|
|
151
|
+
content += `- **URL:** ${settings.url || siteUrl}\n`;
|
|
152
|
+
content += `- **Admin Email:** ${settings.email || "Not set"}\n\n`;
|
|
153
|
+
|
|
154
|
+
content += `**🌍 Localization:**\n`;
|
|
155
|
+
content += `- **Language:** ${settings.language || "English (US)"}\n`;
|
|
156
|
+
content += `- **Timezone:** ${settings.timezone || "UTC"}\n`;
|
|
157
|
+
content += `- **Current Time:** ${currentTime}\n\n`;
|
|
158
|
+
|
|
159
|
+
content += `**📅 Date & Time Format:**\n`;
|
|
160
|
+
content += `- **Date Format:** ${settings.date_format || "Not set"}\n`;
|
|
161
|
+
content += `- **Time Format:** ${settings.time_format || "Not set"}\n`;
|
|
162
|
+
content += `- **Start of Week:** ${startOfWeek}\n\n`;
|
|
163
|
+
|
|
164
|
+
content += `**📝 Content Settings:**\n`;
|
|
165
|
+
content += `- **Posts per Page:** ${settings.posts_per_page || "Not set"}\n`;
|
|
166
|
+
content += `- **Default Category:** ${settings.default_category || "Not set"}\n`;
|
|
167
|
+
content += `- **Default Post Format:** ${settings.default_post_format || "Standard"}\n\n`;
|
|
168
|
+
|
|
169
|
+
content += `**💬 Discussion Settings:**\n`;
|
|
170
|
+
content += `- **Default Comment Status:** ${settings.default_comment_status || "Not set"}\n`;
|
|
171
|
+
content += `- **Default Ping Status:** ${settings.default_ping_status || "Not set"}\n`;
|
|
172
|
+
content += `- **Use Smilies:** ${settings.use_smilies ? "Yes" : "No"}\n\n`;
|
|
173
|
+
|
|
174
|
+
content += `**📊 Retrieved:** ${new Date().toLocaleString()}`;
|
|
175
|
+
|
|
131
176
|
return content;
|
|
132
177
|
} catch (error) {
|
|
133
178
|
throw new Error(`Failed to get site settings: ${getErrorMessage(error)}`);
|
|
134
179
|
}
|
|
135
180
|
}
|
|
136
181
|
|
|
137
|
-
public async handleUpdateSiteSettings(
|
|
138
|
-
client: WordPressClient,
|
|
139
|
-
params: any,
|
|
140
|
-
): Promise<any> {
|
|
182
|
+
public async handleUpdateSiteSettings(client: WordPressClient, params: any): Promise<any> {
|
|
141
183
|
try {
|
|
142
184
|
const updatedSettings = await client.updateSiteSettings(params);
|
|
143
185
|
return `✅ Site settings updated successfully. New title: ${updatedSettings.title}`;
|
|
144
186
|
} catch (error) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
`Failed to update site settings: ${getErrorMessage(error)}`,
|
|
147
|
-
);
|
|
187
|
+
throw new Error(`Failed to update site settings: ${getErrorMessage(error)}`);
|
|
148
188
|
}
|
|
149
189
|
}
|
|
150
190
|
|
|
@@ -153,28 +193,20 @@ export class SiteTools {
|
|
|
153
193
|
params: { term: string; type?: "posts" | "pages" | "media" },
|
|
154
194
|
): Promise<any> {
|
|
155
195
|
try {
|
|
156
|
-
const results = await client.search(
|
|
157
|
-
params.term,
|
|
158
|
-
params.type ? [params.type] : undefined,
|
|
159
|
-
);
|
|
196
|
+
const results = await client.search(params.term, params.type ? [params.type] : undefined);
|
|
160
197
|
if (results.length === 0) {
|
|
161
198
|
return `No results found for "${params.term}".`;
|
|
162
199
|
}
|
|
163
200
|
const content =
|
|
164
201
|
`Found ${results.length} results for "${params.term}":\n\n` +
|
|
165
|
-
results
|
|
166
|
-
.map((r) => `- [${r.type}] **${r.title}**\n Link: ${r.url}`)
|
|
167
|
-
.join("\n");
|
|
202
|
+
results.map((r) => `- [${r.type}] **${r.title}**\n Link: ${r.url}`).join("\n");
|
|
168
203
|
return content;
|
|
169
204
|
} catch (error) {
|
|
170
205
|
throw new Error(`Failed to perform search: ${getErrorMessage(error)}`);
|
|
171
206
|
}
|
|
172
207
|
}
|
|
173
208
|
|
|
174
|
-
public async handleGetApplicationPasswords(
|
|
175
|
-
client: WordPressClient,
|
|
176
|
-
params: { user_id: number },
|
|
177
|
-
): Promise<any> {
|
|
209
|
+
public async handleGetApplicationPasswords(client: WordPressClient, params: { user_id: number }): Promise<any> {
|
|
178
210
|
try {
|
|
179
211
|
const passwords = await client.getApplicationPasswords(params.user_id);
|
|
180
212
|
if (passwords.length === 0) {
|
|
@@ -190,9 +222,7 @@ export class SiteTools {
|
|
|
190
222
|
.join("\n");
|
|
191
223
|
return content;
|
|
192
224
|
} catch (error) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Failed to get application passwords: ${getErrorMessage(error)}`,
|
|
195
|
-
);
|
|
225
|
+
throw new Error(`Failed to get application passwords: ${getErrorMessage(error)}`);
|
|
196
226
|
}
|
|
197
227
|
}
|
|
198
228
|
|
|
@@ -201,10 +231,7 @@ export class SiteTools {
|
|
|
201
231
|
params: { user_id: number; app_name: string },
|
|
202
232
|
): Promise<any> {
|
|
203
233
|
try {
|
|
204
|
-
const result = await client.createApplicationPassword(
|
|
205
|
-
params.user_id,
|
|
206
|
-
params.app_name,
|
|
207
|
-
);
|
|
234
|
+
const result = await client.createApplicationPassword(params.user_id, params.app_name);
|
|
208
235
|
const content =
|
|
209
236
|
"✅ **Application password created successfully!**\n\n" +
|
|
210
237
|
`**Name:** ${result.name}\n` +
|
|
@@ -212,9 +239,7 @@ export class SiteTools {
|
|
|
212
239
|
"**IMPORTANT:** This password is shown only once. Please save it securely.";
|
|
213
240
|
return content;
|
|
214
241
|
} catch (error) {
|
|
215
|
-
throw new Error(
|
|
216
|
-
`Failed to create application password: ${getErrorMessage(error)}`,
|
|
217
|
-
);
|
|
242
|
+
throw new Error(`Failed to create application password: ${getErrorMessage(error)}`);
|
|
218
243
|
}
|
|
219
244
|
}
|
|
220
245
|
|
|
@@ -226,9 +251,7 @@ export class SiteTools {
|
|
|
226
251
|
await client.deleteApplicationPassword(params.user_id, params.uuid);
|
|
227
252
|
return `✅ Application password with UUID ${params.uuid} has been revoked.`;
|
|
228
253
|
} catch (error) {
|
|
229
|
-
throw new Error(
|
|
230
|
-
`Failed to delete application password: ${getErrorMessage(error)}`,
|
|
231
|
-
);
|
|
254
|
+
throw new Error(`Failed to delete application password: ${getErrorMessage(error)}`);
|
|
232
255
|
}
|
|
233
256
|
}
|
|
234
257
|
}
|
package/src/tools/users.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { WordPressClient } from "../client/api.js";
|
|
2
|
-
import {
|
|
3
|
-
CreateUserRequest,
|
|
4
|
-
UpdateUserRequest,
|
|
5
|
-
UserQueryParams,
|
|
6
|
-
} from "../types/wordpress.js";
|
|
2
|
+
import { CreateUserRequest, UpdateUserRequest, UserQueryParams } from "../types/wordpress.js";
|
|
7
3
|
import { getErrorMessage } from "../utils/error.js";
|
|
4
|
+
import { WordPressDataStreamer, StreamingUtils, StreamingResult } from "../utils/streaming.js";
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Provides tools for managing users on a WordPress site.
|
|
@@ -19,7 +16,14 @@ export class UserTools {
|
|
|
19
16
|
return [
|
|
20
17
|
{
|
|
21
18
|
name: "wp_list_users",
|
|
22
|
-
description:
|
|
19
|
+
description:
|
|
20
|
+
"Lists users from a WordPress site with comprehensive filtering and detailed user information including roles, registration dates, and activity status.\n\n" +
|
|
21
|
+
"**Usage Examples:**\n" +
|
|
22
|
+
"• List all users: `wp_list_users`\n" +
|
|
23
|
+
'• Search users: `wp_list_users --search="john"`\n' +
|
|
24
|
+
'• Filter by role: `wp_list_users --roles=["editor","author"]`\n' +
|
|
25
|
+
'• Find admins: `wp_list_users --roles=["administrator"]`\n' +
|
|
26
|
+
'• Combined search: `wp_list_users --search="smith" --roles=["subscriber"]`',
|
|
23
27
|
parameters: [
|
|
24
28
|
{
|
|
25
29
|
name: "search",
|
|
@@ -50,7 +54,13 @@ export class UserTools {
|
|
|
50
54
|
},
|
|
51
55
|
{
|
|
52
56
|
name: "wp_get_current_user",
|
|
53
|
-
description:
|
|
57
|
+
description:
|
|
58
|
+
"Retrieves the currently authenticated user with comprehensive profile information including roles, capabilities, and account details.\n\n" +
|
|
59
|
+
"**Usage Examples:**\n" +
|
|
60
|
+
"• Get current user: `wp_get_current_user`\n" +
|
|
61
|
+
"• Check permissions: Use this to verify your current user's capabilities and roles\n" +
|
|
62
|
+
"• Account verification: Confirm you're authenticated with the correct account\n" +
|
|
63
|
+
"• Profile details: View registration date, email, and user metadata",
|
|
54
64
|
parameters: [],
|
|
55
65
|
handler: this.handleGetCurrentUser.bind(this),
|
|
56
66
|
},
|
|
@@ -121,8 +131,7 @@ export class UserTools {
|
|
|
121
131
|
{
|
|
122
132
|
name: "reassign",
|
|
123
133
|
type: "number",
|
|
124
|
-
description:
|
|
125
|
-
"The ID of a user to reassign the deleted user's content to.",
|
|
134
|
+
description: "The ID of a user to reassign the deleted user's content to.",
|
|
126
135
|
},
|
|
127
136
|
],
|
|
128
137
|
handler: this.handleDeleteUser.bind(this),
|
|
@@ -130,33 +139,86 @@ export class UserTools {
|
|
|
130
139
|
];
|
|
131
140
|
}
|
|
132
141
|
|
|
133
|
-
public async handleListUsers(
|
|
134
|
-
client: WordPressClient,
|
|
135
|
-
params: UserQueryParams,
|
|
136
|
-
): Promise<any> {
|
|
142
|
+
public async handleListUsers(client: WordPressClient, params: UserQueryParams): Promise<any> {
|
|
137
143
|
try {
|
|
138
144
|
const users = await client.getUsers(params);
|
|
139
145
|
if (users.length === 0) {
|
|
140
146
|
return "No users found matching the criteria.";
|
|
141
147
|
}
|
|
148
|
+
|
|
149
|
+
// Use streaming for large user result sets (>30 users)
|
|
150
|
+
if (users.length > 30) {
|
|
151
|
+
const streamResults: StreamingResult<any>[] = [];
|
|
152
|
+
|
|
153
|
+
for await (const result of WordPressDataStreamer.streamUsers(users, {
|
|
154
|
+
includeRoles: true,
|
|
155
|
+
includeCapabilities: false, // Too verbose for large sets
|
|
156
|
+
batchSize: 15,
|
|
157
|
+
})) {
|
|
158
|
+
streamResults.push(result);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return StreamingUtils.formatStreamingResponse(streamResults, "users");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Enhanced user information with comprehensive details
|
|
165
|
+
const siteUrl = client.getSiteUrl ? client.getSiteUrl() : "Unknown site";
|
|
166
|
+
const userCount = users.length;
|
|
167
|
+
const rolesSummary = users.reduce(
|
|
168
|
+
(acc, u) => {
|
|
169
|
+
const roles = u.roles || [];
|
|
170
|
+
roles.forEach((role) => {
|
|
171
|
+
acc[role] = (acc[role] || 0) + 1;
|
|
172
|
+
});
|
|
173
|
+
return acc;
|
|
174
|
+
},
|
|
175
|
+
{} as Record<string, number>,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const metadata = [
|
|
179
|
+
`👥 **Users Summary**: ${userCount} total users`,
|
|
180
|
+
`🌐 **Source**: ${siteUrl}`,
|
|
181
|
+
`📊 **Roles Distribution**: ${Object.entries(rolesSummary)
|
|
182
|
+
.map(([role, count]) => `${role}: ${count}`)
|
|
183
|
+
.join(", ")}`,
|
|
184
|
+
`📅 **Retrieved**: ${new Date().toLocaleString()}`,
|
|
185
|
+
];
|
|
186
|
+
|
|
142
187
|
const content =
|
|
143
|
-
|
|
188
|
+
metadata.join("\n") +
|
|
189
|
+
"\n\n" +
|
|
144
190
|
users
|
|
145
|
-
.map(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
191
|
+
.map((u) => {
|
|
192
|
+
const registrationDate = u.registered_date
|
|
193
|
+
? new Date(u.registered_date).toLocaleDateString("en-US", {
|
|
194
|
+
year: "numeric",
|
|
195
|
+
month: "short",
|
|
196
|
+
day: "numeric",
|
|
197
|
+
})
|
|
198
|
+
: "Unknown";
|
|
199
|
+
|
|
200
|
+
const roles = u.roles?.join(", ") || "No roles";
|
|
201
|
+
const description = u.description || "No description";
|
|
202
|
+
const displayName = u.name || "No display name";
|
|
203
|
+
const userUrl = u.url || "No URL";
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
`- **ID ${u.id}**: ${displayName} (@${u.slug})\n` +
|
|
207
|
+
` 📧 Email: ${u.email || "No email"}\n` +
|
|
208
|
+
` 🎭 Roles: ${roles}\n` +
|
|
209
|
+
` 📅 Registered: ${registrationDate}\n` +
|
|
210
|
+
` 🔗 URL: ${userUrl}\n` +
|
|
211
|
+
` 📝 Description: ${description}`
|
|
212
|
+
);
|
|
213
|
+
})
|
|
214
|
+
.join("\n\n");
|
|
150
215
|
return content;
|
|
151
216
|
} catch (error) {
|
|
152
217
|
throw new Error(`Failed to list users: ${getErrorMessage(error)}`);
|
|
153
218
|
}
|
|
154
219
|
}
|
|
155
220
|
|
|
156
|
-
public async handleGetUser(
|
|
157
|
-
client: WordPressClient,
|
|
158
|
-
params: { id: number },
|
|
159
|
-
): Promise<any> {
|
|
221
|
+
public async handleGetUser(client: WordPressClient, params: { id: number }): Promise<any> {
|
|
160
222
|
try {
|
|
161
223
|
const user = await client.getUser(params.id);
|
|
162
224
|
const content =
|
|
@@ -171,28 +233,70 @@ export class UserTools {
|
|
|
171
233
|
}
|
|
172
234
|
}
|
|
173
235
|
|
|
174
|
-
public async handleGetCurrentUser(
|
|
175
|
-
client: WordPressClient,
|
|
176
|
-
params: any,
|
|
177
|
-
): Promise<any> {
|
|
236
|
+
public async handleGetCurrentUser(client: WordPressClient, params: any): Promise<any> {
|
|
178
237
|
try {
|
|
179
238
|
const user = await client.getCurrentUser();
|
|
239
|
+
const siteUrl = client.getSiteUrl();
|
|
240
|
+
|
|
241
|
+
// Extract meaningful information from capabilities
|
|
242
|
+
const capabilities = user.capabilities || {};
|
|
243
|
+
const keyCapabilities = [
|
|
244
|
+
"edit_posts",
|
|
245
|
+
"edit_pages",
|
|
246
|
+
"publish_posts",
|
|
247
|
+
"publish_pages",
|
|
248
|
+
"delete_posts",
|
|
249
|
+
"delete_pages",
|
|
250
|
+
"manage_categories",
|
|
251
|
+
"manage_options",
|
|
252
|
+
"moderate_comments",
|
|
253
|
+
"upload_files",
|
|
254
|
+
"edit_others_posts",
|
|
255
|
+
"delete_others_posts",
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
const userCapabilities = keyCapabilities.filter((cap) => capabilities[cap]).join(", ");
|
|
259
|
+
const totalCapabilities = Object.keys(capabilities).length;
|
|
260
|
+
|
|
261
|
+
// Format registration date more clearly
|
|
262
|
+
const registrationDate = user.registered_date
|
|
263
|
+
? new Date(user.registered_date).toLocaleDateString("en-US", {
|
|
264
|
+
year: "numeric",
|
|
265
|
+
month: "long",
|
|
266
|
+
day: "numeric",
|
|
267
|
+
})
|
|
268
|
+
: "Not available";
|
|
269
|
+
|
|
270
|
+
// Extract role information
|
|
271
|
+
const roles = user.roles || [];
|
|
272
|
+
const primaryRole = roles[0] || "No role assigned";
|
|
273
|
+
const allRoles = roles.length > 1 ? roles.join(", ") : primaryRole;
|
|
274
|
+
|
|
275
|
+
// Build comprehensive user information
|
|
180
276
|
const content =
|
|
181
|
-
`**Current User Details
|
|
182
|
-
`- **
|
|
183
|
-
`- **
|
|
184
|
-
`- **
|
|
185
|
-
`- **
|
|
277
|
+
`**Current User Details for ${siteUrl}**\n\n` +
|
|
278
|
+
`- **ID:** ${user.id}\n` +
|
|
279
|
+
`- **Display Name:** ${user.name || "Not set"}\n` +
|
|
280
|
+
`- **Username:** ${user.slug || "Not set"}\n` +
|
|
281
|
+
`- **Email:** ${user.email || "Not set"}\n` +
|
|
282
|
+
`- **User URL:** ${user.url || "Not set"}\n` +
|
|
283
|
+
`- **Nickname:** ${user.nickname || user.name || "Not set"}\n` +
|
|
284
|
+
`- **Description:** ${user.description || "No description provided"}\n` +
|
|
285
|
+
`- **Locale:** ${user.locale || "Default"}\n` +
|
|
286
|
+
`- **Registration Date:** ${registrationDate}\n` +
|
|
287
|
+
`- **Primary Role:** ${primaryRole}\n` +
|
|
288
|
+
`- **All Roles:** ${allRoles}\n` +
|
|
289
|
+
`- **Total Capabilities:** ${totalCapabilities} capabilities\n` +
|
|
290
|
+
`- **Key Capabilities:** ${userCapabilities || "None"}\n` +
|
|
291
|
+
`- **Profile Link:** ${user.link || `${siteUrl}/wp-admin/profile.php`}`;
|
|
292
|
+
|
|
186
293
|
return content;
|
|
187
294
|
} catch (error) {
|
|
188
295
|
throw new Error(`Failed to get current user: ${getErrorMessage(error)}`);
|
|
189
296
|
}
|
|
190
297
|
}
|
|
191
298
|
|
|
192
|
-
public async handleCreateUser(
|
|
193
|
-
client: WordPressClient,
|
|
194
|
-
params: CreateUserRequest,
|
|
195
|
-
): Promise<any> {
|
|
299
|
+
public async handleCreateUser(client: WordPressClient, params: CreateUserRequest): Promise<any> {
|
|
196
300
|
try {
|
|
197
301
|
const user = await client.createUser(params);
|
|
198
302
|
return `✅ User "${user.name}" created successfully with ID: ${user.id}.`;
|
|
@@ -201,10 +305,7 @@ export class UserTools {
|
|
|
201
305
|
}
|
|
202
306
|
}
|
|
203
307
|
|
|
204
|
-
public async handleUpdateUser(
|
|
205
|
-
client: WordPressClient,
|
|
206
|
-
params: UpdateUserRequest & { id: number },
|
|
207
|
-
): Promise<any> {
|
|
308
|
+
public async handleUpdateUser(client: WordPressClient, params: UpdateUserRequest & { id: number }): Promise<any> {
|
|
208
309
|
try {
|
|
209
310
|
const user = await client.updateUser(params);
|
|
210
311
|
return `✅ User ${user.id} updated successfully.`;
|
|
@@ -213,10 +314,7 @@ export class UserTools {
|
|
|
213
314
|
}
|
|
214
315
|
}
|
|
215
316
|
|
|
216
|
-
public async handleDeleteUser(
|
|
217
|
-
client: WordPressClient,
|
|
218
|
-
params: { id: number; reassign?: number },
|
|
219
|
-
): Promise<any> {
|
|
317
|
+
public async handleDeleteUser(client: WordPressClient, params: { id: number; reassign?: number }): Promise<any> {
|
|
220
318
|
try {
|
|
221
319
|
await client.deleteUser(params.id, params.reassign);
|
|
222
320
|
let content = `✅ User ${params.id} has been deleted.`;
|