mcp-wordpress 1.1.7 → 1.2.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/README.md +388 -66
- package/dist/cache/CacheInvalidation.d.ts +118 -0
- package/dist/cache/CacheInvalidation.d.ts.map +1 -0
- package/dist/cache/CacheInvalidation.js +349 -0
- package/dist/cache/CacheInvalidation.js.map +1 -0
- package/dist/cache/CacheManager.d.ts +143 -0
- package/dist/cache/CacheManager.d.ts.map +1 -0
- package/dist/cache/CacheManager.js +308 -0
- package/dist/cache/CacheManager.js.map +1 -0
- package/dist/cache/HttpCacheWrapper.d.ts +121 -0
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -0
- package/dist/cache/HttpCacheWrapper.js +280 -0
- package/dist/cache/HttpCacheWrapper.js.map +1 -0
- package/dist/cache/__tests__/CacheInvalidation.test.d.ts +5 -0
- package/dist/cache/__tests__/CacheInvalidation.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CacheInvalidation.test.js +236 -0
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -0
- package/dist/cache/__tests__/CacheManager.test.d.ts +5 -0
- package/dist/cache/__tests__/CacheManager.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CacheManager.test.js +233 -0
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.d.ts +5 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.js +228 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.d.ts +5 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.d.ts.map +1 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +296 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -0
- package/dist/cache/index.d.ts +12 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +9 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/client/CachedWordPressClient.d.ts +160 -0
- package/dist/client/CachedWordPressClient.d.ts.map +1 -0
- package/dist/client/CachedWordPressClient.js +338 -0
- package/dist/client/CachedWordPressClient.js.map +1 -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/config/ConfigurationSchema.d.ts +281 -0
- package/dist/config/ConfigurationSchema.d.ts.map +1 -0
- package/dist/config/ConfigurationSchema.js +205 -0
- package/dist/config/ConfigurationSchema.js.map +1 -0
- package/dist/config/ServerConfiguration.d.ts +38 -0
- package/dist/config/ServerConfiguration.d.ts.map +1 -0
- package/dist/config/ServerConfiguration.js +158 -0
- package/dist/config/ServerConfiguration.js.map +1 -0
- package/dist/docs/DocumentationGenerator.d.ts +184 -0
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -0
- package/dist/docs/DocumentationGenerator.js +735 -0
- package/dist/docs/DocumentationGenerator.js.map +1 -0
- package/dist/docs/MarkdownFormatter.d.ts +84 -0
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -0
- package/dist/docs/MarkdownFormatter.js +448 -0
- package/dist/docs/MarkdownFormatter.js.map +1 -0
- package/dist/docs/index.d.ts +8 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +7 -0
- package/dist/docs/index.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -212
- package/dist/index.js.map +1 -1
- package/dist/performance/AnomalyDetector.d.ts +63 -0
- package/dist/performance/AnomalyDetector.d.ts.map +1 -0
- package/dist/performance/AnomalyDetector.js +222 -0
- package/dist/performance/AnomalyDetector.js.map +1 -0
- package/dist/performance/BenchmarkAnalyzer.d.ts +67 -0
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +1 -0
- package/dist/performance/BenchmarkAnalyzer.js +301 -0
- package/dist/performance/BenchmarkAnalyzer.js.map +1 -0
- package/dist/performance/MetricsCollector.d.ts +139 -0
- package/dist/performance/MetricsCollector.d.ts.map +1 -0
- package/dist/performance/MetricsCollector.js +320 -0
- package/dist/performance/MetricsCollector.js.map +1 -0
- package/dist/performance/PerformanceAnalytics.d.ts +162 -0
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -0
- package/dist/performance/PerformanceAnalytics.js +554 -0
- package/dist/performance/PerformanceAnalytics.js.map +1 -0
- package/dist/performance/PerformanceMonitor.d.ts +202 -0
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -0
- package/dist/performance/PerformanceMonitor.js +478 -0
- package/dist/performance/PerformanceMonitor.js.map +1 -0
- package/dist/performance/TrendAnalyzer.d.ts +69 -0
- package/dist/performance/TrendAnalyzer.d.ts.map +1 -0
- package/dist/performance/TrendAnalyzer.js +203 -0
- package/dist/performance/TrendAnalyzer.js.map +1 -0
- package/dist/performance/index.d.ts +11 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +8 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/security/InputValidator.d.ts +215 -0
- package/dist/security/InputValidator.d.ts.map +1 -0
- package/dist/security/InputValidator.js +278 -0
- package/dist/security/InputValidator.js.map +1 -0
- package/dist/security/SecurityConfig.d.ts +129 -0
- package/dist/security/SecurityConfig.d.ts.map +1 -0
- package/dist/security/SecurityConfig.js +262 -0
- package/dist/security/SecurityConfig.js.map +1 -0
- package/dist/server/ConnectionTester.d.ts +24 -0
- package/dist/server/ConnectionTester.d.ts.map +1 -0
- package/dist/server/ConnectionTester.js +61 -0
- package/dist/server/ConnectionTester.js.map +1 -0
- package/dist/server/ToolRegistry.d.ts +46 -0
- package/dist/server/ToolRegistry.d.ts.map +1 -0
- package/dist/server/ToolRegistry.js +148 -0
- package/dist/server/ToolRegistry.js.map +1 -0
- package/dist/tools/BaseToolClass.d.ts +76 -0
- package/dist/tools/BaseToolClass.d.ts.map +1 -0
- package/dist/tools/BaseToolClass.js +104 -0
- package/dist/tools/BaseToolClass.js.map +1 -0
- package/dist/tools/BaseToolManager.d.ts +26 -0
- package/dist/tools/BaseToolManager.d.ts.map +1 -0
- package/dist/tools/BaseToolManager.js +56 -0
- package/dist/tools/BaseToolManager.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/cache.d.ts +260 -0
- package/dist/tools/cache.d.ts.map +1 -0
- package/dist/tools/cache.js +237 -0
- package/dist/tools/cache.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/performance.d.ts +63 -0
- package/dist/tools/performance.d.ts.map +1 -0
- package/dist/tools/performance.js +865 -0
- package/dist/tools/performance.js.map +1 -0
- package/dist/types/client.d.ts +1 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts +4 -0
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +11 -0
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts +68 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +185 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/CACHING.md +340 -0
- package/docs/DOCKER.md +451 -0
- package/docs/PERFORMANCE_MONITORING.md +471 -0
- package/docs/SECURITY_TESTING.md +393 -0
- package/docs/api/README.md +200 -0
- package/docs/api/categories/auth.md +40 -0
- package/docs/api/categories/cache.md +41 -0
- package/docs/api/categories/comment.md +44 -0
- package/docs/api/categories/media.md +43 -0
- package/docs/api/categories/page.md +43 -0
- package/docs/api/categories/performance.md +44 -0
- package/docs/api/categories/post.md +43 -0
- package/docs/api/categories/site.md +43 -0
- package/docs/api/categories/taxonomy.md +47 -0
- package/docs/api/categories/user.md +43 -0
- package/docs/api/openapi.json +3305 -0
- package/docs/api/summary.json +12 -0
- package/docs/api/tools/wp_approve_comment.md +98 -0
- package/docs/api/tools/wp_cache_clear.md +120 -0
- package/docs/api/tools/wp_cache_info.md +119 -0
- package/docs/api/tools/wp_cache_stats.md +119 -0
- package/docs/api/tools/wp_cache_warm.md +119 -0
- package/docs/api/tools/wp_create_application_password.md +102 -0
- package/docs/api/tools/wp_create_category.md +102 -0
- package/docs/api/tools/wp_create_comment.md +128 -0
- package/docs/api/tools/wp_create_page.md +135 -0
- package/docs/api/tools/wp_create_post.md +147 -0
- package/docs/api/tools/wp_create_tag.md +101 -0
- package/docs/api/tools/wp_create_user.md +135 -0
- package/docs/api/tools/wp_delete_application_password.md +101 -0
- package/docs/api/tools/wp_delete_category.md +100 -0
- package/docs/api/tools/wp_delete_comment.md +101 -0
- package/docs/api/tools/wp_delete_media.md +108 -0
- package/docs/api/tools/wp_delete_page.md +108 -0
- package/docs/api/tools/wp_delete_post.md +117 -0
- package/docs/api/tools/wp_delete_tag.md +100 -0
- package/docs/api/tools/wp_delete_user.md +108 -0
- package/docs/api/tools/wp_get_application_passwords.md +103 -0
- package/docs/api/tools/wp_get_auth_status.md +101 -0
- package/docs/api/tools/wp_get_category.md +103 -0
- package/docs/api/tools/wp_get_comment.md +103 -0
- package/docs/api/tools/wp_get_current_user.md +101 -0
- package/docs/api/tools/wp_get_media.md +103 -0
- package/docs/api/tools/wp_get_page.md +103 -0
- package/docs/api/tools/wp_get_page_revisions.md +103 -0
- package/docs/api/tools/wp_get_post.md +112 -0
- package/docs/api/tools/wp_get_post_revisions.md +103 -0
- package/docs/api/tools/wp_get_site_settings.md +108 -0
- package/docs/api/tools/wp_get_tag.md +103 -0
- package/docs/api/tools/wp_get_user.md +103 -0
- package/docs/api/tools/wp_list_categories.md +111 -0
- package/docs/api/tools/wp_list_comments.md +111 -0
- package/docs/api/tools/wp_list_media.md +145 -0
- package/docs/api/tools/wp_list_pages.md +145 -0
- package/docs/api/tools/wp_list_posts.md +156 -0
- package/docs/api/tools/wp_list_tags.md +110 -0
- package/docs/api/tools/wp_list_users.md +111 -0
- package/docs/api/tools/wp_performance_alerts.md +162 -0
- package/docs/api/tools/wp_performance_benchmark.md +160 -0
- package/docs/api/tools/wp_performance_export.md +162 -0
- package/docs/api/tools/wp_performance_history.md +161 -0
- package/docs/api/tools/wp_performance_optimize.md +162 -0
- package/docs/api/tools/wp_performance_stats.md +160 -0
- package/docs/api/tools/wp_search_site.md +99 -0
- package/docs/api/tools/wp_spam_comment.md +98 -0
- package/docs/api/tools/wp_switch_auth_method.md +122 -0
- package/docs/api/tools/wp_test_auth.md +96 -0
- package/docs/api/tools/wp_update_category.md +102 -0
- package/docs/api/tools/wp_update_comment.md +127 -0
- package/docs/api/tools/wp_update_media.md +129 -0
- package/docs/api/tools/wp_update_page.md +135 -0
- package/docs/api/tools/wp_update_post.md +144 -0
- package/docs/api/tools/wp_update_site_settings.md +127 -0
- package/docs/api/tools/wp_update_tag.md +102 -0
- package/docs/api/tools/wp_update_user.md +134 -0
- package/docs/api/tools/wp_upload_media.md +131 -0
- package/docs/api/types/WordPressPost.md +39 -0
- package/docs/contract-testing.md +183 -0
- package/docs/developer/NPM_AUTH_SETUP.md +3 -3
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +218 -0
- package/package.json +84 -64
- package/src/cache/CacheInvalidation.ts +421 -0
- package/src/cache/CacheManager.ts +391 -0
- package/src/cache/HttpCacheWrapper.ts +372 -0
- package/src/cache/__tests__/CacheInvalidation.test.ts +299 -0
- package/src/cache/__tests__/CacheManager.test.ts +300 -0
- package/src/cache/__tests__/CachedWordPressClient.test.ts +304 -0
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +359 -0
- package/src/cache/index.ts +26 -0
- package/src/client/CachedWordPressClient.ts +442 -0
- package/src/config/ConfigurationSchema.ts +246 -0
- package/src/config/ServerConfiguration.ts +215 -0
- package/src/docs/DocumentationGenerator.ts +952 -0
- package/src/docs/MarkdownFormatter.ts +494 -0
- package/src/docs/index.ts +21 -0
- package/src/index.ts +14 -274
- package/src/performance/MetricsCollector.ts +447 -0
- package/src/performance/PerformanceAnalytics.ts +762 -0
- package/src/performance/PerformanceMonitor.ts +649 -0
- package/src/performance/index.ts +28 -0
- package/src/security/InputValidator.ts +319 -0
- package/src/security/SecurityConfig.ts +301 -0
- package/src/server/ConnectionTester.ts +74 -0
- package/src/server/ToolRegistry.ts +194 -0
- package/src/tools/BaseToolManager.ts +66 -0
- package/src/tools/cache.ts +259 -0
- package/src/tools/index.ts +2 -0
- package/src/tools/performance.ts +948 -0
- package/src/types/client.ts +1 -0
- package/src/utils/toolWrapper.ts +11 -0
- package/src/utils/validation.ts +259 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security configuration and constants for MCP WordPress
|
|
3
|
+
*/
|
|
4
|
+
import { randomBytes } from 'crypto';
|
|
5
|
+
export const SecurityConfig = {
|
|
6
|
+
// Rate limiting
|
|
7
|
+
rateLimiting: {
|
|
8
|
+
default: {
|
|
9
|
+
windowMs: 60 * 1000, // 1 minute
|
|
10
|
+
maxRequests: 60
|
|
11
|
+
},
|
|
12
|
+
authentication: {
|
|
13
|
+
windowMs: 5 * 60 * 1000, // 5 minutes
|
|
14
|
+
maxAttempts: 5
|
|
15
|
+
},
|
|
16
|
+
upload: {
|
|
17
|
+
windowMs: 60 * 1000, // 1 minute
|
|
18
|
+
maxRequests: 10
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
// File upload restrictions
|
|
22
|
+
fileUpload: {
|
|
23
|
+
maxSizeMB: 10,
|
|
24
|
+
allowedMimeTypes: [
|
|
25
|
+
'image/jpeg',
|
|
26
|
+
'image/png',
|
|
27
|
+
'image/gif',
|
|
28
|
+
'image/webp',
|
|
29
|
+
'image/svg+xml',
|
|
30
|
+
'application/pdf',
|
|
31
|
+
'application/msword',
|
|
32
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
33
|
+
'application/vnd.ms-excel',
|
|
34
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
35
|
+
'text/plain',
|
|
36
|
+
'text/csv'
|
|
37
|
+
],
|
|
38
|
+
// Dangerous file extensions to block
|
|
39
|
+
blockedExtensions: [
|
|
40
|
+
'.exe',
|
|
41
|
+
'.bat',
|
|
42
|
+
'.cmd',
|
|
43
|
+
'.com',
|
|
44
|
+
'.pif',
|
|
45
|
+
'.scr',
|
|
46
|
+
'.vbs',
|
|
47
|
+
'.js',
|
|
48
|
+
'.jar',
|
|
49
|
+
'.zip',
|
|
50
|
+
'.rar',
|
|
51
|
+
'.tar',
|
|
52
|
+
'.php',
|
|
53
|
+
'.php3',
|
|
54
|
+
'.php4',
|
|
55
|
+
'.php5',
|
|
56
|
+
'.phtml',
|
|
57
|
+
'.sh',
|
|
58
|
+
'.bash',
|
|
59
|
+
'.zsh',
|
|
60
|
+
'.fish',
|
|
61
|
+
'.ps1',
|
|
62
|
+
'.psm1'
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
// Input validation
|
|
66
|
+
validation: {
|
|
67
|
+
maxStringLength: 1000,
|
|
68
|
+
maxTitleLength: 200,
|
|
69
|
+
maxContentLength: 50000,
|
|
70
|
+
maxExcerptLength: 500,
|
|
71
|
+
maxUrlLength: 2048,
|
|
72
|
+
maxUsernameLength: 60,
|
|
73
|
+
minUsernameLength: 3,
|
|
74
|
+
maxPasswordLength: 128,
|
|
75
|
+
minPasswordLength: 8
|
|
76
|
+
},
|
|
77
|
+
// Request timeouts (milliseconds)
|
|
78
|
+
timeouts: {
|
|
79
|
+
default: 30000, // 30 seconds
|
|
80
|
+
upload: 600000, // 10 minutes
|
|
81
|
+
auth: 10000 // 10 seconds
|
|
82
|
+
},
|
|
83
|
+
// Security headers
|
|
84
|
+
headers: {
|
|
85
|
+
'X-Content-Type-Options': 'nosniff',
|
|
86
|
+
'X-Frame-Options': 'DENY',
|
|
87
|
+
'X-XSS-Protection': '1; mode=block',
|
|
88
|
+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
|
|
89
|
+
'Content-Security-Policy': 'default-src \'self\''
|
|
90
|
+
},
|
|
91
|
+
// Error messages (generic to avoid information disclosure)
|
|
92
|
+
errorMessages: {
|
|
93
|
+
authentication: 'Authentication failed. Please check your credentials.',
|
|
94
|
+
authorization: 'You do not have permission to perform this action.',
|
|
95
|
+
validation: 'Invalid input provided.',
|
|
96
|
+
rateLimit: 'Too many requests. Please try again later.',
|
|
97
|
+
serverError: 'An error occurred processing your request.',
|
|
98
|
+
notFound: 'The requested resource was not found.'
|
|
99
|
+
},
|
|
100
|
+
// Logging configuration
|
|
101
|
+
logging: {
|
|
102
|
+
// Fields to exclude from logs
|
|
103
|
+
excludeFields: [
|
|
104
|
+
'password',
|
|
105
|
+
'appPassword',
|
|
106
|
+
'app_password',
|
|
107
|
+
'token',
|
|
108
|
+
'secret',
|
|
109
|
+
'authorization',
|
|
110
|
+
'cookie',
|
|
111
|
+
'session',
|
|
112
|
+
'key',
|
|
113
|
+
'apiKey',
|
|
114
|
+
'api_key'
|
|
115
|
+
],
|
|
116
|
+
// Patterns to redact in log messages
|
|
117
|
+
redactPatterns: [
|
|
118
|
+
/password["\s:=]+["']?([^"'\s]+)["']?/gi,
|
|
119
|
+
/token["\s:=]+["']?([^"'\s]+)["']?/gi,
|
|
120
|
+
/secret["\s:=]+["']?([^"'\s]+)["']?/gi,
|
|
121
|
+
/key["\s:=]+["']?([^"'\s]+)["']?/gi
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
// Cache configuration
|
|
125
|
+
cache: {
|
|
126
|
+
// Default cache settings
|
|
127
|
+
enabled: true,
|
|
128
|
+
maxSize: 1000, // Maximum number of cached entries
|
|
129
|
+
defaultTTL: 15 * 60 * 1000, // 15 minutes default TTL
|
|
130
|
+
enableLRU: true,
|
|
131
|
+
enableStats: true,
|
|
132
|
+
// TTL presets by data type (milliseconds)
|
|
133
|
+
ttlPresets: {
|
|
134
|
+
static: 4 * 60 * 60 * 1000, // 4 hours - site settings, user roles
|
|
135
|
+
semiStatic: 2 * 60 * 60 * 1000, // 2 hours - categories, tags, user profiles
|
|
136
|
+
dynamic: 15 * 60 * 1000, // 15 minutes - posts, pages, comments
|
|
137
|
+
session: 30 * 60 * 1000, // 30 minutes - authentication, current user
|
|
138
|
+
realtime: 60 * 1000 // 1 minute - real-time data
|
|
139
|
+
},
|
|
140
|
+
// Cache-Control headers by data type
|
|
141
|
+
cacheHeaders: {
|
|
142
|
+
static: 'public, max-age=14400', // 4 hours
|
|
143
|
+
semiStatic: 'public, max-age=7200', // 2 hours
|
|
144
|
+
dynamic: 'public, max-age=900', // 15 minutes
|
|
145
|
+
session: 'private, max-age=1800', // 30 minutes
|
|
146
|
+
realtime: 'public, max-age=60' // 1 minute
|
|
147
|
+
},
|
|
148
|
+
// Invalidation settings
|
|
149
|
+
invalidation: {
|
|
150
|
+
enabled: true,
|
|
151
|
+
batchSize: 100, // Max events to process in one batch
|
|
152
|
+
queueTimeout: 5000, // Max time to wait before processing queue (ms)
|
|
153
|
+
enableCascading: true // Allow cascading invalidations
|
|
154
|
+
},
|
|
155
|
+
// Memory management
|
|
156
|
+
cleanup: {
|
|
157
|
+
interval: 60 * 1000, // Cleanup interval in milliseconds (1 minute)
|
|
158
|
+
maxMemoryMB: 50, // Maximum memory usage for cache
|
|
159
|
+
evictionThreshold: 0.8 // Start evicting when 80% full
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Security utility functions
|
|
165
|
+
*/
|
|
166
|
+
export class SecurityUtils {
|
|
167
|
+
/**
|
|
168
|
+
* Redact sensitive information from objects
|
|
169
|
+
*/
|
|
170
|
+
static redactSensitiveData(obj) {
|
|
171
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
172
|
+
return obj;
|
|
173
|
+
}
|
|
174
|
+
const redacted = Array.isArray(obj) ? [...obj] : { ...obj };
|
|
175
|
+
for (const key in redacted) {
|
|
176
|
+
if (SecurityConfig.logging.excludeFields.some((field) => key.toLowerCase().includes(field.toLowerCase()))) {
|
|
177
|
+
redacted[key] = '[REDACTED]';
|
|
178
|
+
}
|
|
179
|
+
else if (typeof redacted[key] === 'object') {
|
|
180
|
+
redacted[key] = SecurityUtils.redactSensitiveData(redacted[key]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return redacted;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Redact sensitive patterns from strings
|
|
187
|
+
*/
|
|
188
|
+
static redactString(str) {
|
|
189
|
+
let redacted = str;
|
|
190
|
+
for (const pattern of SecurityConfig.logging.redactPatterns) {
|
|
191
|
+
redacted = redacted.replace(pattern, (match, value) => {
|
|
192
|
+
return match.replace(value, '[REDACTED]');
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return redacted;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Generate secure random strings
|
|
199
|
+
*/
|
|
200
|
+
static generateSecureToken(length = 32) {
|
|
201
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
202
|
+
const array = new Uint8Array(length);
|
|
203
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
204
|
+
crypto.getRandomValues(array);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Fallback for Node.js
|
|
208
|
+
const buffer = randomBytes(length);
|
|
209
|
+
array.set(buffer);
|
|
210
|
+
}
|
|
211
|
+
return Array.from(array, (byte) => chars[byte % chars.length]).join('');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Check if a file extension is allowed
|
|
215
|
+
*/
|
|
216
|
+
static isFileExtensionAllowed(filename) {
|
|
217
|
+
const ext = path.extname(filename).toLowerCase();
|
|
218
|
+
return !SecurityConfig.fileUpload.blockedExtensions.includes(ext);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Sanitize log output
|
|
222
|
+
*/
|
|
223
|
+
static sanitizeForLog(data) {
|
|
224
|
+
if (typeof data === 'string') {
|
|
225
|
+
return SecurityUtils.redactString(data);
|
|
226
|
+
}
|
|
227
|
+
if (typeof data === 'object') {
|
|
228
|
+
return SecurityUtils.redactSensitiveData(data);
|
|
229
|
+
}
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Secure error handler that prevents information disclosure
|
|
235
|
+
*/
|
|
236
|
+
export function createSecureError(error, fallbackMessage = SecurityConfig.errorMessages.serverError) {
|
|
237
|
+
// Log the actual error for debugging (with sanitization)
|
|
238
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
239
|
+
console.error('Secure Error:', SecurityUtils.sanitizeForLog(error));
|
|
240
|
+
}
|
|
241
|
+
// Return generic error to prevent information disclosure
|
|
242
|
+
const secureError = new Error(fallbackMessage);
|
|
243
|
+
// Preserve error code if it's safe
|
|
244
|
+
if (error && typeof error.code === 'string' && !error.code.includes('_')) {
|
|
245
|
+
secureError.code = error.code;
|
|
246
|
+
}
|
|
247
|
+
return secureError;
|
|
248
|
+
}
|
|
249
|
+
// Import path for file extension checking
|
|
250
|
+
import * as path from 'path';
|
|
251
|
+
/**
|
|
252
|
+
* Environment-specific security settings
|
|
253
|
+
*/
|
|
254
|
+
export function getEnvironmentSecurity() {
|
|
255
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
256
|
+
return {
|
|
257
|
+
strictMode: isProduction,
|
|
258
|
+
verboseErrors: !isProduction,
|
|
259
|
+
enforceHttps: isProduction
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=SecurityConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityConfig.js","sourceRoot":"","sources":["../../src/security/SecurityCon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AC,EAAE,CAAC;QACxE,WAAmB,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,0CAA0C;AAC1C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAKpC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAE3D,OAAO;QACL,UAAU,EAAE,YAAY;QACxB,aAAa,EAAE,CAAC,YAAY;QAC5B,YAAY,EAAE,YAAY;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WordPressClient } from '../client/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Service for testing WordPress client connections
|
|
4
|
+
* Handles connection validation and health checks
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConnectionTester {
|
|
7
|
+
/**
|
|
8
|
+
* Test connections to all configured WordPress sites
|
|
9
|
+
*/
|
|
10
|
+
static testClientConnections(wordpressClients: Map<string, WordPressClient>): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Check if error is authentication-related
|
|
13
|
+
*/
|
|
14
|
+
private static isAuthenticationError;
|
|
15
|
+
/**
|
|
16
|
+
* Perform health check for a specific client
|
|
17
|
+
*/
|
|
18
|
+
static healthCheck(client: WordPressClient): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Perform health checks for all clients
|
|
21
|
+
*/
|
|
22
|
+
static healthCheckAll(wordpressClients: Map<string, WordPressClient>): Promise<Map<string, boolean>>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ConnectionTester.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionTester.d.ts","sourceRoot":"","sources":["../../src/server/ConnectionTester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;WACiB,qBAAqB,CACvC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC;IAsBhB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAOpC;;OAEG;WACiB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAU1E;;OAEG;WACiB,cAAc,CAChC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,GAC7C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAUjC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getErrorMessage } from '../utils/error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Service for testing WordPress client connections
|
|
4
|
+
* Handles connection validation and health checks
|
|
5
|
+
*/
|
|
6
|
+
export class ConnectionTester {
|
|
7
|
+
/**
|
|
8
|
+
* Test connections to all configured WordPress sites
|
|
9
|
+
*/
|
|
10
|
+
static async testClientConnections(wordpressClients) {
|
|
11
|
+
console.error('INFO: Testing connections to all configured WordPress sites...');
|
|
12
|
+
const connectionPromises = Array.from(wordpressClients.entries()).map(async ([siteId, client]) => {
|
|
13
|
+
try {
|
|
14
|
+
await client.ping();
|
|
15
|
+
console.error(`SUCCESS: Connection to site '${siteId}' successful.`);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(`ERROR: Failed to connect to site '${siteId}': ${getErrorMessage(error)}`);
|
|
19
|
+
if (ConnectionTester.isAuthenticationError(error)) {
|
|
20
|
+
console.error(`Authentication may have failed for site '${siteId}'. Please check credentials.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
await Promise.all(connectionPromises);
|
|
25
|
+
console.error('INFO: Connection tests complete.');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if error is authentication-related
|
|
29
|
+
*/
|
|
30
|
+
static isAuthenticationError(error) {
|
|
31
|
+
if (error?.response?.status && [401, 403].includes(error.response.status)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return error?.code === 'WORDPRESS_AUTH_ERROR';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Perform health check for a specific client
|
|
38
|
+
*/
|
|
39
|
+
static async healthCheck(client) {
|
|
40
|
+
try {
|
|
41
|
+
await client.ping();
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(`Health check failed: ${getErrorMessage(error)}`);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Perform health checks for all clients
|
|
51
|
+
*/
|
|
52
|
+
static async healthCheckAll(wordpressClients) {
|
|
53
|
+
const results = new Map();
|
|
54
|
+
for (const [siteId, client] of wordpressClients.entries()) {
|
|
55
|
+
const isHealthy = await ConnectionTester.healthCheck(client);
|
|
56
|
+
results.set(siteId, isHealthy);
|
|
57
|
+
}
|
|
58
|
+
return results;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=ConnectionTester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionTester.js","sourceRoot":"","sources":["../../src/server/ConnectionTester.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,qBAAqB,CACvC,gBAA8C;QAE9C,OAAO,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QAEhF,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CACnE,KAAK,EAAE,CAAC,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,CAAC,cAAc,CAChC,gBAA8C;QAE9C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;QAE3C,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1D,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAC7D,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { WordPressClient } from '../client/api.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for tool definition
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolDefinition {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
parameters?: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
handler: (client: WordPressClient, args: any) => Promise<any>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Registry for managing MCP tools
|
|
19
|
+
* Handles tool registration, parameter validation, and execution
|
|
20
|
+
*/
|
|
21
|
+
export declare class ToolRegistry {
|
|
22
|
+
private server;
|
|
23
|
+
private wordpressClients;
|
|
24
|
+
constructor(server: McpServer, wordpressClients: Map<string, WordPressClient>);
|
|
25
|
+
/**
|
|
26
|
+
* Register all available tools with the MCP server
|
|
27
|
+
*/
|
|
28
|
+
registerAllTools(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Register a single tool with parameter validation and execution handling
|
|
31
|
+
*/
|
|
32
|
+
private registerTool;
|
|
33
|
+
/**
|
|
34
|
+
* Build Zod parameter schema from tool definition
|
|
35
|
+
*/
|
|
36
|
+
private buildParameterSchema;
|
|
37
|
+
/**
|
|
38
|
+
* Get appropriate Zod type for parameter definition
|
|
39
|
+
*/
|
|
40
|
+
private getZodTypeForParameter;
|
|
41
|
+
/**
|
|
42
|
+
* Check if error is authentication-related
|
|
43
|
+
*/
|
|
44
|
+
private isAuthenticationError;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ToolRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.d.ts","sourceRoot":"","sources":["../../src/server/ToolRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;IACH,OAAO,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,gBAAgB,CAA+B;gBAE3C,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAK7E;;OAEG;IACI,gBAAgB,IAAI,IAAI;IAoB/B;;OAEG;IACH,OAAO,CAAC,YAAY;IAiFpB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAiB9B;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAM9B"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { getErrorMessage } from '../utils/error.js';
|
|
2
|
+
import * as Tools from '../tools/index.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing MCP tools
|
|
6
|
+
* Handles tool registration, parameter validation, and execution
|
|
7
|
+
*/
|
|
8
|
+
export class ToolRegistry {
|
|
9
|
+
server;
|
|
10
|
+
wordpressClients;
|
|
11
|
+
constructor(server, wordpressClients) {
|
|
12
|
+
this.server = server;
|
|
13
|
+
this.wordpressClients = wordpressClients;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Register all available tools with the MCP server
|
|
17
|
+
*/
|
|
18
|
+
registerAllTools() {
|
|
19
|
+
// Register all tools from the tools directory
|
|
20
|
+
Object.values(Tools).forEach((ToolClass) => {
|
|
21
|
+
let toolInstance;
|
|
22
|
+
// Cache and Performance tools need the clients map
|
|
23
|
+
if (ToolClass.name === 'CacheTools' || ToolClass.name === 'PerformanceTools') {
|
|
24
|
+
toolInstance = new ToolClass(this.wordpressClients);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
toolInstance = new ToolClass();
|
|
28
|
+
}
|
|
29
|
+
const tools = toolInstance.getTools();
|
|
30
|
+
tools.forEach((tool) => {
|
|
31
|
+
this.registerTool(tool);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Register a single tool with parameter validation and execution handling
|
|
37
|
+
*/
|
|
38
|
+
registerTool(tool) {
|
|
39
|
+
// Create base parameter schema with site parameter
|
|
40
|
+
const baseSchema = {
|
|
41
|
+
site: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured.')
|
|
45
|
+
};
|
|
46
|
+
// Merge with tool-specific parameters
|
|
47
|
+
const parameterSchema = this.buildParameterSchema(tool, baseSchema);
|
|
48
|
+
// Make site parameter required if multiple sites are configured
|
|
49
|
+
if (this.wordpressClients.size > 1) {
|
|
50
|
+
parameterSchema.site = parameterSchema.site.describe('The ID of the WordPress site to target (from mcp-wordpress.config.json). Required when multiple sites are configured.');
|
|
51
|
+
}
|
|
52
|
+
this.server.tool(tool.name, tool.description || `WordPress tool: ${tool.name}`, parameterSchema, async (args) => {
|
|
53
|
+
try {
|
|
54
|
+
const siteId = args.site || 'default';
|
|
55
|
+
const client = this.wordpressClients.get(siteId);
|
|
56
|
+
if (!client) {
|
|
57
|
+
const availableSites = Array.from(this.wordpressClients.keys()).join(', ');
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: `Error: Site with ID '${siteId}' not found. Available sites: ${availableSites}`
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
isError: true
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Call the tool handler with the client and parameters
|
|
69
|
+
const result = await tool.handler(client, args);
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (this.isAuthenticationError(error)) {
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: 'text',
|
|
85
|
+
text: `Authentication failed for site '${args.site || 'default'}'. Please check your credentials.`
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
isError: true
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: 'text',
|
|
95
|
+
text: `Error: ${getErrorMessage(error)}`
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
isError: true
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Build Zod parameter schema from tool definition
|
|
105
|
+
*/
|
|
106
|
+
buildParameterSchema(tool, baseSchema) {
|
|
107
|
+
return tool.parameters?.reduce((schema, param) => {
|
|
108
|
+
let zodType = this.getZodTypeForParameter(param);
|
|
109
|
+
if (param.description) {
|
|
110
|
+
zodType = zodType.describe(param.description);
|
|
111
|
+
}
|
|
112
|
+
if (!param.required) {
|
|
113
|
+
zodType = zodType.optional();
|
|
114
|
+
}
|
|
115
|
+
schema[param.name] = zodType;
|
|
116
|
+
return schema;
|
|
117
|
+
}, { ...baseSchema }) || baseSchema;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get appropriate Zod type for parameter definition
|
|
121
|
+
*/
|
|
122
|
+
getZodTypeForParameter(param) {
|
|
123
|
+
switch (param.type) {
|
|
124
|
+
case 'string':
|
|
125
|
+
return z.string();
|
|
126
|
+
case 'number':
|
|
127
|
+
return z.number();
|
|
128
|
+
case 'boolean':
|
|
129
|
+
return z.boolean();
|
|
130
|
+
case 'array':
|
|
131
|
+
return z.array(z.string());
|
|
132
|
+
case 'object':
|
|
133
|
+
return z.record(z.any());
|
|
134
|
+
default:
|
|
135
|
+
return z.string();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Check if error is authentication-related
|
|
140
|
+
*/
|
|
141
|
+
isAuthenticationError(error) {
|
|
142
|
+
if (error?.response?.status && [401, 403].includes(error.response.status)) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return error?.code === 'WORDPRESS_AUTH_ERROR';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=ToolRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../src/server/ToolRegistry.ts"],"names":[],"mappings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AAC,MAAM,EAAE,CAAC;YACpB,KAAK,QAAQ;gBACX,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YACpB,KAAK,SAAS;gBACZ,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;YACrB,KAAK,OAAO;gBACV,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC7B,KAAK,QAAQ;gBACX,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YAC3B;gBACE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED;;OAEG;IACK,qBAAqB,CAAC,KAAU;QACtC,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,EAAE,IAAI,KAAK,sBAAsB,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { WordPressClient } from '../client/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tool parameter definition for MCP tools
|
|
4
|
+
*/
|
|
5
|
+
export interface ToolParameter {
|
|
6
|
+
name: string;
|
|
7
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
8
|
+
description: string;
|
|
9
|
+
enum?: string[];
|
|
10
|
+
items?: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
required?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* MCP Tool definition
|
|
17
|
+
*/
|
|
18
|
+
export interface MCPTool {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters: ToolParameter[];
|
|
22
|
+
handler: ToolHandler;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Tool handler function type
|
|
26
|
+
*/
|
|
27
|
+
export interface ToolHandler<TParams = any, TResult = string> {
|
|
28
|
+
(client: WordPressClient, params: TParams): Promise<TResult>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Base class for all WordPress tool implementations
|
|
32
|
+
* Provides common functionality and patterns used across tool classes
|
|
33
|
+
*/
|
|
34
|
+
export declare abstract class BaseToolClass {
|
|
35
|
+
/**
|
|
36
|
+
* Format a list response with consistent styling
|
|
37
|
+
*/
|
|
38
|
+
protected formatListResponse<T>(items: T[], entityName: string, formatter: (item: T) => string, totalCount?: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Format a single entity response
|
|
41
|
+
*/
|
|
42
|
+
protected formatDetailResponse(entity: any, entityName: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Format a success response for create/update operations
|
|
45
|
+
*/
|
|
46
|
+
protected formatSuccessResponse(action: string, entityName: string, entity: any): string;
|
|
47
|
+
/**
|
|
48
|
+
* Handle errors consistently across all tools
|
|
49
|
+
*/
|
|
50
|
+
protected handleError(error: unknown, operation: string): never;
|
|
51
|
+
/**
|
|
52
|
+
* Validate required parameters
|
|
53
|
+
*/
|
|
54
|
+
protected validateRequiredParams(params: any, requiredFields: string[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* Create common pagination parameters
|
|
57
|
+
*/
|
|
58
|
+
protected getPaginationParameters(): ToolParameter[];
|
|
59
|
+
/**
|
|
60
|
+
* Create common status parameter
|
|
61
|
+
*/
|
|
62
|
+
protected getStatusParameter(validStatuses: string[]): ToolParameter;
|
|
63
|
+
/**
|
|
64
|
+
* Create site parameter for multi-site support
|
|
65
|
+
*/
|
|
66
|
+
protected getSiteParameter(): ToolParameter;
|
|
67
|
+
/**
|
|
68
|
+
* Get the list of tools provided by this class
|
|
69
|
+
*/
|
|
70
|
+
abstract getTools(): MCPTool[];
|
|
71
|
+
/**
|
|
72
|
+
* Handle a tool request
|
|
73
|
+
*/
|
|
74
|
+
abstract handleTool(toolName: string, client: WordPressClient, params: any): Promise<string>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=BaseToolClass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseToolClass.d.ts","sourceRoot":"","sources":["../../src/tools/BaseToolClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,MAAM;IAC1D,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9D;AAED;;;GAGG;AACH,8BAAsB,aAAa;IACjC;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAC9B,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM;IAYT;;OAEG;IACH,SAAS,CAAC,oBAAoB,CAAC,MA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