mcp-wordpress 1.1.2 → 1.1.6
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 +8 -8
- package/bin/mcp-wordpress.js +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +157 -157
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/auth.js +72 -72
- package/dist/client/auth.js.map +1 -1
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.d.ts.map +1 -1
- package/dist/client/managers/AuthenticationManager.js +50 -46
- package/dist/client/managers/AuthenticationManager.js.map +1 -1
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.d.ts.map +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/BaseManager.js.map +1 -1
- package/dist/client/managers/RequestManager.d.ts +2 -2
- package/dist/client/managers/RequestManager.js +15 -15
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -61
- package/dist/index.js.map +1 -1
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.js +31 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.js +79 -79
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.d.ts.map +1 -1
- package/dist/tools/media.js +80 -80
- package/dist/tools/media.js.map +1 -1
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.js +75 -75
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.js +94 -94
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/mcp.d.ts +1 -1
- package/dist/types/mcp.d.ts.map +1 -1
- package/dist/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js +10 -6
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/toolWrapper.js +3 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +208 -0
- package/docs/developer/MAINTENANCE.md +307 -0
- package/docs/developer/MIGRATION_GUIDE.md +172 -0
- package/docs/developer/NPM_AUTH_SETUP.md +142 -0
- package/docs/developer/REFACTORING.md +196 -0
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +126 -0
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +173 -0
- package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +187 -0
- package/package.json +4 -3
- package/src/client/api.ts +229 -229
- package/src/client/auth.ts +135 -136
- package/src/client/managers/AuthenticationManager.ts +148 -105
- package/src/client/managers/BaseManager.ts +15 -12
- package/src/client/managers/RequestManager.ts +17 -17
- package/src/client/managers/index.ts +3 -3
- package/src/index.ts +141 -114
- package/src/server.ts +1 -1
- package/src/tools/auth.ts +36 -36
- package/src/tools/comments.ts +90 -90
- package/src/tools/media.ts +89 -91
- package/src/tools/pages.ts +86 -86
- package/src/tools/posts.ts +106 -106
- package/src/tools/site.ts +71 -71
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/types/mcp.ts +36 -16
- package/src/types/wordpress.ts +1 -1
- package/src/utils/debug.ts +63 -39
- package/src/utils/error.ts +1 -1
- package/src/utils/toolWrapper.ts +4 -4
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
package/src/tools/comments.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { WordPressClient } from
|
|
1
|
+
import { WordPressClient } from '../client/api.js';
|
|
2
2
|
import {
|
|
3
3
|
CommentQueryParams,
|
|
4
4
|
CreateCommentRequest,
|
|
5
|
-
UpdateCommentRequest
|
|
6
|
-
} from
|
|
7
|
-
import { getErrorMessage } from
|
|
5
|
+
UpdateCommentRequest
|
|
6
|
+
} from '../types/wordpress.js';
|
|
7
|
+
import { getErrorMessage } from '../utils/error.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Provides tools for managing comments on a WordPress site.
|
|
@@ -18,155 +18,155 @@ export class CommentTools {
|
|
|
18
18
|
public getTools(): any[] {
|
|
19
19
|
return [
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
21
|
+
name: 'wp_list_comments',
|
|
22
|
+
description: 'Lists comments from a WordPress site, with filters.',
|
|
23
23
|
parameters: [
|
|
24
24
|
{
|
|
25
|
-
name:
|
|
26
|
-
type:
|
|
25
|
+
name: 'post',
|
|
26
|
+
type: 'number',
|
|
27
27
|
description:
|
|
28
|
-
|
|
28
|
+
'Limit results to comments assigned to a specific post ID.'
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
name:
|
|
32
|
-
type:
|
|
33
|
-
description:
|
|
34
|
-
enum: [
|
|
35
|
-
}
|
|
31
|
+
name: 'status',
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Filter by comment status.',
|
|
34
|
+
enum: ['hold', 'approve', 'spam', 'trash']
|
|
35
|
+
}
|
|
36
36
|
],
|
|
37
|
-
handler: this.handleListComments.bind(this)
|
|
37
|
+
handler: this.handleListComments.bind(this)
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
name:
|
|
41
|
-
description:
|
|
40
|
+
name: 'wp_get_comment',
|
|
41
|
+
description: 'Retrieves a single comment by its ID.',
|
|
42
42
|
parameters: [
|
|
43
43
|
{
|
|
44
|
-
name:
|
|
45
|
-
type:
|
|
44
|
+
name: 'id',
|
|
45
|
+
type: 'number',
|
|
46
46
|
required: true,
|
|
47
|
-
description:
|
|
48
|
-
}
|
|
47
|
+
description: 'The unique identifier for the comment.'
|
|
48
|
+
}
|
|
49
49
|
],
|
|
50
|
-
handler: this.handleGetComment.bind(this)
|
|
50
|
+
handler: this.handleGetComment.bind(this)
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
name:
|
|
54
|
-
description:
|
|
53
|
+
name: 'wp_create_comment',
|
|
54
|
+
description: 'Creates a new comment on a post.',
|
|
55
55
|
parameters: [
|
|
56
56
|
{
|
|
57
|
-
name:
|
|
58
|
-
type:
|
|
57
|
+
name: 'post',
|
|
58
|
+
type: 'number',
|
|
59
59
|
required: true,
|
|
60
|
-
description:
|
|
60
|
+
description: 'The ID of the post to comment on.'
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
name:
|
|
64
|
-
type:
|
|
63
|
+
name: 'content',
|
|
64
|
+
type: 'string',
|
|
65
65
|
required: true,
|
|
66
|
-
description:
|
|
66
|
+
description: 'The content of the comment.'
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
name:
|
|
70
|
-
type:
|
|
71
|
-
description:
|
|
69
|
+
name: 'author_name',
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'The name of the comment author.'
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
|
-
name:
|
|
75
|
-
type:
|
|
76
|
-
description:
|
|
77
|
-
}
|
|
74
|
+
name: 'author_email',
|
|
75
|
+
type: 'string',
|
|
76
|
+
description: 'The email of the comment author.'
|
|
77
|
+
}
|
|
78
78
|
],
|
|
79
|
-
handler: this.handleCreateComment.bind(this)
|
|
79
|
+
handler: this.handleCreateComment.bind(this)
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
name:
|
|
83
|
-
description:
|
|
82
|
+
name: 'wp_update_comment',
|
|
83
|
+
description: 'Updates an existing comment.',
|
|
84
84
|
parameters: [
|
|
85
85
|
{
|
|
86
|
-
name:
|
|
87
|
-
type:
|
|
86
|
+
name: 'id',
|
|
87
|
+
type: 'number',
|
|
88
88
|
required: true,
|
|
89
|
-
description:
|
|
89
|
+
description: 'The ID of the comment to update.'
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
name:
|
|
93
|
-
type:
|
|
94
|
-
description:
|
|
92
|
+
name: 'content',
|
|
93
|
+
type: 'string',
|
|
94
|
+
description: 'The updated content for the comment.'
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
name:
|
|
98
|
-
type:
|
|
99
|
-
description:
|
|
100
|
-
enum: [
|
|
101
|
-
}
|
|
97
|
+
name: 'status',
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'The new status for the comment.',
|
|
100
|
+
enum: ['hold', 'approve', 'spam', 'trash']
|
|
101
|
+
}
|
|
102
102
|
],
|
|
103
|
-
handler: this.handleUpdateComment.bind(this)
|
|
103
|
+
handler: this.handleUpdateComment.bind(this)
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
|
-
name:
|
|
107
|
-
description:
|
|
106
|
+
name: 'wp_delete_comment',
|
|
107
|
+
description: 'Deletes a comment.',
|
|
108
108
|
parameters: [
|
|
109
109
|
{
|
|
110
|
-
name:
|
|
111
|
-
type:
|
|
110
|
+
name: 'id',
|
|
111
|
+
type: 'number',
|
|
112
112
|
required: true,
|
|
113
|
-
description:
|
|
113
|
+
description: 'The ID of the comment to delete.'
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
name:
|
|
117
|
-
type:
|
|
116
|
+
name: 'force',
|
|
117
|
+
type: 'boolean',
|
|
118
118
|
description:
|
|
119
|
-
|
|
120
|
-
}
|
|
119
|
+
'If true, the comment will be permanently deleted. Defaults to false (moved to trash).'
|
|
120
|
+
}
|
|
121
121
|
],
|
|
122
|
-
handler: this.handleDeleteComment.bind(this)
|
|
122
|
+
handler: this.handleDeleteComment.bind(this)
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
|
-
name:
|
|
126
|
-
description:
|
|
125
|
+
name: 'wp_approve_comment',
|
|
126
|
+
description: 'Approves a pending comment.',
|
|
127
127
|
parameters: [
|
|
128
128
|
{
|
|
129
|
-
name:
|
|
130
|
-
type:
|
|
129
|
+
name: 'id',
|
|
130
|
+
type: 'number',
|
|
131
131
|
required: true,
|
|
132
|
-
description:
|
|
133
|
-
}
|
|
132
|
+
description: 'The ID of the comment to approve.'
|
|
133
|
+
}
|
|
134
134
|
],
|
|
135
|
-
handler: this.handleApproveComment.bind(this)
|
|
135
|
+
handler: this.handleApproveComment.bind(this)
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
name:
|
|
139
|
-
description:
|
|
138
|
+
name: 'wp_spam_comment',
|
|
139
|
+
description: 'Marks a comment as spam.',
|
|
140
140
|
parameters: [
|
|
141
141
|
{
|
|
142
|
-
name:
|
|
143
|
-
type:
|
|
142
|
+
name: 'id',
|
|
143
|
+
type: 'number',
|
|
144
144
|
required: true,
|
|
145
|
-
description:
|
|
146
|
-
}
|
|
145
|
+
description: 'The ID of the comment to mark as spam.'
|
|
146
|
+
}
|
|
147
147
|
],
|
|
148
|
-
handler: this.handleSpamComment.bind(this)
|
|
149
|
-
}
|
|
148
|
+
handler: this.handleSpamComment.bind(this)
|
|
149
|
+
}
|
|
150
150
|
];
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
public async handleListComments(
|
|
154
154
|
client: WordPressClient,
|
|
155
|
-
params: CommentQueryParams
|
|
155
|
+
params: CommentQueryParams
|
|
156
156
|
): Promise<any> {
|
|
157
157
|
try {
|
|
158
158
|
const comments = await client.getComments(params);
|
|
159
159
|
if (comments.length === 0) {
|
|
160
|
-
return
|
|
160
|
+
return 'No comments found matching the criteria.';
|
|
161
161
|
}
|
|
162
162
|
const content =
|
|
163
163
|
`Found ${comments.length} comments:\n\n` +
|
|
164
164
|
comments
|
|
165
165
|
.map(
|
|
166
166
|
(c) =>
|
|
167
|
-
`- ID ${c.id}: By **${c.author_name}** on Post ${c.post} (${c.status})\n > ${c.content.rendered.substring(0, 100)}
|
|
167
|
+
`- ID ${c.id}: By **${c.author_name}** on Post ${c.post} (${c.status})\n > ${c.content.rendered.substring(0, 100)}...`
|
|
168
168
|
)
|
|
169
|
-
.join(
|
|
169
|
+
.join('\n');
|
|
170
170
|
return content;
|
|
171
171
|
} catch (error) {
|
|
172
172
|
throw new Error(`Failed to list comments: ${getErrorMessage(error)}`);
|
|
@@ -175,7 +175,7 @@ export class CommentTools {
|
|
|
175
175
|
|
|
176
176
|
public async handleGetComment(
|
|
177
177
|
client: WordPressClient,
|
|
178
|
-
params: { id: number }
|
|
178
|
+
params: { id: number }
|
|
179
179
|
): Promise<any> {
|
|
180
180
|
try {
|
|
181
181
|
const comment = await client.getComment(params.id);
|
|
@@ -194,7 +194,7 @@ export class CommentTools {
|
|
|
194
194
|
|
|
195
195
|
public async handleCreateComment(
|
|
196
196
|
client: WordPressClient,
|
|
197
|
-
params: CreateCommentRequest
|
|
197
|
+
params: CreateCommentRequest
|
|
198
198
|
): Promise<any> {
|
|
199
199
|
try {
|
|
200
200
|
const comment = await client.createComment(params);
|
|
@@ -206,7 +206,7 @@ export class CommentTools {
|
|
|
206
206
|
|
|
207
207
|
public async handleUpdateComment(
|
|
208
208
|
client: WordPressClient,
|
|
209
|
-
params: UpdateCommentRequest & { id: number }
|
|
209
|
+
params: UpdateCommentRequest & { id: number }
|
|
210
210
|
): Promise<any> {
|
|
211
211
|
try {
|
|
212
212
|
const comment = await client.updateComment(params);
|
|
@@ -218,11 +218,11 @@ export class CommentTools {
|
|
|
218
218
|
|
|
219
219
|
public async handleDeleteComment(
|
|
220
220
|
client: WordPressClient,
|
|
221
|
-
params: { id: number; force?: boolean }
|
|
221
|
+
params: { id: number; force?: boolean }
|
|
222
222
|
): Promise<any> {
|
|
223
223
|
try {
|
|
224
224
|
await client.deleteComment(params.id, params.force);
|
|
225
|
-
const action = params.force ?
|
|
225
|
+
const action = params.force ? 'permanently deleted' : 'moved to trash';
|
|
226
226
|
return `✅ Comment ${params.id} has been ${action}.`;
|
|
227
227
|
} catch (error) {
|
|
228
228
|
throw new Error(`Failed to delete comment: ${getErrorMessage(error)}`);
|
|
@@ -231,12 +231,12 @@ export class CommentTools {
|
|
|
231
231
|
|
|
232
232
|
public async handleApproveComment(
|
|
233
233
|
client: WordPressClient,
|
|
234
|
-
params: { id: number }
|
|
234
|
+
params: { id: number }
|
|
235
235
|
): Promise<any> {
|
|
236
236
|
try {
|
|
237
237
|
const comment = await client.updateComment({
|
|
238
238
|
id: params.id,
|
|
239
|
-
status:
|
|
239
|
+
status: 'approved'
|
|
240
240
|
});
|
|
241
241
|
return `✅ Comment ${comment.id} has been approved.`;
|
|
242
242
|
} catch (error) {
|
|
@@ -246,12 +246,12 @@ export class CommentTools {
|
|
|
246
246
|
|
|
247
247
|
public async handleSpamComment(
|
|
248
248
|
client: WordPressClient,
|
|
249
|
-
params: { id: number }
|
|
249
|
+
params: { id: number }
|
|
250
250
|
): Promise<any> {
|
|
251
251
|
try {
|
|
252
252
|
const comment = await client.updateComment({
|
|
253
253
|
id: params.id,
|
|
254
|
-
status:
|
|
254
|
+
status: 'spam'
|
|
255
255
|
});
|
|
256
256
|
return `✅ Comment ${comment.id} has been marked as spam.`;
|
|
257
257
|
} catch (error) {
|
package/src/tools/media.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import
|
|
3
|
-
import { WordPressClient } from "../client/api.js";
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import { WordPressClient } from '../client/api.js';
|
|
4
3
|
import {
|
|
5
4
|
MediaQueryParams,
|
|
6
5
|
UpdateMediaRequest,
|
|
7
|
-
UploadMediaRequest
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
import { getErrorMessage } from "../utils/error.js";
|
|
6
|
+
UploadMediaRequest
|
|
7
|
+
} from '../types/wordpress.js';
|
|
8
|
+
import { getErrorMessage } from '../utils/error.js';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* Provides tools for managing media on a WordPress site.
|
|
@@ -21,152 +19,152 @@ export class MediaTools {
|
|
|
21
19
|
public getTools(): any[] {
|
|
22
20
|
return [
|
|
23
21
|
{
|
|
24
|
-
name:
|
|
25
|
-
description:
|
|
22
|
+
name: 'wp_list_media',
|
|
23
|
+
description: 'Lists media items from a WordPress site, with filters.',
|
|
26
24
|
parameters: [
|
|
27
25
|
{
|
|
28
|
-
name:
|
|
29
|
-
type:
|
|
30
|
-
description:
|
|
26
|
+
name: 'per_page',
|
|
27
|
+
type: 'number',
|
|
28
|
+
description: 'Number of items to return per page (max 100).'
|
|
31
29
|
},
|
|
32
30
|
{
|
|
33
|
-
name:
|
|
34
|
-
type:
|
|
35
|
-
description:
|
|
31
|
+
name: 'search',
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Limit results to those matching a search term.'
|
|
36
34
|
},
|
|
37
35
|
{
|
|
38
|
-
name:
|
|
39
|
-
type:
|
|
40
|
-
description:
|
|
41
|
-
enum: [
|
|
42
|
-
}
|
|
36
|
+
name: 'media_type',
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'Limit results to a specific media type.',
|
|
39
|
+
enum: ['image', 'video', 'audio', 'application']
|
|
40
|
+
}
|
|
43
41
|
],
|
|
44
|
-
handler: this.handleListMedia.bind(this)
|
|
42
|
+
handler: this.handleListMedia.bind(this)
|
|
45
43
|
},
|
|
46
44
|
{
|
|
47
|
-
name:
|
|
48
|
-
description:
|
|
45
|
+
name: 'wp_get_media',
|
|
46
|
+
description: 'Retrieves a single media item by its ID.',
|
|
49
47
|
parameters: [
|
|
50
48
|
{
|
|
51
|
-
name:
|
|
52
|
-
type:
|
|
49
|
+
name: 'id',
|
|
50
|
+
type: 'number',
|
|
53
51
|
required: true,
|
|
54
|
-
description:
|
|
55
|
-
}
|
|
52
|
+
description: 'The unique identifier for the media item.'
|
|
53
|
+
}
|
|
56
54
|
],
|
|
57
|
-
handler: this.handleGetMedia.bind(this)
|
|
55
|
+
handler: this.handleGetMedia.bind(this)
|
|
58
56
|
},
|
|
59
57
|
{
|
|
60
|
-
name:
|
|
61
|
-
description:
|
|
58
|
+
name: 'wp_upload_media',
|
|
59
|
+
description: 'Uploads a file to the WordPress media library.',
|
|
62
60
|
parameters: [
|
|
63
61
|
{
|
|
64
|
-
name:
|
|
65
|
-
type:
|
|
62
|
+
name: 'file_path',
|
|
63
|
+
type: 'string',
|
|
66
64
|
required: true,
|
|
67
|
-
description:
|
|
65
|
+
description: 'The local, absolute path to the file to upload.'
|
|
68
66
|
},
|
|
69
67
|
{
|
|
70
|
-
name:
|
|
71
|
-
type:
|
|
72
|
-
description:
|
|
68
|
+
name: 'title',
|
|
69
|
+
type: 'string',
|
|
70
|
+
description: 'The title for the media item.'
|
|
73
71
|
},
|
|
74
72
|
{
|
|
75
|
-
name:
|
|
76
|
-
type:
|
|
73
|
+
name: 'alt_text',
|
|
74
|
+
type: 'string',
|
|
77
75
|
description:
|
|
78
|
-
|
|
76
|
+
'Alternative text for the media item (for accessibility).'
|
|
79
77
|
},
|
|
80
78
|
{
|
|
81
|
-
name:
|
|
82
|
-
type:
|
|
83
|
-
description:
|
|
79
|
+
name: 'caption',
|
|
80
|
+
type: 'string',
|
|
81
|
+
description: 'The caption for the media item.'
|
|
84
82
|
},
|
|
85
83
|
{
|
|
86
|
-
name:
|
|
87
|
-
type:
|
|
88
|
-
description:
|
|
84
|
+
name: 'description',
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'The description for the media item.'
|
|
89
87
|
},
|
|
90
88
|
{
|
|
91
|
-
name:
|
|
92
|
-
type:
|
|
93
|
-
description:
|
|
94
|
-
}
|
|
89
|
+
name: 'post',
|
|
90
|
+
type: 'number',
|
|
91
|
+
description: 'The ID of a post to attach this media to.'
|
|
92
|
+
}
|
|
95
93
|
],
|
|
96
|
-
handler: this.handleUploadMedia.bind(this)
|
|
94
|
+
handler: this.handleUploadMedia.bind(this)
|
|
97
95
|
},
|
|
98
96
|
{
|
|
99
|
-
name:
|
|
100
|
-
description:
|
|
97
|
+
name: 'wp_update_media',
|
|
98
|
+
description: 'Updates the metadata of an existing media item.',
|
|
101
99
|
parameters: [
|
|
102
100
|
{
|
|
103
|
-
name:
|
|
104
|
-
type:
|
|
101
|
+
name: 'id',
|
|
102
|
+
type: 'number',
|
|
105
103
|
required: true,
|
|
106
|
-
description:
|
|
104
|
+
description: 'The ID of the media item to update.'
|
|
107
105
|
},
|
|
108
106
|
{
|
|
109
|
-
name:
|
|
110
|
-
type:
|
|
111
|
-
description:
|
|
107
|
+
name: 'title',
|
|
108
|
+
type: 'string',
|
|
109
|
+
description: 'The new title for the media item.'
|
|
112
110
|
},
|
|
113
111
|
{
|
|
114
|
-
name:
|
|
115
|
-
type:
|
|
116
|
-
description:
|
|
112
|
+
name: 'alt_text',
|
|
113
|
+
type: 'string',
|
|
114
|
+
description: 'The new alternative text.'
|
|
117
115
|
},
|
|
118
116
|
{
|
|
119
|
-
name:
|
|
120
|
-
type:
|
|
121
|
-
description:
|
|
117
|
+
name: 'caption',
|
|
118
|
+
type: 'string',
|
|
119
|
+
description: 'The new caption.'
|
|
122
120
|
},
|
|
123
121
|
{
|
|
124
|
-
name:
|
|
125
|
-
type:
|
|
126
|
-
description:
|
|
127
|
-
}
|
|
122
|
+
name: 'description',
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'The new description.'
|
|
125
|
+
}
|
|
128
126
|
],
|
|
129
|
-
handler: this.handleUpdateMedia.bind(this)
|
|
127
|
+
handler: this.handleUpdateMedia.bind(this)
|
|
130
128
|
},
|
|
131
129
|
{
|
|
132
|
-
name:
|
|
133
|
-
description:
|
|
130
|
+
name: 'wp_delete_media',
|
|
131
|
+
description: 'Deletes a media item.',
|
|
134
132
|
parameters: [
|
|
135
133
|
{
|
|
136
|
-
name:
|
|
137
|
-
type:
|
|
134
|
+
name: 'id',
|
|
135
|
+
type: 'number',
|
|
138
136
|
required: true,
|
|
139
|
-
description:
|
|
137
|
+
description: 'The ID of the media item to delete.'
|
|
140
138
|
},
|
|
141
139
|
{
|
|
142
|
-
name:
|
|
143
|
-
type:
|
|
140
|
+
name: 'force',
|
|
141
|
+
type: 'boolean',
|
|
144
142
|
description:
|
|
145
|
-
|
|
146
|
-
}
|
|
143
|
+
'If true, permanently delete. If false, move to trash. Defaults to false.'
|
|
144
|
+
}
|
|
147
145
|
],
|
|
148
|
-
handler: this.handleDeleteMedia.bind(this)
|
|
149
|
-
}
|
|
146
|
+
handler: this.handleDeleteMedia.bind(this)
|
|
147
|
+
}
|
|
150
148
|
];
|
|
151
149
|
}
|
|
152
150
|
|
|
153
151
|
public async handleListMedia(
|
|
154
152
|
client: WordPressClient,
|
|
155
|
-
params: MediaQueryParams
|
|
153
|
+
params: MediaQueryParams
|
|
156
154
|
): Promise<any> {
|
|
157
155
|
try {
|
|
158
156
|
const media = await client.getMedia(params);
|
|
159
157
|
if (media.length === 0) {
|
|
160
|
-
return
|
|
158
|
+
return 'No media items found matching the criteria.';
|
|
161
159
|
}
|
|
162
160
|
const content =
|
|
163
161
|
`Found ${media.length} media items:\n\n` +
|
|
164
162
|
media
|
|
165
163
|
.map(
|
|
166
164
|
(m) =>
|
|
167
|
-
`- ID ${m.id}: **${m.title.rendered}** (${m.mime_type})\n Link: ${m.source_url}
|
|
165
|
+
`- ID ${m.id}: **${m.title.rendered}** (${m.mime_type})\n Link: ${m.source_url}`
|
|
168
166
|
)
|
|
169
|
-
.join(
|
|
167
|
+
.join('\n');
|
|
170
168
|
return content;
|
|
171
169
|
} catch (error) {
|
|
172
170
|
throw new Error(`Failed to list media: ${getErrorMessage(error)}`);
|
|
@@ -175,7 +173,7 @@ export class MediaTools {
|
|
|
175
173
|
|
|
176
174
|
public async handleGetMedia(
|
|
177
175
|
client: WordPressClient,
|
|
178
|
-
params: { id: number }
|
|
176
|
+
params: { id: number }
|
|
179
177
|
): Promise<any> {
|
|
180
178
|
try {
|
|
181
179
|
const media = await client.getMediaItem(params.id);
|
|
@@ -185,10 +183,10 @@ export class MediaTools {
|
|
|
185
183
|
`- **URL:** ${media.source_url}\n` +
|
|
186
184
|
`- **Type:** ${media.media_type} (${media.mime_type})\n` +
|
|
187
185
|
`- **Date:** ${new Date(media.date).toLocaleString()}\n` +
|
|
188
|
-
(media.alt_text ? `- **Alt Text:** ${media.alt_text}\n` :
|
|
186
|
+
(media.alt_text ? `- **Alt Text:** ${media.alt_text}\n` : '') +
|
|
189
187
|
(media.caption.rendered
|
|
190
188
|
? `- **Caption:** ${media.caption.rendered}\n`
|
|
191
|
-
:
|
|
189
|
+
: '');
|
|
192
190
|
return content;
|
|
193
191
|
} catch (error) {
|
|
194
192
|
throw new Error(`Failed to get media item: ${getErrorMessage(error)}`);
|
|
@@ -197,7 +195,7 @@ export class MediaTools {
|
|
|
197
195
|
|
|
198
196
|
public async handleUploadMedia(
|
|
199
197
|
client: WordPressClient,
|
|
200
|
-
params: UploadMediaRequest & { file_path: string }
|
|
198
|
+
params: UploadMediaRequest & { file_path: string }
|
|
201
199
|
): Promise<any> {
|
|
202
200
|
try {
|
|
203
201
|
if (!fs.existsSync(params.file_path)) {
|
|
@@ -213,7 +211,7 @@ export class MediaTools {
|
|
|
213
211
|
|
|
214
212
|
public async handleUpdateMedia(
|
|
215
213
|
client: WordPressClient,
|
|
216
|
-
params: UpdateMediaRequest & { id: number }
|
|
214
|
+
params: UpdateMediaRequest & { id: number }
|
|
217
215
|
): Promise<any> {
|
|
218
216
|
try {
|
|
219
217
|
const media = await client.updateMedia(params);
|
|
@@ -225,11 +223,11 @@ export class MediaTools {
|
|
|
225
223
|
|
|
226
224
|
public async handleDeleteMedia(
|
|
227
225
|
client: WordPressClient,
|
|
228
|
-
params: { id: number; force?: boolean }
|
|
226
|
+
params: { id: number; force?: boolean }
|
|
229
227
|
): Promise<any> {
|
|
230
228
|
try {
|
|
231
229
|
await client.deleteMedia(params.id, params.force);
|
|
232
|
-
const action = params.force ?
|
|
230
|
+
const action = params.force ? 'permanently deleted' : 'moved to trash';
|
|
233
231
|
return `✅ Media item ${params.id} has been ${action}.`;
|
|
234
232
|
} catch (error) {
|
|
235
233
|
throw new Error(`Failed to delete media: ${getErrorMessage(error)}`);
|