mcp-wordpress 1.1.2
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.md +568 -0
- package/bin/mcp-wordpress.js +12 -0
- package/bin/setup.js +302 -0
- package/bin/status.js +359 -0
- package/dist/client/WordPressClient.d.ts +81 -0
- package/dist/client/WordPressClient.d.ts.map +1 -0
- package/dist/client/WordPressClient.js +354 -0
- package/dist/client/WordPressClient.js.map +1 -0
- package/dist/client/api.d.ts +140 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +727 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/auth.d.ts +121 -0
- package/dist/client/auth.d.ts.map +1 -0
- package/dist/client/auth.js +430 -0
- package/dist/client/auth.js.map +1 -0
- package/dist/client/managers/AuthenticationManager.d.ts +39 -0
- package/dist/client/managers/AuthenticationManager.d.ts.map +1 -0
- package/dist/client/managers/AuthenticationManager.js +159 -0
- package/dist/client/managers/AuthenticationManager.js.map +1 -0
- package/dist/client/managers/BaseManager.d.ts +22 -0
- package/dist/client/managers/BaseManager.d.ts.map +1 -0
- package/dist/client/managers/BaseManager.js +47 -0
- package/dist/client/managers/BaseManager.js.map +1 -0
- package/dist/client/managers/RequestManager.d.ts +45 -0
- package/dist/client/managers/RequestManager.d.ts.map +1 -0
- package/dist/client/managers/RequestManager.js +161 -0
- package/dist/client/managers/RequestManager.js.map +1 -0
- package/dist/client/managers/index.d.ts +8 -0
- package/dist/client/managers/index.d.ts.map +1 -0
- package/dist/client/managers/index.js +8 -0
- package/dist/client/managers/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +264 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/auth.d.ts +44 -0
- package/dist/tools/auth.d.ts.map +1 -0
- package/dist/tools/auth.js +126 -0
- package/dist/tools/auth.js.map +1 -0
- package/dist/tools/base.d.ts +37 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +60 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/comments.d.ts +33 -0
- package/dist/tools/comments.d.ts.map +1 -0
- package/dist/tools/comments.js +228 -0
- package/dist/tools/comments.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/media.d.ts +29 -0
- package/dist/tools/media.d.ts.map +1 -0
- package/dist/tools/media.js +208 -0
- package/dist/tools/media.js.map +1 -0
- package/dist/tools/pages.d.ts +30 -0
- package/dist/tools/pages.d.ts.map +1 -0
- package/dist/tools/pages.js +211 -0
- package/dist/tools/pages.js.map +1 -0
- package/dist/tools/posts.d.ts +30 -0
- package/dist/tools/posts.d.ts.map +1 -0
- package/dist/tools/posts.js +240 -0
- package/dist/tools/posts.js.map +1 -0
- package/dist/tools/site.d.ts +31 -0
- package/dist/tools/site.d.ts.map +1 -0
- package/dist/tools/site.js +192 -0
- package/dist/tools/site.js.map +1 -0
- package/dist/tools/taxonomies.d.ts +37 -0
- package/dist/tools/taxonomies.d.ts.map +1 -0
- package/dist/tools/taxonomies.js +280 -0
- package/dist/tools/taxonomies.js.map +1 -0
- package/dist/tools/users.d.ts +28 -0
- package/dist/tools/users.d.ts.map +1 -0
- package/dist/tools/users.js +201 -0
- package/dist/tools/users.js.map +1 -0
- package/dist/types/client.d.ts +215 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +72 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/index.d.ts +157 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mcp.d.ts +178 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +7 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/wordpress.d.ts +443 -0
- package/dist/types/wordpress.d.ts.map +1 -0
- package/dist/types/wordpress.js +7 -0
- package/dist/types/wordpress.js.map +1 -0
- package/dist/utils/debug.d.ts +63 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +195 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/error.d.ts +19 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +71 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/toolWrapper.d.ts +36 -0
- package/dist/utils/toolWrapper.d.ts.map +1 -0
- package/dist/utils/toolWrapper.js +90 -0
- package/dist/utils/toolWrapper.js.map +1 -0
- package/package.json +115 -0
- package/src/client/api.ts +1043 -0
- package/src/client/auth.ts +527 -0
- package/src/client/managers/AuthenticationManager.ts +190 -0
- package/src/client/managers/BaseManager.ts +73 -0
- package/src/client/managers/RequestManager.ts +214 -0
- package/src/client/managers/index.ts +8 -0
- package/src/index.ts +337 -0
- package/src/server.ts +7 -0
- package/src/tools/auth.ts +153 -0
- package/src/tools/comments.ts +263 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/media.ts +240 -0
- package/src/tools/pages.ts +246 -0
- package/src/tools/posts.ts +277 -0
- package/src/tools/site.ts +227 -0
- package/src/tools/taxonomies.ts +322 -0
- package/src/tools/users.ts +233 -0
- package/src/types/client.ts +304 -0
- package/src/types/index.ts +207 -0
- package/src/types/mcp.ts +247 -0
- package/src/types/wordpress.ts +491 -0
- package/src/utils/debug.ts +258 -0
- package/src/utils/error.ts +88 -0
- package/src/utils/toolWrapper.ts +105 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { WordPressClient } from "../client/api.js";
|
|
2
|
+
import {
|
|
3
|
+
WordPressApplicationPassword,
|
|
4
|
+
} from "../types/wordpress.js";
|
|
5
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Provides tools for managing general site settings and operations on a WordPress site.
|
|
9
|
+
* This class encapsulates tool definitions and their corresponding handlers.
|
|
10
|
+
*/
|
|
11
|
+
export class SiteTools {
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the list of site management tools.
|
|
14
|
+
* @returns An array of MCPTool definitions.
|
|
15
|
+
*/
|
|
16
|
+
public getTools(): any[] {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
name: "wp_get_site_settings",
|
|
20
|
+
description: "Retrieves the general settings for a WordPress site.",
|
|
21
|
+
parameters: [],
|
|
22
|
+
handler: this.handleGetSiteSettings.bind(this),
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "wp_update_site_settings",
|
|
26
|
+
description:
|
|
27
|
+
"Updates one or more general settings for a WordPress site.",
|
|
28
|
+
parameters: [
|
|
29
|
+
{
|
|
30
|
+
name: "title",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "The title of the site.",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "description",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "The tagline or description of the site.",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "timezone",
|
|
41
|
+
type: "string",
|
|
42
|
+
description:
|
|
43
|
+
"A city in the same timezone, e.g., 'America/New_York'.",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
handler: this.handleUpdateSiteSettings.bind(this),
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "wp_search_site",
|
|
50
|
+
description: "Performs a site-wide search for content.",
|
|
51
|
+
parameters: [
|
|
52
|
+
{
|
|
53
|
+
name: "term",
|
|
54
|
+
type: "string",
|
|
55
|
+
required: true,
|
|
56
|
+
description: "The search term to look for.",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "type",
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "The type of content to search.",
|
|
62
|
+
enum: ["posts", "pages", "media"],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
handler: this.handleSearchSite.bind(this),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "wp_get_application_passwords",
|
|
69
|
+
description: "Lists application passwords for a specific user.",
|
|
70
|
+
parameters: [
|
|
71
|
+
{
|
|
72
|
+
name: "user_id",
|
|
73
|
+
type: "number",
|
|
74
|
+
required: true,
|
|
75
|
+
description: "The ID of the user to get application passwords for.",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
handler: this.handleGetApplicationPasswords.bind(this),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "wp_create_application_password",
|
|
82
|
+
description: "Creates a new application password for a user.",
|
|
83
|
+
parameters: [
|
|
84
|
+
{
|
|
85
|
+
name: "user_id",
|
|
86
|
+
type: "number",
|
|
87
|
+
required: true,
|
|
88
|
+
description: "The ID of the user to create the password for.",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "app_name",
|
|
92
|
+
type: "string",
|
|
93
|
+
required: true,
|
|
94
|
+
description: "The name of the application this password is for.",
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
handler: this.handleCreateApplicationPassword.bind(this),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "wp_delete_application_password",
|
|
101
|
+
description: "Revokes an existing application password.",
|
|
102
|
+
parameters: [
|
|
103
|
+
{
|
|
104
|
+
name: "user_id",
|
|
105
|
+
type: "number",
|
|
106
|
+
required: true,
|
|
107
|
+
description: "The ID of the user who owns the password.",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "uuid",
|
|
111
|
+
type: "string",
|
|
112
|
+
required: true,
|
|
113
|
+
description: "The UUID of the application password to revoke.",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
handler: this.handleDeleteApplicationPassword.bind(this),
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public async handleGetSiteSettings(
|
|
122
|
+
client: WordPressClient,
|
|
123
|
+
params: any,
|
|
124
|
+
): Promise<any> {
|
|
125
|
+
try {
|
|
126
|
+
const settings = await client.getSiteSettings();
|
|
127
|
+
const content =
|
|
128
|
+
`**Site Settings for ${settings.url}**\n\n` +
|
|
129
|
+
`- **Title:** ${settings.title}\n` +
|
|
130
|
+
`- **Description:** ${settings.description}\n` +
|
|
131
|
+
`- **Timezone:** ${settings.timezone}\n` +
|
|
132
|
+
`- **Language:** ${settings.language}`;
|
|
133
|
+
return content;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(`Failed to get site settings: ${getErrorMessage(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async handleUpdateSiteSettings(
|
|
140
|
+
client: WordPressClient,
|
|
141
|
+
params: any,
|
|
142
|
+
): Promise<any> {
|
|
143
|
+
try {
|
|
144
|
+
const updatedSettings = await client.updateSiteSettings(params);
|
|
145
|
+
return `✅ Site settings updated successfully. New title: ${updatedSettings.title}`;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw new Error(`Failed to update site settings: ${getErrorMessage(error)}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public async handleSearchSite(
|
|
152
|
+
client: WordPressClient,
|
|
153
|
+
params: { term: string; type?: "posts" | "pages" | "media" },
|
|
154
|
+
): Promise<any> {
|
|
155
|
+
try {
|
|
156
|
+
const results = await client.search(params.term, params.type ? [params.type] : undefined);
|
|
157
|
+
if (results.length === 0) {
|
|
158
|
+
return `No results found for "${params.term}".`;
|
|
159
|
+
}
|
|
160
|
+
const content =
|
|
161
|
+
`Found ${results.length} results for "${params.term}":\n\n` +
|
|
162
|
+
results
|
|
163
|
+
.map((r) => `- [${r.type}] **${r.title}**\n Link: ${r.url}`)
|
|
164
|
+
.join("\n");
|
|
165
|
+
return content;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new Error(`Failed to perform search: ${getErrorMessage(error)}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public async handleGetApplicationPasswords(
|
|
172
|
+
client: WordPressClient,
|
|
173
|
+
params: { user_id: number },
|
|
174
|
+
): Promise<any> {
|
|
175
|
+
try {
|
|
176
|
+
const passwords = await client.getApplicationPasswords(params.user_id);
|
|
177
|
+
if (passwords.length === 0) {
|
|
178
|
+
return `No application passwords found for user ID ${params.user_id}.`;
|
|
179
|
+
}
|
|
180
|
+
const content =
|
|
181
|
+
`Found ${passwords.length} application passwords for user ID ${params.user_id}:\n\n` +
|
|
182
|
+
passwords
|
|
183
|
+
.map(
|
|
184
|
+
(p: WordPressApplicationPassword) =>
|
|
185
|
+
`- **${p.name}** (UUID: ${p.uuid})\n Created: ${new Date(p.created).toLocaleDateString()}`,
|
|
186
|
+
)
|
|
187
|
+
.join("\n");
|
|
188
|
+
return content;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new Error(`Failed to get application passwords: ${getErrorMessage(error)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public async handleCreateApplicationPassword(
|
|
195
|
+
client: WordPressClient,
|
|
196
|
+
params: { user_id: number; app_name: string },
|
|
197
|
+
): Promise<any> {
|
|
198
|
+
try {
|
|
199
|
+
const result = await client.createApplicationPassword(
|
|
200
|
+
params.user_id,
|
|
201
|
+
params.app_name,
|
|
202
|
+
);
|
|
203
|
+
const content =
|
|
204
|
+
`✅ **Application password created successfully!**\n\n` +
|
|
205
|
+
`**Name:** ${result.name}\n` +
|
|
206
|
+
`**Password:** \`${result.password}\`\n\n` +
|
|
207
|
+
`**IMPORTANT:** This password is shown only once. Please save it securely.`;
|
|
208
|
+
return content;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new Error(`Failed to create application password: ${getErrorMessage(error)}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public async handleDeleteApplicationPassword(
|
|
215
|
+
client: WordPressClient,
|
|
216
|
+
params: { user_id: number; uuid: string },
|
|
217
|
+
): Promise<any> {
|
|
218
|
+
try {
|
|
219
|
+
await client.deleteApplicationPassword(params.user_id, params.uuid);
|
|
220
|
+
return `✅ Application password with UUID ${params.uuid} has been revoked.`;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
throw new Error(`Failed to delete application password: ${getErrorMessage(error)}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export default SiteTools;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { WordPressClient } from "../client/api.js";
|
|
2
|
+
import {
|
|
3
|
+
CreateCategoryRequest,
|
|
4
|
+
CreateTagRequest,
|
|
5
|
+
UpdateCategoryRequest,
|
|
6
|
+
UpdateTagRequest,
|
|
7
|
+
} from "../types/wordpress.js";
|
|
8
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides tools for managing taxonomies (categories and tags) on a WordPress site.
|
|
12
|
+
* This class encapsulates tool definitions and their corresponding handlers.
|
|
13
|
+
*/
|
|
14
|
+
export class TaxonomyTools {
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the list of taxonomy management tools.
|
|
17
|
+
* @returns An array of MCPTool definitions.
|
|
18
|
+
*/
|
|
19
|
+
public getTools(): any[] {
|
|
20
|
+
return [
|
|
21
|
+
// Categories
|
|
22
|
+
{
|
|
23
|
+
name: "wp_list_categories",
|
|
24
|
+
description: "Lists categories from a WordPress site.",
|
|
25
|
+
parameters: [
|
|
26
|
+
{
|
|
27
|
+
name: "search",
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Limit results to those matching a search term.",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "hide_empty",
|
|
33
|
+
type: "boolean",
|
|
34
|
+
description: "Whether to hide categories with no posts.",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
handler: this.handleListCategories.bind(this),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "wp_get_category",
|
|
41
|
+
description: "Retrieves a single category by its ID.",
|
|
42
|
+
parameters: [
|
|
43
|
+
{
|
|
44
|
+
name: "id",
|
|
45
|
+
type: "number",
|
|
46
|
+
required: true,
|
|
47
|
+
description: "The unique identifier for the category.",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
handler: this.handleGetCategory.bind(this),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "wp_create_category",
|
|
54
|
+
description: "Creates a new category.",
|
|
55
|
+
parameters: [
|
|
56
|
+
{
|
|
57
|
+
name: "name",
|
|
58
|
+
type: "string",
|
|
59
|
+
required: true,
|
|
60
|
+
description: "The name of the category.",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "description",
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "The description for the category.",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
handler: this.handleCreateCategory.bind(this),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "wp_update_category",
|
|
72
|
+
description: "Updates an existing category.",
|
|
73
|
+
parameters: [
|
|
74
|
+
{
|
|
75
|
+
name: "id",
|
|
76
|
+
type: "number",
|
|
77
|
+
required: true,
|
|
78
|
+
description: "The ID of the category to update.",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "name",
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "The new name for the category.",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
handler: this.handleUpdateCategory.bind(this),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "wp_delete_category",
|
|
90
|
+
description: "Deletes a category.",
|
|
91
|
+
parameters: [
|
|
92
|
+
{
|
|
93
|
+
name: "id",
|
|
94
|
+
type: "number",
|
|
95
|
+
required: true,
|
|
96
|
+
description: "The ID of the category to delete.",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
handler: this.handleDeleteCategory.bind(this),
|
|
100
|
+
},
|
|
101
|
+
// Tags
|
|
102
|
+
{
|
|
103
|
+
name: "wp_list_tags",
|
|
104
|
+
description: "Lists tags from a WordPress site.",
|
|
105
|
+
parameters: [
|
|
106
|
+
{
|
|
107
|
+
name: "search",
|
|
108
|
+
type: "string",
|
|
109
|
+
description: "Limit results to those matching a search term.",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
handler: this.handleListTags.bind(this),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "wp_get_tag",
|
|
116
|
+
description: "Retrieves a single tag by its ID.",
|
|
117
|
+
parameters: [
|
|
118
|
+
{
|
|
119
|
+
name: "id",
|
|
120
|
+
type: "number",
|
|
121
|
+
required: true,
|
|
122
|
+
description: "The unique identifier for the tag.",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
handler: this.handleGetTag.bind(this),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "wp_create_tag",
|
|
129
|
+
description: "Creates a new tag.",
|
|
130
|
+
parameters: [
|
|
131
|
+
{
|
|
132
|
+
name: "name",
|
|
133
|
+
type: "string",
|
|
134
|
+
required: true,
|
|
135
|
+
description: "The name of the tag.",
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
handler: this.handleCreateTag.bind(this),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "wp_update_tag",
|
|
142
|
+
description: "Updates an existing tag.",
|
|
143
|
+
parameters: [
|
|
144
|
+
{
|
|
145
|
+
name: "id",
|
|
146
|
+
type: "number",
|
|
147
|
+
required: true,
|
|
148
|
+
description: "The ID of the tag to update.",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "name",
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "The new name for the tag.",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
handler: this.handleUpdateTag.bind(this),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "wp_delete_tag",
|
|
160
|
+
description: "Deletes a tag.",
|
|
161
|
+
parameters: [
|
|
162
|
+
{
|
|
163
|
+
name: "id",
|
|
164
|
+
type: "number",
|
|
165
|
+
required: true,
|
|
166
|
+
description: "The ID of the tag to delete.",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
handler: this.handleDeleteTag.bind(this),
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public async handleListCategories(
|
|
175
|
+
client: WordPressClient,
|
|
176
|
+
params: any,
|
|
177
|
+
): Promise<any> {
|
|
178
|
+
try {
|
|
179
|
+
const categories = await client.getCategories(params);
|
|
180
|
+
if (categories.length === 0) {
|
|
181
|
+
return "No categories found.";
|
|
182
|
+
}
|
|
183
|
+
const content =
|
|
184
|
+
`Found ${categories.length} categories:\n\n` +
|
|
185
|
+
categories
|
|
186
|
+
.map((c) => `- ID ${c.id}: **${c.name}** (Posts: ${c.count})`)
|
|
187
|
+
.join("\n");
|
|
188
|
+
return content;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new Error(`Failed to list categories: ${getErrorMessage(error)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public async handleGetCategory(
|
|
195
|
+
client: WordPressClient,
|
|
196
|
+
params: { id: number },
|
|
197
|
+
): Promise<any> {
|
|
198
|
+
try {
|
|
199
|
+
const category = await client.getCategory(params.id);
|
|
200
|
+
const content =
|
|
201
|
+
`**Category Details (ID: ${category.id})**\n\n` +
|
|
202
|
+
`- **Name:** ${category.name}\n` +
|
|
203
|
+
`- **Slug:** ${category.slug}\n` +
|
|
204
|
+
`- **Description:** ${category.description || "None"}\n` +
|
|
205
|
+
`- **Post Count:** ${category.count}`;
|
|
206
|
+
return content;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
throw new Error(`Failed to get category: ${getErrorMessage(error)}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public async handleCreateCategory(
|
|
213
|
+
client: WordPressClient,
|
|
214
|
+
params: CreateCategoryRequest,
|
|
215
|
+
): Promise<any> {
|
|
216
|
+
try {
|
|
217
|
+
const category = await client.createCategory(params);
|
|
218
|
+
return `✅ Category "${category.name}" created successfully with ID: ${category.id}.`;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw new Error(`Failed to create category: ${getErrorMessage(error)}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public async handleUpdateCategory(
|
|
225
|
+
client: WordPressClient,
|
|
226
|
+
params: UpdateCategoryRequest & { id: number },
|
|
227
|
+
): Promise<any> {
|
|
228
|
+
try {
|
|
229
|
+
const category = await client.updateCategory(params);
|
|
230
|
+
return `✅ Category ${category.id} updated successfully.`;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
throw new Error(`Failed to update category: ${getErrorMessage(error)}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public async handleDeleteCategory(
|
|
237
|
+
client: WordPressClient,
|
|
238
|
+
params: { id: number },
|
|
239
|
+
): Promise<any> {
|
|
240
|
+
try {
|
|
241
|
+
await client.deleteCategory(params.id);
|
|
242
|
+
return `✅ Category ${params.id} has been deleted.`;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
throw new Error(`Failed to delete category: ${getErrorMessage(error)}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public async handleListTags(
|
|
249
|
+
client: WordPressClient,
|
|
250
|
+
params: any,
|
|
251
|
+
): Promise<any> {
|
|
252
|
+
try {
|
|
253
|
+
const tags = await client.getTags(params);
|
|
254
|
+
if (tags.length === 0) {
|
|
255
|
+
return "No tags found.";
|
|
256
|
+
}
|
|
257
|
+
const content =
|
|
258
|
+
`Found ${tags.length} tags:\n\n` +
|
|
259
|
+
tags
|
|
260
|
+
.map((t) => `- ID ${t.id}: **${t.name}** (Posts: ${t.count})`)
|
|
261
|
+
.join("\n");
|
|
262
|
+
return content;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
throw new Error(`Failed to list tags: ${getErrorMessage(error)}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public async handleGetTag(
|
|
269
|
+
client: WordPressClient,
|
|
270
|
+
params: { id: number },
|
|
271
|
+
): Promise<any> {
|
|
272
|
+
try {
|
|
273
|
+
const tag = await client.getTag(params.id);
|
|
274
|
+
const content =
|
|
275
|
+
`**Tag Details (ID: ${tag.id})**\n\n` +
|
|
276
|
+
`- **Name:** ${tag.name}\n` +
|
|
277
|
+
`- **Slug:** ${tag.slug}\n` +
|
|
278
|
+
`- **Post Count:** ${tag.count}`;
|
|
279
|
+
return content;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
throw new Error(`Failed to get tag: ${getErrorMessage(error)}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public async handleCreateTag(
|
|
286
|
+
client: WordPressClient,
|
|
287
|
+
params: CreateTagRequest,
|
|
288
|
+
): Promise<any> {
|
|
289
|
+
try {
|
|
290
|
+
const tag = await client.createTag(params);
|
|
291
|
+
return `✅ Tag "${tag.name}" created successfully with ID: ${tag.id}.`;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
throw new Error(`Failed to create tag: ${getErrorMessage(error)}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public async handleUpdateTag(
|
|
298
|
+
client: WordPressClient,
|
|
299
|
+
params: UpdateTagRequest & { id: number },
|
|
300
|
+
): Promise<any> {
|
|
301
|
+
try {
|
|
302
|
+
const tag = await client.updateTag(params);
|
|
303
|
+
return `✅ Tag ${tag.id} updated successfully.`;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
throw new Error(`Failed to update tag: ${getErrorMessage(error)}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public async handleDeleteTag(
|
|
310
|
+
client: WordPressClient,
|
|
311
|
+
params: { id: number },
|
|
312
|
+
): Promise<any> {
|
|
313
|
+
try {
|
|
314
|
+
await client.deleteTag(params.id);
|
|
315
|
+
return `✅ Tag ${params.id} has been deleted.`;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
throw new Error(`Failed to delete tag: ${getErrorMessage(error)}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export default TaxonomyTools;
|