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,246 @@
|
|
|
1
|
+
import { WordPressClient } from "../client/api.js";
|
|
2
|
+
import {
|
|
3
|
+
CreatePostRequest,
|
|
4
|
+
PostQueryParams,
|
|
5
|
+
UpdatePostRequest,
|
|
6
|
+
} from "../types/wordpress.js";
|
|
7
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Provides tools for managing pages on a WordPress site.
|
|
11
|
+
* This class encapsulates tool definitions and their corresponding handlers.
|
|
12
|
+
*/
|
|
13
|
+
export class PageTools {
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the list of page management tools.
|
|
16
|
+
* @returns An array of MCPTool definitions.
|
|
17
|
+
*/
|
|
18
|
+
public getTools(): any[] {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
name: "wp_list_pages",
|
|
22
|
+
description: "Lists pages from a WordPress site, with filters.",
|
|
23
|
+
parameters: [
|
|
24
|
+
{
|
|
25
|
+
name: "per_page",
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Number of items to return per page (max 100).",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "search",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Limit results to those matching a search term.",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "status",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Filter by page status.",
|
|
38
|
+
enum: ["publish", "future", "draft", "pending", "private"],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
handler: this.handleListPages.bind(this),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "wp_get_page",
|
|
45
|
+
description: "Retrieves a single page by its ID.",
|
|
46
|
+
parameters: [
|
|
47
|
+
{
|
|
48
|
+
name: "id",
|
|
49
|
+
type: "number",
|
|
50
|
+
required: true,
|
|
51
|
+
description: "The unique identifier for the page.",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
handler: this.handleGetPage.bind(this),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "wp_create_page",
|
|
58
|
+
description: "Creates a new page.",
|
|
59
|
+
parameters: [
|
|
60
|
+
{
|
|
61
|
+
name: "title",
|
|
62
|
+
type: "string",
|
|
63
|
+
required: true,
|
|
64
|
+
description: "The title for the page.",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "content",
|
|
68
|
+
type: "string",
|
|
69
|
+
description: "The content for the page, in HTML format.",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "status",
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "The publishing status for the page.",
|
|
75
|
+
enum: ["publish", "draft", "pending", "private"],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
handler: this.handleCreatePage.bind(this),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "wp_update_page",
|
|
82
|
+
description: "Updates an existing page.",
|
|
83
|
+
parameters: [
|
|
84
|
+
{
|
|
85
|
+
name: "id",
|
|
86
|
+
type: "number",
|
|
87
|
+
required: true,
|
|
88
|
+
description: "The ID of the page to update.",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "title",
|
|
92
|
+
type: "string",
|
|
93
|
+
description: "The new title for the page.",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "content",
|
|
97
|
+
type: "string",
|
|
98
|
+
description: "The new content for the page, in HTML format.",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "status",
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "The new status for the page.",
|
|
104
|
+
enum: ["publish", "draft", "pending", "private"],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
handler: this.handleUpdatePage.bind(this),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "wp_delete_page",
|
|
111
|
+
description: "Deletes a page.",
|
|
112
|
+
parameters: [
|
|
113
|
+
{
|
|
114
|
+
name: "id",
|
|
115
|
+
type: "number",
|
|
116
|
+
required: true,
|
|
117
|
+
description: "The ID of the page to delete.",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "force",
|
|
121
|
+
type: "boolean",
|
|
122
|
+
description:
|
|
123
|
+
"If true, permanently delete. If false, move to trash. Defaults to false.",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
handler: this.handleDeletePage.bind(this),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "wp_get_page_revisions",
|
|
130
|
+
description: "Retrieves revisions for a specific page.",
|
|
131
|
+
parameters: [
|
|
132
|
+
{
|
|
133
|
+
name: "id",
|
|
134
|
+
type: "number",
|
|
135
|
+
required: true,
|
|
136
|
+
description: "The ID of the page to get revisions for.",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
handler: this.handleGetPageRevisions.bind(this),
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public async handleListPages(
|
|
145
|
+
client: WordPressClient,
|
|
146
|
+
params: PostQueryParams,
|
|
147
|
+
): Promise<any> {
|
|
148
|
+
try {
|
|
149
|
+
const pages = await client.getPages(params);
|
|
150
|
+
if (pages.length === 0) {
|
|
151
|
+
return "No pages found matching the criteria.";
|
|
152
|
+
}
|
|
153
|
+
const content =
|
|
154
|
+
`Found ${pages.length} pages:\n\n` +
|
|
155
|
+
pages
|
|
156
|
+
.map(
|
|
157
|
+
(p) =>
|
|
158
|
+
`- ID ${p.id}: **${p.title.rendered}** (${p.status})\n Link: ${p.link}`,
|
|
159
|
+
)
|
|
160
|
+
.join("\n");
|
|
161
|
+
return content;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw new Error(`Failed to list pages: ${getErrorMessage(error)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async handleGetPage(
|
|
168
|
+
client: WordPressClient,
|
|
169
|
+
params: { id: number },
|
|
170
|
+
): Promise<any> {
|
|
171
|
+
try {
|
|
172
|
+
const page = await client.getPage(params.id);
|
|
173
|
+
const content =
|
|
174
|
+
`**Page Details (ID: ${page.id})**\n\n` +
|
|
175
|
+
`- **Title:** ${page.title.rendered}\n` +
|
|
176
|
+
`- **Status:** ${page.status}\n` +
|
|
177
|
+
`- **Link:** ${page.link}\n` +
|
|
178
|
+
`- **Date:** ${new Date(page.date).toLocaleString()}`;
|
|
179
|
+
return content;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
throw new Error(`Failed to get page: ${getErrorMessage(error)}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public async handleCreatePage(
|
|
186
|
+
client: WordPressClient,
|
|
187
|
+
params: CreatePostRequest,
|
|
188
|
+
): Promise<any> {
|
|
189
|
+
try {
|
|
190
|
+
const page = await client.createPage(params);
|
|
191
|
+
return `✅ Page created successfully!\n- ID: ${page.id}\n- Title: ${page.title.rendered}\n- Link: ${page.link}`;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error(`Failed to create page: ${getErrorMessage(error)}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public async handleUpdatePage(
|
|
198
|
+
client: WordPressClient,
|
|
199
|
+
params: UpdatePostRequest & { id: number },
|
|
200
|
+
): Promise<any> {
|
|
201
|
+
try {
|
|
202
|
+
const page = await client.updatePage(params);
|
|
203
|
+
return `✅ Page ${page.id} updated successfully.`;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
throw new Error(`Failed to update page: ${getErrorMessage(error)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public async handleDeletePage(
|
|
210
|
+
client: WordPressClient,
|
|
211
|
+
params: { id: number; force?: boolean },
|
|
212
|
+
): Promise<any> {
|
|
213
|
+
try {
|
|
214
|
+
await client.deletePage(params.id, params.force);
|
|
215
|
+
const action = params.force ? "permanently deleted" : "moved to trash";
|
|
216
|
+
return `✅ Page ${params.id} has been ${action}.`;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
throw new Error(`Failed to delete page: ${getErrorMessage(error)}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public async handleGetPageRevisions(
|
|
223
|
+
client: WordPressClient,
|
|
224
|
+
params: { id: number },
|
|
225
|
+
): Promise<any> {
|
|
226
|
+
try {
|
|
227
|
+
const revisions = await client.getPageRevisions(params.id);
|
|
228
|
+
if (revisions.length === 0) {
|
|
229
|
+
return `No revisions found for page ${params.id}.`;
|
|
230
|
+
}
|
|
231
|
+
const content =
|
|
232
|
+
`Found ${revisions.length} revisions for page ${params.id}:\n\n` +
|
|
233
|
+
revisions
|
|
234
|
+
.map(
|
|
235
|
+
(r) =>
|
|
236
|
+
`- Revision by user ID ${r.author} at ${new Date(r.modified).toLocaleString()}`,
|
|
237
|
+
)
|
|
238
|
+
.join("\n");
|
|
239
|
+
return content;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
throw new Error(`Failed to get page revisions: ${getErrorMessage(error)}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export default PageTools;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { WordPressClient } from "../client/api.js";
|
|
2
|
+
import {
|
|
3
|
+
CreatePostRequest,
|
|
4
|
+
PostQueryParams,
|
|
5
|
+
UpdatePostRequest,
|
|
6
|
+
} from "../types/wordpress.js";
|
|
7
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Provides tools for managing posts on a WordPress site.
|
|
11
|
+
* This class encapsulates tool definitions and their corresponding handlers.
|
|
12
|
+
*/
|
|
13
|
+
export class PostTools {
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the list of post management tools.
|
|
16
|
+
* @returns An array of MCPTool definitions.
|
|
17
|
+
*/
|
|
18
|
+
public getTools(): any[] {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
name: "wp_list_posts",
|
|
22
|
+
description: "Lists posts from a WordPress site, with filters.",
|
|
23
|
+
parameters: [
|
|
24
|
+
{
|
|
25
|
+
name: "per_page",
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Number of items to return per page (max 100).",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "search",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Limit results to those matching a search term.",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "status",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Filter by post status.",
|
|
38
|
+
enum: ["publish", "future", "draft", "pending", "private"],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "categories",
|
|
42
|
+
type: "array",
|
|
43
|
+
items: { type: "number" },
|
|
44
|
+
description: "Limit results to posts in specific category IDs.",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "tags",
|
|
48
|
+
type: "array",
|
|
49
|
+
items: { type: "number" },
|
|
50
|
+
description: "Limit results to posts with specific tag IDs.",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
handler: this.handleListPosts.bind(this),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "wp_get_post",
|
|
57
|
+
description: "Retrieves a single post by its ID.",
|
|
58
|
+
parameters: [
|
|
59
|
+
{
|
|
60
|
+
name: "id",
|
|
61
|
+
type: "number",
|
|
62
|
+
required: true,
|
|
63
|
+
description: "The unique identifier for the post.",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
handler: this.handleGetPost.bind(this),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "wp_create_post",
|
|
70
|
+
description: "Creates a new post.",
|
|
71
|
+
parameters: [
|
|
72
|
+
{
|
|
73
|
+
name: "title",
|
|
74
|
+
type: "string",
|
|
75
|
+
required: true,
|
|
76
|
+
description: "The title for the post.",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "content",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "The content for the post, in HTML format.",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "status",
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "The publishing status for the post.",
|
|
87
|
+
enum: ["publish", "draft", "pending", "private"],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "excerpt",
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "The excerpt for the post.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "categories",
|
|
96
|
+
type: "array",
|
|
97
|
+
items: { type: "number" },
|
|
98
|
+
description: "An array of category IDs to assign to the post.",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "tags",
|
|
102
|
+
type: "array",
|
|
103
|
+
items: { type: "number" },
|
|
104
|
+
description: "An array of tag IDs to assign to the post.",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
handler: this.handleCreatePost.bind(this),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "wp_update_post",
|
|
111
|
+
description: "Updates an existing post.",
|
|
112
|
+
parameters: [
|
|
113
|
+
{
|
|
114
|
+
name: "id",
|
|
115
|
+
type: "number",
|
|
116
|
+
required: true,
|
|
117
|
+
description: "The ID of the post to update.",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "title",
|
|
121
|
+
type: "string",
|
|
122
|
+
description: "The new title for the post.",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "content",
|
|
126
|
+
type: "string",
|
|
127
|
+
description: "The new content for the post, in HTML format.",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "status",
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "The new status for the post.",
|
|
133
|
+
enum: ["publish", "draft", "pending", "private"],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
handler: this.handleUpdatePost.bind(this),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "wp_delete_post",
|
|
140
|
+
description: "Deletes a post.",
|
|
141
|
+
parameters: [
|
|
142
|
+
{
|
|
143
|
+
name: "id",
|
|
144
|
+
type: "number",
|
|
145
|
+
required: true,
|
|
146
|
+
description: "The ID of the post to delete.",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "force",
|
|
150
|
+
type: "boolean",
|
|
151
|
+
description:
|
|
152
|
+
"If true, permanently delete. If false, move to trash. Defaults to false.",
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
handler: this.handleDeletePost.bind(this),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "wp_get_post_revisions",
|
|
159
|
+
description: "Retrieves revisions for a specific post.",
|
|
160
|
+
parameters: [
|
|
161
|
+
{
|
|
162
|
+
name: "id",
|
|
163
|
+
type: "number",
|
|
164
|
+
required: true,
|
|
165
|
+
description: "The ID of the post to get revisions for.",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
handler: this.handleGetPostRevisions.bind(this),
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public async handleListPosts(
|
|
174
|
+
client: WordPressClient,
|
|
175
|
+
params: PostQueryParams,
|
|
176
|
+
): Promise<any> {
|
|
177
|
+
try {
|
|
178
|
+
const posts = await client.getPosts(params);
|
|
179
|
+
if (posts.length === 0) {
|
|
180
|
+
return "No posts found matching the criteria.";
|
|
181
|
+
}
|
|
182
|
+
const content =
|
|
183
|
+
`Found ${posts.length} posts:\n\n` +
|
|
184
|
+
posts
|
|
185
|
+
.map(
|
|
186
|
+
(p) =>
|
|
187
|
+
`- ID ${p.id}: **${p.title.rendered}** (${p.status})\n Link: ${p.link}`,
|
|
188
|
+
)
|
|
189
|
+
.join("\n");
|
|
190
|
+
return content;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new Error(`Failed to list posts: ${getErrorMessage(error)}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public async handleGetPost(
|
|
197
|
+
client: WordPressClient,
|
|
198
|
+
params: { id: number },
|
|
199
|
+
): Promise<any> {
|
|
200
|
+
try {
|
|
201
|
+
const post = await client.getPost(params.id);
|
|
202
|
+
const content =
|
|
203
|
+
`**Post Details (ID: ${post.id})**\n\n` +
|
|
204
|
+
`- **Title:** ${post.title.rendered}\n` +
|
|
205
|
+
`- **Status:** ${post.status}\n` +
|
|
206
|
+
`- **Link:** ${post.link}\n` +
|
|
207
|
+
`- **Date:** ${new Date(post.date).toLocaleString()}`;
|
|
208
|
+
return content;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new Error(`Failed to get post: ${getErrorMessage(error)}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public async handleCreatePost(
|
|
215
|
+
client: WordPressClient,
|
|
216
|
+
params: CreatePostRequest,
|
|
217
|
+
): Promise<any> {
|
|
218
|
+
try {
|
|
219
|
+
const post = await client.createPost(params);
|
|
220
|
+
return `✅ Post created successfully!\n- ID: ${post.id}\n- Title: ${post.title.rendered}\n- Link: ${post.link}`;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
throw new Error(`Failed to create post: ${getErrorMessage(error)}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public async handleUpdatePost(
|
|
227
|
+
client: WordPressClient,
|
|
228
|
+
params: UpdatePostRequest & { id: number },
|
|
229
|
+
): Promise<any> {
|
|
230
|
+
try {
|
|
231
|
+
const post = await client.updatePost(params);
|
|
232
|
+
return `✅ Post ${post.id} updated successfully.`;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
throw new Error(`Failed to update post: ${getErrorMessage(error)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public async handleDeletePost(
|
|
239
|
+
client: WordPressClient,
|
|
240
|
+
params: { id: number; force?: boolean },
|
|
241
|
+
): Promise<any> {
|
|
242
|
+
try {
|
|
243
|
+
await client.deletePost(params.id, params.force);
|
|
244
|
+
const action = params.force ? "permanently deleted" : "moved to trash";
|
|
245
|
+
return `✅ Post ${params.id} has been ${action}.`;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
throw new Error(`Failed to delete post: ${getErrorMessage(error)}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public async handleGetPostRevisions(
|
|
252
|
+
client: WordPressClient,
|
|
253
|
+
params: { id: number },
|
|
254
|
+
): Promise<any> {
|
|
255
|
+
try {
|
|
256
|
+
const revisions = await client.getPostRevisions(params.id);
|
|
257
|
+
if (revisions.length === 0) {
|
|
258
|
+
return `No revisions found for post ${params.id}.`;
|
|
259
|
+
}
|
|
260
|
+
const content =
|
|
261
|
+
`Found ${revisions.length} revisions for post ${params.id}:\n\n` +
|
|
262
|
+
revisions
|
|
263
|
+
.map(
|
|
264
|
+
(r) =>
|
|
265
|
+
`- Revision by user ID ${r.author} at ${new Date(
|
|
266
|
+
r.modified,
|
|
267
|
+
).toLocaleString()}`,
|
|
268
|
+
)
|
|
269
|
+
.join("\n");
|
|
270
|
+
return content;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new Error(`Failed to get post revisions: ${getErrorMessage(error)}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default PostTools;
|