mcp-wordpress 1.2.2 → 1.3.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 +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- 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/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- 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/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.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/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
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,16 +246,18 @@ 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) {
|
|
258
|
-
throw new Error(
|
|
258
|
+
throw new Error(
|
|
259
|
+
`Failed to mark comment as spam: ${getErrorMessage(error)}`,
|
|
260
|
+
);
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
}
|
package/src/tools/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { default as AuthTools } from
|
|
2
|
-
export { default as CacheTools } from
|
|
3
|
-
export { default as CommentTools } from
|
|
4
|
-
export { default as MediaTools } from
|
|
5
|
-
export { default as PageTools } from
|
|
6
|
-
export { default as PerformanceTools } from
|
|
7
|
-
export { default as PostTools } from
|
|
8
|
-
export { default as SiteTools } from
|
|
9
|
-
export { default as TaxonomyTools } from
|
|
10
|
-
export { default as UserTools } from
|
|
1
|
+
export { default as AuthTools } from "./auth.js";
|
|
2
|
+
export { default as CacheTools } from "./cache.js";
|
|
3
|
+
export { default as CommentTools } from "./comments.js";
|
|
4
|
+
export { default as MediaTools } from "./media.js";
|
|
5
|
+
export { default as PageTools } from "./pages.js";
|
|
6
|
+
export { default as PerformanceTools } from "./performance.js";
|
|
7
|
+
export { default as PostTools } from "./posts.js";
|
|
8
|
+
export { default as SiteTools } from "./site.js";
|
|
9
|
+
export { default as TaxonomyTools } from "./taxonomies.js";
|
|
10
|
+
export { default as UserTools } from "./users.js";
|
package/src/tools/media.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import { WordPressClient } from
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { WordPressClient } from "../client/api.js";
|
|
3
3
|
import {
|
|
4
4
|
MediaQueryParams,
|
|
5
5
|
UpdateMediaRequest,
|
|
6
|
-
UploadMediaRequest
|
|
7
|
-
} from
|
|
8
|
-
import { getErrorMessage } from
|
|
6
|
+
UploadMediaRequest,
|
|
7
|
+
} from "../types/wordpress.js";
|
|
8
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Provides tools for managing media on a WordPress site.
|
|
@@ -19,152 +19,152 @@ export class MediaTools {
|
|
|
19
19
|
public getTools(): any[] {
|
|
20
20
|
return [
|
|
21
21
|
{
|
|
22
|
-
name:
|
|
23
|
-
description:
|
|
22
|
+
name: "wp_list_media",
|
|
23
|
+
description: "Lists media items from a WordPress site, with filters.",
|
|
24
24
|
parameters: [
|
|
25
25
|
{
|
|
26
|
-
name:
|
|
27
|
-
type:
|
|
28
|
-
description:
|
|
26
|
+
name: "per_page",
|
|
27
|
+
type: "number",
|
|
28
|
+
description: "Number of items to return per page (max 100).",
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
name:
|
|
32
|
-
type:
|
|
33
|
-
description:
|
|
31
|
+
name: "search",
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Limit results to those matching a search term.",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
name:
|
|
37
|
-
type:
|
|
38
|
-
description:
|
|
39
|
-
enum: [
|
|
40
|
-
}
|
|
36
|
+
name: "media_type",
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Limit results to a specific media type.",
|
|
39
|
+
enum: ["image", "video", "audio", "application"],
|
|
40
|
+
},
|
|
41
41
|
],
|
|
42
|
-
handler: this.handleListMedia.bind(this)
|
|
42
|
+
handler: this.handleListMedia.bind(this),
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
name:
|
|
46
|
-
description:
|
|
45
|
+
name: "wp_get_media",
|
|
46
|
+
description: "Retrieves a single media item by its ID.",
|
|
47
47
|
parameters: [
|
|
48
48
|
{
|
|
49
|
-
name:
|
|
50
|
-
type:
|
|
49
|
+
name: "id",
|
|
50
|
+
type: "number",
|
|
51
51
|
required: true,
|
|
52
|
-
description:
|
|
53
|
-
}
|
|
52
|
+
description: "The unique identifier for the media item.",
|
|
53
|
+
},
|
|
54
54
|
],
|
|
55
|
-
handler: this.handleGetMedia.bind(this)
|
|
55
|
+
handler: this.handleGetMedia.bind(this),
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
name:
|
|
59
|
-
description:
|
|
58
|
+
name: "wp_upload_media",
|
|
59
|
+
description: "Uploads a file to the WordPress media library.",
|
|
60
60
|
parameters: [
|
|
61
61
|
{
|
|
62
|
-
name:
|
|
63
|
-
type:
|
|
62
|
+
name: "file_path",
|
|
63
|
+
type: "string",
|
|
64
64
|
required: true,
|
|
65
|
-
description:
|
|
65
|
+
description: "The local, absolute path to the file to upload.",
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
|
-
name:
|
|
69
|
-
type:
|
|
70
|
-
description:
|
|
68
|
+
name: "title",
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "The title for the media item.",
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
|
-
name:
|
|
74
|
-
type:
|
|
73
|
+
name: "alt_text",
|
|
74
|
+
type: "string",
|
|
75
75
|
description:
|
|
76
|
-
|
|
76
|
+
"Alternative text for the media item (for accessibility).",
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
|
-
name:
|
|
80
|
-
type:
|
|
81
|
-
description:
|
|
79
|
+
name: "caption",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "The caption for the media item.",
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
name:
|
|
85
|
-
type:
|
|
86
|
-
description:
|
|
84
|
+
name: "description",
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "The description for the media item.",
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
name:
|
|
90
|
-
type:
|
|
91
|
-
description:
|
|
92
|
-
}
|
|
89
|
+
name: "post",
|
|
90
|
+
type: "number",
|
|
91
|
+
description: "The ID of a post to attach this media to.",
|
|
92
|
+
},
|
|
93
93
|
],
|
|
94
|
-
handler: this.handleUploadMedia.bind(this)
|
|
94
|
+
handler: this.handleUploadMedia.bind(this),
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
name:
|
|
98
|
-
description:
|
|
97
|
+
name: "wp_update_media",
|
|
98
|
+
description: "Updates the metadata of an existing media item.",
|
|
99
99
|
parameters: [
|
|
100
100
|
{
|
|
101
|
-
name:
|
|
102
|
-
type:
|
|
101
|
+
name: "id",
|
|
102
|
+
type: "number",
|
|
103
103
|
required: true,
|
|
104
|
-
description:
|
|
104
|
+
description: "The ID of the media item to update.",
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
name:
|
|
108
|
-
type:
|
|
109
|
-
description:
|
|
107
|
+
name: "title",
|
|
108
|
+
type: "string",
|
|
109
|
+
description: "The new title for the media item.",
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
|
-
name:
|
|
113
|
-
type:
|
|
114
|
-
description:
|
|
112
|
+
name: "alt_text",
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "The new alternative text.",
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
|
-
name:
|
|
118
|
-
type:
|
|
119
|
-
description:
|
|
117
|
+
name: "caption",
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "The new caption.",
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
|
-
name:
|
|
123
|
-
type:
|
|
124
|
-
description:
|
|
125
|
-
}
|
|
122
|
+
name: "description",
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "The new description.",
|
|
125
|
+
},
|
|
126
126
|
],
|
|
127
|
-
handler: this.handleUpdateMedia.bind(this)
|
|
127
|
+
handler: this.handleUpdateMedia.bind(this),
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
|
-
name:
|
|
131
|
-
description:
|
|
130
|
+
name: "wp_delete_media",
|
|
131
|
+
description: "Deletes a media item.",
|
|
132
132
|
parameters: [
|
|
133
133
|
{
|
|
134
|
-
name:
|
|
135
|
-
type:
|
|
134
|
+
name: "id",
|
|
135
|
+
type: "number",
|
|
136
136
|
required: true,
|
|
137
|
-
description:
|
|
137
|
+
description: "The ID of the media item to delete.",
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
|
-
name:
|
|
141
|
-
type:
|
|
140
|
+
name: "force",
|
|
141
|
+
type: "boolean",
|
|
142
142
|
description:
|
|
143
|
-
|
|
144
|
-
}
|
|
143
|
+
"If true, permanently delete. If false, move to trash. Defaults to false.",
|
|
144
|
+
},
|
|
145
145
|
],
|
|
146
|
-
handler: this.handleDeleteMedia.bind(this)
|
|
147
|
-
}
|
|
146
|
+
handler: this.handleDeleteMedia.bind(this),
|
|
147
|
+
},
|
|
148
148
|
];
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
public async handleListMedia(
|
|
152
152
|
client: WordPressClient,
|
|
153
|
-
params: MediaQueryParams
|
|
153
|
+
params: MediaQueryParams,
|
|
154
154
|
): Promise<any> {
|
|
155
155
|
try {
|
|
156
156
|
const media = await client.getMedia(params);
|
|
157
157
|
if (media.length === 0) {
|
|
158
|
-
return
|
|
158
|
+
return "No media items found matching the criteria.";
|
|
159
159
|
}
|
|
160
160
|
const content =
|
|
161
161
|
`Found ${media.length} media items:\n\n` +
|
|
162
162
|
media
|
|
163
163
|
.map(
|
|
164
164
|
(m) =>
|
|
165
|
-
`- 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}`,
|
|
166
166
|
)
|
|
167
|
-
.join(
|
|
167
|
+
.join("\n");
|
|
168
168
|
return content;
|
|
169
169
|
} catch (error) {
|
|
170
170
|
throw new Error(`Failed to list media: ${getErrorMessage(error)}`);
|
|
@@ -173,7 +173,7 @@ export class MediaTools {
|
|
|
173
173
|
|
|
174
174
|
public async handleGetMedia(
|
|
175
175
|
client: WordPressClient,
|
|
176
|
-
params: { id: number }
|
|
176
|
+
params: { id: number },
|
|
177
177
|
): Promise<any> {
|
|
178
178
|
try {
|
|
179
179
|
const media = await client.getMediaItem(params.id);
|
|
@@ -183,10 +183,10 @@ export class MediaTools {
|
|
|
183
183
|
`- **URL:** ${media.source_url}\n` +
|
|
184
184
|
`- **Type:** ${media.media_type} (${media.mime_type})\n` +
|
|
185
185
|
`- **Date:** ${new Date(media.date).toLocaleString()}\n` +
|
|
186
|
-
(media.alt_text ? `- **Alt Text:** ${media.alt_text}\n` :
|
|
186
|
+
(media.alt_text ? `- **Alt Text:** ${media.alt_text}\n` : "") +
|
|
187
187
|
(media.caption.rendered
|
|
188
188
|
? `- **Caption:** ${media.caption.rendered}\n`
|
|
189
|
-
:
|
|
189
|
+
: "");
|
|
190
190
|
return content;
|
|
191
191
|
} catch (error) {
|
|
192
192
|
throw new Error(`Failed to get media item: ${getErrorMessage(error)}`);
|
|
@@ -195,7 +195,7 @@ export class MediaTools {
|
|
|
195
195
|
|
|
196
196
|
public async handleUploadMedia(
|
|
197
197
|
client: WordPressClient,
|
|
198
|
-
params: UploadMediaRequest & { file_path: string }
|
|
198
|
+
params: UploadMediaRequest & { file_path: string },
|
|
199
199
|
): Promise<any> {
|
|
200
200
|
try {
|
|
201
201
|
if (!fs.existsSync(params.file_path)) {
|
|
@@ -211,7 +211,7 @@ export class MediaTools {
|
|
|
211
211
|
|
|
212
212
|
public async handleUpdateMedia(
|
|
213
213
|
client: WordPressClient,
|
|
214
|
-
params: UpdateMediaRequest & { id: number }
|
|
214
|
+
params: UpdateMediaRequest & { id: number },
|
|
215
215
|
): Promise<any> {
|
|
216
216
|
try {
|
|
217
217
|
const media = await client.updateMedia(params);
|
|
@@ -223,11 +223,11 @@ export class MediaTools {
|
|
|
223
223
|
|
|
224
224
|
public async handleDeleteMedia(
|
|
225
225
|
client: WordPressClient,
|
|
226
|
-
params: { id: number; force?: boolean }
|
|
226
|
+
params: { id: number; force?: boolean },
|
|
227
227
|
): Promise<any> {
|
|
228
228
|
try {
|
|
229
229
|
await client.deleteMedia(params.id, params.force);
|
|
230
|
-
const action = params.force ?
|
|
230
|
+
const action = params.force ? "permanently deleted" : "moved to trash";
|
|
231
231
|
return `✅ Media item ${params.id} has been ${action}.`;
|
|
232
232
|
} catch (error) {
|
|
233
233
|
throw new Error(`Failed to delete media: ${getErrorMessage(error)}`);
|