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,952 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive API Documentation Auto-Generation System
|
|
3
|
+
* Extracts documentation from tool classes, types, and WordPress mappings
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as Tools from '../tools/index.js';
|
|
9
|
+
import type { ToolDefinition } from '../server/ToolRegistry.js';
|
|
10
|
+
|
|
11
|
+
export interface DocumentationConfig {
|
|
12
|
+
outputDir: string;
|
|
13
|
+
includeExamples: boolean;
|
|
14
|
+
includeWordPressMapping: boolean;
|
|
15
|
+
generateOpenAPI: boolean;
|
|
16
|
+
generateInteractiveHtml: boolean;
|
|
17
|
+
validateExamples: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ToolDocumentation {
|
|
21
|
+
name: string;
|
|
22
|
+
category: string;
|
|
23
|
+
description: string;
|
|
24
|
+
parameters: ParameterDocumentation[];
|
|
25
|
+
examples: ExampleUsage[];
|
|
26
|
+
wordpressEndpoint: string | undefined;
|
|
27
|
+
requiredPermissions: string[] | undefined;
|
|
28
|
+
returnType: string;
|
|
29
|
+
errorCodes: ErrorDocumentation[];
|
|
30
|
+
relatedTools: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ParameterDocumentation {
|
|
34
|
+
name: string;
|
|
35
|
+
type: string;
|
|
36
|
+
required: boolean;
|
|
37
|
+
description: string;
|
|
38
|
+
defaultValue: any;
|
|
39
|
+
allowedValues: string[] | undefined;
|
|
40
|
+
examples: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ExampleUsage {
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
command: string;
|
|
47
|
+
parameters: Record<string, any>;
|
|
48
|
+
expectedResponse: any;
|
|
49
|
+
errorExample?: {
|
|
50
|
+
scenario: string;
|
|
51
|
+
error: any;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ErrorDocumentation {
|
|
56
|
+
code: string;
|
|
57
|
+
message: string;
|
|
58
|
+
description: string;
|
|
59
|
+
resolution: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface DocumentationOutput {
|
|
63
|
+
tools: ToolDocumentation[];
|
|
64
|
+
categories: CategoryDocumentation[];
|
|
65
|
+
types: TypeDocumentation[];
|
|
66
|
+
openApiSpec: OpenAPISpecification | undefined;
|
|
67
|
+
summary: DocumentationSummary;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CategoryDocumentation {
|
|
71
|
+
name: string;
|
|
72
|
+
description: string;
|
|
73
|
+
toolCount: number;
|
|
74
|
+
tools: string[];
|
|
75
|
+
usagePatterns: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface TypeDocumentation {
|
|
79
|
+
name: string;
|
|
80
|
+
description: string;
|
|
81
|
+
properties: PropertyDocumentation[];
|
|
82
|
+
examples: any[];
|
|
83
|
+
wordpressSource?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface PropertyDocumentation {
|
|
87
|
+
name: string;
|
|
88
|
+
type: string;
|
|
89
|
+
required: boolean;
|
|
90
|
+
description: string;
|
|
91
|
+
format?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface OpenAPISpecification {
|
|
95
|
+
openapi: string;
|
|
96
|
+
info: any;
|
|
97
|
+
paths: Record<string, any>;
|
|
98
|
+
components: Record<string, any>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface DocumentationSummary {
|
|
102
|
+
totalTools: number;
|
|
103
|
+
totalCategories: number;
|
|
104
|
+
totalTypes: number;
|
|
105
|
+
lastUpdated: string;
|
|
106
|
+
version: string;
|
|
107
|
+
coverage: {
|
|
108
|
+
toolsWithExamples: number;
|
|
109
|
+
toolsWithWordPressMapping: number;
|
|
110
|
+
typesDocumented: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Main Documentation Generator
|
|
116
|
+
*/
|
|
117
|
+
export class DocumentationGenerator {
|
|
118
|
+
private config: DocumentationConfig;
|
|
119
|
+
private toolCategories: Map<string, string[]> = new Map();
|
|
120
|
+
private wordpressEndpoints: Map<string, string> = new Map();
|
|
121
|
+
|
|
122
|
+
constructor(config: Partial<DocumentationConfig> = {}) {
|
|
123
|
+
this.config = {
|
|
124
|
+
outputDir: 'docs/api',
|
|
125
|
+
includeExamples: true,
|
|
126
|
+
includeWordPressMapping: true,
|
|
127
|
+
generateOpenAPI: true,
|
|
128
|
+
generateInteractiveHtml: true,
|
|
129
|
+
validateExamples: false,
|
|
130
|
+
...config
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.initializeWordPressMapping();
|
|
134
|
+
this.initializeToolCategories();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generate complete documentation for all tools and types
|
|
139
|
+
*/
|
|
140
|
+
async generateFullDocumentation(): Promise<DocumentationOutput> {
|
|
141
|
+
console.log('🚀 Starting API documentation generation...');
|
|
142
|
+
|
|
143
|
+
const tools = await this.extractAllToolDocumentation();
|
|
144
|
+
const categories = this.generateCategoryDocumentation(tools);
|
|
145
|
+
const types = await this.extractTypeDocumentation();
|
|
146
|
+
|
|
147
|
+
let openApiSpec: OpenAPISpecification | undefined = undefined;
|
|
148
|
+
if (this.config.generateOpenAPI) {
|
|
149
|
+
openApiSpec = this.generateOpenAPISpecification(tools, types);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const summary = this.generateDocumentationSummary(tools, categories, types);
|
|
153
|
+
|
|
154
|
+
const output: DocumentationOutput = {
|
|
155
|
+
tools,
|
|
156
|
+
categories,
|
|
157
|
+
types,
|
|
158
|
+
openApiSpec,
|
|
159
|
+
summary
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Write documentation to files
|
|
163
|
+
await this.writeDocumentationFiles(output);
|
|
164
|
+
|
|
165
|
+
console.log(`✅ Documentation generation complete! ${tools.length} tools documented.`);
|
|
166
|
+
return output;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Extract documentation from all tool classes
|
|
171
|
+
*/
|
|
172
|
+
private async extractAllToolDocumentation(): Promise<ToolDocumentation[]> {
|
|
173
|
+
const toolDocs: ToolDocumentation[] = [];
|
|
174
|
+
|
|
175
|
+
// Iterate through all tool classes
|
|
176
|
+
for (const [className, ToolClass] of Object.entries(Tools)) {
|
|
177
|
+
try {
|
|
178
|
+
// Create tool instance
|
|
179
|
+
let toolInstance: any;
|
|
180
|
+
if (className === 'CacheTools' || className === 'PerformanceTools') {
|
|
181
|
+
// These tools need client map - use empty map for doc generation
|
|
182
|
+
toolInstance = new ToolClass(new Map());
|
|
183
|
+
} else {
|
|
184
|
+
toolInstance = new (ToolClass as new () => any)();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const toolDefinitions = toolInstance.getTools();
|
|
188
|
+
const category = this.extractCategoryFromClassName(className);
|
|
189
|
+
|
|
190
|
+
for (const toolDef of toolDefinitions) {
|
|
191
|
+
const doc = await this.extractToolDocumentation(toolDef, category, className);
|
|
192
|
+
toolDocs.push(doc);
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.warn(`⚠️ Failed to extract documentation for ${className}:`, error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return toolDocs.sort((a, b) => a.name.localeCompare(b.name));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Extract documentation for a single tool
|
|
204
|
+
*/
|
|
205
|
+
private async extractToolDocumentation(
|
|
206
|
+
toolDef: ToolDefinition,
|
|
207
|
+
category: string,
|
|
208
|
+
className: string
|
|
209
|
+
): Promise<ToolDocumentation> {
|
|
210
|
+
const parameters = this.extractParameterDocumentation(toolDef.parameters || []);
|
|
211
|
+
const examples = this.generateToolExamples(toolDef, category);
|
|
212
|
+
const wordpressEndpoint = this.wordpressEndpoints.get(toolDef.name);
|
|
213
|
+
const returnType = this.inferReturnType(toolDef.name, category);
|
|
214
|
+
const errorCodes = this.generateErrorDocumentation(toolDef.name);
|
|
215
|
+
const relatedTools = this.findRelatedTools(toolDef.name, category);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
name: toolDef.name,
|
|
219
|
+
category,
|
|
220
|
+
description: toolDef.description || `${category} tool: ${toolDef.name}`,
|
|
221
|
+
parameters,
|
|
222
|
+
examples,
|
|
223
|
+
wordpressEndpoint,
|
|
224
|
+
requiredPermissions: this.getRequiredPermissions(toolDef.name),
|
|
225
|
+
returnType,
|
|
226
|
+
errorCodes,
|
|
227
|
+
relatedTools
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Extract parameter documentation
|
|
233
|
+
*/
|
|
234
|
+
private extractParameterDocumentation(parameters: any[]): ParameterDocumentation[] {
|
|
235
|
+
return parameters.map(param => ({
|
|
236
|
+
name: param.name,
|
|
237
|
+
type: param.type || 'string',
|
|
238
|
+
required: param.required || false,
|
|
239
|
+
description: param.description || `${param.name} parameter`,
|
|
240
|
+
defaultValue: this.getDefaultValue(param),
|
|
241
|
+
allowedValues: this.getAllowedValues(param) || undefined,
|
|
242
|
+
examples: this.generateParameterExamples(param)
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Generate usage examples for tools
|
|
248
|
+
*/
|
|
249
|
+
private generateToolExamples(toolDef: ToolDefinition, category: string): ExampleUsage[] {
|
|
250
|
+
const examples: ExampleUsage[] = [];
|
|
251
|
+
|
|
252
|
+
// Basic usage example
|
|
253
|
+
const basicExample = this.generateBasicExample(toolDef, category);
|
|
254
|
+
if (basicExample) {
|
|
255
|
+
examples.push(basicExample);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Multi-site example (if applicable)
|
|
259
|
+
if (this.supportsMultiSite(toolDef)) {
|
|
260
|
+
const multiSiteExample = this.generateMultiSiteExample(toolDef, category);
|
|
261
|
+
if (multiSiteExample) {
|
|
262
|
+
examples.push(multiSiteExample);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Advanced example with all parameters
|
|
267
|
+
const advancedExample = this.generateAdvancedExample(toolDef, category);
|
|
268
|
+
if (advancedExample) {
|
|
269
|
+
examples.push(advancedExample);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return examples;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Generate basic usage example
|
|
277
|
+
*/
|
|
278
|
+
private generateBasicExample(toolDef: ToolDefinition, category: string): ExampleUsage | null {
|
|
279
|
+
const toolName = toolDef.name;
|
|
280
|
+
const basicParams: Record<string, any> = {};
|
|
281
|
+
|
|
282
|
+
// Add essential parameters
|
|
283
|
+
const requiredParams = (toolDef.parameters || []).filter(p => p.required);
|
|
284
|
+
for (const param of requiredParams.slice(0, 2)) { // Limit to 2 for basic example
|
|
285
|
+
basicParams[param.name] = this.generateExampleValue(param);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
title: `Basic ${category} Usage`,
|
|
290
|
+
description: `Simple example of using ${toolName}`,
|
|
291
|
+
command: toolName,
|
|
292
|
+
parameters: basicParams,
|
|
293
|
+
expectedResponse: this.generateExpectedResponse(toolName, category, 'basic'),
|
|
294
|
+
errorExample: {
|
|
295
|
+
scenario: 'Authentication failure',
|
|
296
|
+
error: {
|
|
297
|
+
error: 'Authentication failed',
|
|
298
|
+
message: 'Invalid credentials or insufficient permissions'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Generate multi-site example
|
|
306
|
+
*/
|
|
307
|
+
private generateMultiSiteExample(toolDef: ToolDefinition, category: string): ExampleUsage | null {
|
|
308
|
+
const params = { site: 'site1', ...this.getExampleParameters(toolDef, 1) };
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
title: `Multi-Site ${category} Usage`,
|
|
312
|
+
description: `Using ${toolDef.name} with specific site targeting`,
|
|
313
|
+
command: toolDef.name,
|
|
314
|
+
parameters: params,
|
|
315
|
+
expectedResponse: this.generateExpectedResponse(toolDef.name, category, 'multisite')
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Generate advanced example with all parameters
|
|
321
|
+
*/
|
|
322
|
+
private generateAdvancedExample(toolDef: ToolDefinition, category: string): ExampleUsage | null {
|
|
323
|
+
const allParams = this.getExampleParameters(toolDef, 'all');
|
|
324
|
+
|
|
325
|
+
if (Object.keys(allParams).length <= 2) {
|
|
326
|
+
return null; // Skip if not enough parameters for advanced example
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
title: `Advanced ${category} Configuration`,
|
|
331
|
+
description: 'Comprehensive example using all available parameters',
|
|
332
|
+
command: toolDef.name,
|
|
333
|
+
parameters: allParams,
|
|
334
|
+
expectedResponse: this.generateExpectedResponse(toolDef.name, category, 'advanced')
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Generate category documentation
|
|
340
|
+
*/
|
|
341
|
+
private generateCategoryDocumentation(tools: ToolDocumentation[]): CategoryDocumentation[] {
|
|
342
|
+
const categories = new Map<string, ToolDocumentation[]>();
|
|
343
|
+
|
|
344
|
+
// Group tools by category
|
|
345
|
+
for (const tool of tools) {
|
|
346
|
+
if (!categories.has(tool.category)) {
|
|
347
|
+
categories.set(tool.category, []);
|
|
348
|
+
}
|
|
349
|
+
categories.get(tool.category)!.push(tool);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return Array.from(categories.entries()).map(([categoryName, categoryTools]) => ({
|
|
353
|
+
name: categoryName,
|
|
354
|
+
description: this.getCategoryDescription(categoryName),
|
|
355
|
+
toolCount: categoryTools.length,
|
|
356
|
+
tools: categoryTools.map(t => t.name).sort(),
|
|
357
|
+
usagePatterns: this.generateUsagePatterns(categoryName, categoryTools)
|
|
358
|
+
}));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Extract type documentation from TypeScript definitions
|
|
363
|
+
*/
|
|
364
|
+
private async extractTypeDocumentation(): Promise<TypeDocumentation[]> {
|
|
365
|
+
// This would analyze TypeScript files to extract type information
|
|
366
|
+
// For now, we'll provide key WordPress and MCP types
|
|
367
|
+
return [
|
|
368
|
+
{
|
|
369
|
+
name: 'WordPressPost',
|
|
370
|
+
description: 'WordPress blog post object',
|
|
371
|
+
properties: [
|
|
372
|
+
{ name: 'id', type: 'number', required: true, description: 'Unique identifier' },
|
|
373
|
+
{ name: 'title', type: 'string', required: true, description: 'Post title' },
|
|
374
|
+
{ name: 'content', type: 'string', required: true, description: 'Post content' },
|
|
375
|
+
{ name: 'status', type: 'string', required: true, description: 'Publication status' }
|
|
376
|
+
],
|
|
377
|
+
examples: [this.generateWordPressPostExample()],
|
|
378
|
+
wordpressSource: '/wp-json/wp/v2/posts'
|
|
379
|
+
}
|
|
380
|
+
// Add more types as needed
|
|
381
|
+
];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Generate OpenAPI specification
|
|
386
|
+
*/
|
|
387
|
+
private generateOpenAPISpecification(
|
|
388
|
+
tools: ToolDocumentation[],
|
|
389
|
+
types: TypeDocumentation[]
|
|
390
|
+
): OpenAPISpecification {
|
|
391
|
+
const paths: Record<string, any> = {};
|
|
392
|
+
const components: Record<string, any> = {
|
|
393
|
+
schemas: {},
|
|
394
|
+
parameters: {},
|
|
395
|
+
responses: {}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// Convert tools to OpenAPI paths
|
|
399
|
+
for (const tool of tools) {
|
|
400
|
+
const path = `/tools/${tool.name}`;
|
|
401
|
+
paths[path] = {
|
|
402
|
+
post: {
|
|
403
|
+
summary: tool.description,
|
|
404
|
+
description: `Execute ${tool.name} MCP tool`,
|
|
405
|
+
tags: [tool.category],
|
|
406
|
+
requestBody: {
|
|
407
|
+
required: true,
|
|
408
|
+
content: {
|
|
409
|
+
'application/json': {
|
|
410
|
+
schema: this.generateParameterSchema(tool.parameters)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
responses: {
|
|
415
|
+
'200': {
|
|
416
|
+
description: 'Successful response',
|
|
417
|
+
content: {
|
|
418
|
+
'application/json': {
|
|
419
|
+
schema: { type: 'object' }
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
'400': {
|
|
424
|
+
description: 'Bad request - invalid parameters'
|
|
425
|
+
},
|
|
426
|
+
'401': {
|
|
427
|
+
description: 'Authentication failed'
|
|
428
|
+
},
|
|
429
|
+
'500': {
|
|
430
|
+
description: 'Internal server error'
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Add type schemas to components
|
|
438
|
+
for (const type of types) {
|
|
439
|
+
components.schemas[type.name] = this.convertTypeToJsonSchema(type);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
openapi: '3.0.3',
|
|
444
|
+
info: {
|
|
445
|
+
title: 'WordPress MCP Server API',
|
|
446
|
+
description: 'Model Context Protocol server for WordPress management',
|
|
447
|
+
version: '1.2.0',
|
|
448
|
+
contact: {
|
|
449
|
+
name: 'MCP WordPress',
|
|
450
|
+
url: 'https://github.com/docdyhr/mcp-wordpress'
|
|
451
|
+
},
|
|
452
|
+
license: {
|
|
453
|
+
name: 'MIT',
|
|
454
|
+
url: 'https://opensource.org/licenses/MIT'
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
paths,
|
|
458
|
+
components
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Write all documentation files
|
|
464
|
+
*/
|
|
465
|
+
private async writeDocumentationFiles(output: DocumentationOutput): Promise<void> {
|
|
466
|
+
const outputDir = this.config.outputDir;
|
|
467
|
+
|
|
468
|
+
// Ensure output directory exists
|
|
469
|
+
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
470
|
+
await fs.promises.mkdir(path.join(outputDir, 'tools'), { recursive: true });
|
|
471
|
+
await fs.promises.mkdir(path.join(outputDir, 'types'), { recursive: true });
|
|
472
|
+
await fs.promises.mkdir(path.join(outputDir, 'examples'), { recursive: true });
|
|
473
|
+
await fs.promises.mkdir(path.join(outputDir, 'categories'), { recursive: true });
|
|
474
|
+
|
|
475
|
+
// Write main API documentation
|
|
476
|
+
await this.writeApiOverview(output);
|
|
477
|
+
|
|
478
|
+
// Write individual tool documentation
|
|
479
|
+
for (const tool of output.tools) {
|
|
480
|
+
await this.writeToolDocumentation(tool);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Write category documentation
|
|
484
|
+
for (const category of output.categories) {
|
|
485
|
+
await this.writeCategoryDocumentation(category);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Write type documentation
|
|
489
|
+
for (const type of output.types) {
|
|
490
|
+
await this.writeTypeDocumentation(type);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Write OpenAPI specification
|
|
494
|
+
if (output.openApiSpec) {
|
|
495
|
+
await fs.promises.writeFile(
|
|
496
|
+
path.join(outputDir, 'openapi.json'),
|
|
497
|
+
JSON.stringify(output.openApiSpec, null, 2)
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Write summary
|
|
502
|
+
await fs.promises.writeFile(
|
|
503
|
+
path.join(outputDir, 'summary.json'),
|
|
504
|
+
JSON.stringify(output.summary, null, 2)
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
console.log(`📁 Documentation written to ${outputDir}/`);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Helper methods for specific documentation tasks...
|
|
511
|
+
|
|
512
|
+
private extractCategoryFromClassName(className: string): string {
|
|
513
|
+
return className.replace('Tools', '').toLowerCase();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private initializeWordPressMapping(): void {
|
|
517
|
+
// Map MCP tools to WordPress REST API endpoints
|
|
518
|
+
this.wordpressEndpoints.set('wp_list_posts', '/wp-json/wp/v2/posts');
|
|
519
|
+
this.wordpressEndpoints.set('wp_get_post', '/wp-json/wp/v2/posts/{id}');
|
|
520
|
+
this.wordpressEndpoints.set('wp_create_post', '/wp-json/wp/v2/posts');
|
|
521
|
+
this.wordpressEndpoints.set('wp_update_post', '/wp-json/wp/v2/posts/{id}');
|
|
522
|
+
this.wordpressEndpoints.set('wp_delete_post', '/wp-json/wp/v2/posts/{id}');
|
|
523
|
+
// Add more mappings...
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
private initializeToolCategories(): void {
|
|
527
|
+
this.toolCategories.set('Posts', ['wp_list_posts', 'wp_get_post', 'wp_create_post', 'wp_update_post', 'wp_delete_post', 'wp_search_posts']);
|
|
528
|
+
this.toolCategories.set('Pages', ['wp_list_pages', 'wp_get_page', 'wp_create_page', 'wp_update_page', 'wp_delete_page', 'wp_search_pages']);
|
|
529
|
+
// Add more categories...
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private generateDocumentationSummary(
|
|
533
|
+
tools: ToolDocumentation[],
|
|
534
|
+
categories: CategoryDocumentation[],
|
|
535
|
+
types: TypeDocumentation[]
|
|
536
|
+
): DocumentationSummary {
|
|
537
|
+
return {
|
|
538
|
+
totalTools: tools.length,
|
|
539
|
+
totalCategories: categories.length,
|
|
540
|
+
totalTypes: types.length,
|
|
541
|
+
lastUpdated: new Date().toISOString(),
|
|
542
|
+
version: '1.2.0',
|
|
543
|
+
coverage: {
|
|
544
|
+
toolsWithExamples: tools.filter(t => t.examples.length > 0).length,
|
|
545
|
+
toolsWithWordPressMapping: tools.filter(t => t.wordpressEndpoint).length,
|
|
546
|
+
typesDocumented: types.length
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Helper methods for documentation generation
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
private getDefaultValue(param: any): any {
|
|
556
|
+
const defaults: Record<string, any> = {
|
|
557
|
+
'per_page': 10,
|
|
558
|
+
'page': 1,
|
|
559
|
+
'order': 'desc',
|
|
560
|
+
'orderby': 'date',
|
|
561
|
+
'status': 'publish',
|
|
562
|
+
'format': 'summary',
|
|
563
|
+
'category': 'all',
|
|
564
|
+
'includeExamples': true,
|
|
565
|
+
'includeTrends': true
|
|
566
|
+
};
|
|
567
|
+
return defaults[param.name];
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
private getAllowedValues(param: any): string[] | undefined {
|
|
571
|
+
const allowedValues: Record<string, string[]> = {
|
|
572
|
+
'status': ['publish', 'draft', 'private', 'pending', 'future'],
|
|
573
|
+
'order': ['asc', 'desc'],
|
|
574
|
+
'orderby': ['date', 'title', 'author', 'modified'],
|
|
575
|
+
'format': ['summary', 'detailed', 'raw'],
|
|
576
|
+
'category': ['overview', 'requests', 'cache', 'system', 'tools', 'all'],
|
|
577
|
+
'timeframe': ['1h', '6h', '12h', '24h', '7d', '30d'],
|
|
578
|
+
'priority': ['quick_wins', 'medium_term', 'long_term', 'all'],
|
|
579
|
+
'focus': ['speed', 'reliability', 'efficiency', 'scaling']
|
|
580
|
+
};
|
|
581
|
+
return allowedValues[param.name];
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
private generateParameterExamples(param: any): string[] {
|
|
585
|
+
const examples: Record<string, string[]> = {
|
|
586
|
+
'id': ['123', '456'],
|
|
587
|
+
'title': ['My Blog Post', 'Hello World'],
|
|
588
|
+
'content': ['<p>Post content here</p>', 'This is my post content'],
|
|
589
|
+
'site': ['site1', 'production', 'staging'],
|
|
590
|
+
'per_page': ['10', '20', '50'],
|
|
591
|
+
'search': ['wordpress', 'tutorial'],
|
|
592
|
+
'author': ['1', '2'],
|
|
593
|
+
'email': ['user@example.com', 'admin@site.com'],
|
|
594
|
+
'username': ['john_doe', 'admin'],
|
|
595
|
+
'limit': ['10', '20', '50'],
|
|
596
|
+
'timeframe': ['24h', '7d', '1h']
|
|
597
|
+
};
|
|
598
|
+
return examples[param.name] || ['example'];
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
private supportsMultiSite(toolDef: ToolDefinition): boolean {
|
|
602
|
+
// All tools support multi-site via the site parameter
|
|
603
|
+
return toolDef.parameters?.some(p => p.name === 'site') ?? true;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
private generateExampleValue(param: any): any {
|
|
607
|
+
const exampleValues: Record<string, any> = {
|
|
608
|
+
'id': 123,
|
|
609
|
+
'title': 'Example Post Title',
|
|
610
|
+
'content': 'This is example content for the post.',
|
|
611
|
+
'site': 'site1',
|
|
612
|
+
'per_page': 10,
|
|
613
|
+
'page': 1,
|
|
614
|
+
'search': 'wordpress',
|
|
615
|
+
'author': 1,
|
|
616
|
+
'email': 'user@example.com',
|
|
617
|
+
'username': 'john_doe',
|
|
618
|
+
'status': 'publish',
|
|
619
|
+
'order': 'desc',
|
|
620
|
+
'orderby': 'date',
|
|
621
|
+
'limit': 20,
|
|
622
|
+
'timeframe': '24h',
|
|
623
|
+
'format': 'summary',
|
|
624
|
+
'category': 'overview'
|
|
625
|
+
};
|
|
626
|
+
return exampleValues[param.name] || 'example_value';
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
private generateExpectedResponse(toolName: string, category: string, type: string): any {
|
|
630
|
+
if (toolName.includes('list')) {
|
|
631
|
+
return {
|
|
632
|
+
success: true,
|
|
633
|
+
data: [
|
|
634
|
+
{ id: 1, title: `Example ${category} 1`, status: 'publish' },
|
|
635
|
+
{ id: 2, title: `Example ${category} 2`, status: 'draft' }
|
|
636
|
+
],
|
|
637
|
+
total: 2,
|
|
638
|
+
pages: 1
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (toolName.includes('get')) {
|
|
643
|
+
return {
|
|
644
|
+
success: true,
|
|
645
|
+
data: {
|
|
646
|
+
id: 123,
|
|
647
|
+
title: `Example ${category}`,
|
|
648
|
+
content: 'Example content',
|
|
649
|
+
status: 'publish',
|
|
650
|
+
date: '2024-01-01T00:00:00Z'
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if (toolName.includes('create') || toolName.includes('update')) {
|
|
656
|
+
return {
|
|
657
|
+
success: true,
|
|
658
|
+
data: {
|
|
659
|
+
id: 123,
|
|
660
|
+
title: 'Created/Updated successfully',
|
|
661
|
+
status: 'publish'
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (toolName.includes('delete')) {
|
|
667
|
+
return {
|
|
668
|
+
success: true,
|
|
669
|
+
data: {
|
|
670
|
+
deleted: true,
|
|
671
|
+
id: 123
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (toolName.includes('performance')) {
|
|
677
|
+
return {
|
|
678
|
+
success: true,
|
|
679
|
+
data: {
|
|
680
|
+
overview: {
|
|
681
|
+
overallHealth: 'Good',
|
|
682
|
+
performanceScore: 85,
|
|
683
|
+
averageResponseTime: '245ms',
|
|
684
|
+
cacheHitRate: '87.5%'
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return {
|
|
691
|
+
success: true,
|
|
692
|
+
data: {},
|
|
693
|
+
message: `${toolName} executed successfully`
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
private getExampleParameters(toolDef: ToolDefinition, type: string | number): Record<string, any> {
|
|
698
|
+
const params: Record<string, any> = {};
|
|
699
|
+
const parameters = toolDef.parameters || [];
|
|
700
|
+
|
|
701
|
+
if (type === 'all') {
|
|
702
|
+
// Include all parameters
|
|
703
|
+
for (const param of parameters) {
|
|
704
|
+
params[param.name] = this.generateExampleValue(param);
|
|
705
|
+
}
|
|
706
|
+
} else if (typeof type === 'number') {
|
|
707
|
+
// Include limited number of parameters
|
|
708
|
+
for (const param of parameters.slice(0, type)) {
|
|
709
|
+
params[param.name] = this.generateExampleValue(param);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
return params;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
private getCategoryDescription(categoryName: string): string {
|
|
717
|
+
const descriptions: Record<string, string> = {
|
|
718
|
+
'posts': 'Blog post creation, editing, and management tools',
|
|
719
|
+
'pages': 'Static page creation and management tools',
|
|
720
|
+
'media': 'File upload, management, and media library tools',
|
|
721
|
+
'users': 'User account management and authentication tools',
|
|
722
|
+
'comments': 'Comment moderation and management tools',
|
|
723
|
+
'taxonomies': 'Category and tag management tools',
|
|
724
|
+
'site': 'Site settings and configuration tools',
|
|
725
|
+
'auth': 'Authentication testing and management tools',
|
|
726
|
+
'cache': 'Performance caching and optimization tools',
|
|
727
|
+
'performance': 'Performance monitoring and analytics tools'
|
|
728
|
+
};
|
|
729
|
+
return descriptions[categoryName.toLowerCase()] || `${categoryName} management tools`;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
private generateUsagePatterns(categoryName: string, tools: ToolDocumentation[]): string[] {
|
|
733
|
+
const patterns: Record<string, string[]> = {
|
|
734
|
+
'posts': [
|
|
735
|
+
'Create and publish blog posts',
|
|
736
|
+
'Bulk edit multiple posts',
|
|
737
|
+
'Search and filter posts by criteria',
|
|
738
|
+
'Schedule posts for future publication'
|
|
739
|
+
],
|
|
740
|
+
'media': [
|
|
741
|
+
'Upload images and files',
|
|
742
|
+
'Organize media library',
|
|
743
|
+
'Generate thumbnails and variants',
|
|
744
|
+
'Bulk media operations'
|
|
745
|
+
],
|
|
746
|
+
'users': [
|
|
747
|
+
'Manage user accounts and roles',
|
|
748
|
+
'User authentication and permissions',
|
|
749
|
+
'Bulk user operations',
|
|
750
|
+
'User profile management'
|
|
751
|
+
],
|
|
752
|
+
'performance': [
|
|
753
|
+
'Monitor real-time performance metrics',
|
|
754
|
+
'Analyze historical performance trends',
|
|
755
|
+
'Generate optimization recommendations',
|
|
756
|
+
'Export performance reports'
|
|
757
|
+
]
|
|
758
|
+
};
|
|
759
|
+
return patterns[categoryName.toLowerCase()] || [
|
|
760
|
+
`Manage ${categoryName.toLowerCase()} efficiently`,
|
|
761
|
+
`Bulk ${categoryName.toLowerCase()} operations`,
|
|
762
|
+
`Search and filter ${categoryName.toLowerCase()}`
|
|
763
|
+
];
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
private generateWordPressPostExample(): any {
|
|
767
|
+
return {
|
|
768
|
+
id: 123,
|
|
769
|
+
title: 'Welcome to WordPress',
|
|
770
|
+
content: '<p>This is your first post. Edit or delete it to get started!</p>',
|
|
771
|
+
status: 'publish',
|
|
772
|
+
date: '2024-01-01T00:00:00Z',
|
|
773
|
+
author: 1,
|
|
774
|
+
categories: [1],
|
|
775
|
+
tags: [1, 2],
|
|
776
|
+
featured_media: 0,
|
|
777
|
+
excerpt: 'A sample WordPress post',
|
|
778
|
+
slug: 'welcome-to-wordpress'
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
private generateParameterSchema(parameters: ParameterDocumentation[]): any {
|
|
783
|
+
const properties: Record<string, any> = {};
|
|
784
|
+
const required: string[] = [];
|
|
785
|
+
|
|
786
|
+
for (const param of parameters) {
|
|
787
|
+
properties[param.name] = {
|
|
788
|
+
type: param.type,
|
|
789
|
+
description: param.description
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
if (param.allowedValues) {
|
|
793
|
+
properties[param.name].enum = param.allowedValues;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if (param.defaultValue !== undefined) {
|
|
797
|
+
properties[param.name].default = param.defaultValue;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
if (param.required) {
|
|
801
|
+
required.push(param.name);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
return {
|
|
806
|
+
type: 'object',
|
|
807
|
+
properties,
|
|
808
|
+
required: required.length > 0 ? required : undefined
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
private convertTypeToJsonSchema(type: TypeDocumentation): any {
|
|
813
|
+
const properties: Record<string, any> = {};
|
|
814
|
+
const required: string[] = [];
|
|
815
|
+
|
|
816
|
+
for (const prop of type.properties) {
|
|
817
|
+
properties[prop.name] = {
|
|
818
|
+
type: prop.type,
|
|
819
|
+
description: prop.description
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
if (prop.format) {
|
|
823
|
+
properties[prop.name].format = prop.format;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
if (prop.required) {
|
|
827
|
+
required.push(prop.name);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
return {
|
|
832
|
+
type: 'object',
|
|
833
|
+
description: type.description,
|
|
834
|
+
properties,
|
|
835
|
+
required: required.length > 0 ? required : undefined
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
private inferReturnType(toolName: string, category: string): string {
|
|
840
|
+
if (toolName.includes('list')) return `${category}[]`;
|
|
841
|
+
if (toolName.includes('get')) return category;
|
|
842
|
+
if (toolName.includes('create')) return category;
|
|
843
|
+
if (toolName.includes('update')) return category;
|
|
844
|
+
if (toolName.includes('delete')) return 'DeleteResult';
|
|
845
|
+
if (toolName.includes('search')) return `${category}[]`;
|
|
846
|
+
if (toolName.includes('performance')) return 'PerformanceMetrics';
|
|
847
|
+
if (toolName.includes('cache')) return 'CacheStats';
|
|
848
|
+
return 'object';
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
private generateErrorDocumentation(toolName: string): ErrorDocumentation[] {
|
|
852
|
+
return [
|
|
853
|
+
{
|
|
854
|
+
code: 'AUTHENTICATION_FAILED',
|
|
855
|
+
message: 'Authentication failed',
|
|
856
|
+
description: 'Invalid credentials or insufficient permissions',
|
|
857
|
+
resolution: 'Check your authentication credentials and user permissions'
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
code: 'VALIDATION_ERROR',
|
|
861
|
+
message: 'Parameter validation failed',
|
|
862
|
+
description: 'One or more required parameters are missing or invalid',
|
|
863
|
+
resolution: 'Review the required parameters and their formats'
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
code: 'NOT_FOUND',
|
|
867
|
+
message: 'Resource not found',
|
|
868
|
+
description: 'The requested resource does not exist',
|
|
869
|
+
resolution: 'Verify the resource ID and ensure it exists'
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
code: 'PERMISSION_DENIED',
|
|
873
|
+
message: 'Insufficient permissions',
|
|
874
|
+
description: 'The user does not have permission to perform this action',
|
|
875
|
+
resolution: 'Contact an administrator to grant the necessary permissions'
|
|
876
|
+
}
|
|
877
|
+
];
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
private findRelatedTools(toolName: string, category: string): string[] {
|
|
881
|
+
// Find tools in the same category
|
|
882
|
+
const categoryTools = this.toolCategories.get(category) || [];
|
|
883
|
+
return categoryTools.filter(tool => tool !== toolName).slice(0, 3);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
private getRequiredPermissions(toolName: string): string[] | undefined {
|
|
887
|
+
const permissions: Record<string, string[]> = {
|
|
888
|
+
'wp_create_post': ['publish_posts', 'edit_posts'],
|
|
889
|
+
'wp_update_post': ['edit_posts'],
|
|
890
|
+
'wp_delete_post': ['delete_posts'],
|
|
891
|
+
'wp_create_page': ['publish_pages', 'edit_pages'],
|
|
892
|
+
'wp_update_page': ['edit_pages'],
|
|
893
|
+
'wp_delete_page': ['delete_pages'],
|
|
894
|
+
'wp_upload_media': ['upload_files'],
|
|
895
|
+
'wp_delete_media': ['delete_files'],
|
|
896
|
+
'wp_create_user': ['create_users'],
|
|
897
|
+
'wp_update_user': ['edit_users'],
|
|
898
|
+
'wp_delete_user': ['delete_users'],
|
|
899
|
+
'wp_moderate_comment': ['moderate_comments'],
|
|
900
|
+
'wp_get_site_settings': ['manage_options']
|
|
901
|
+
};
|
|
902
|
+
return permissions[toolName];
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* File writing implementations
|
|
907
|
+
*/
|
|
908
|
+
|
|
909
|
+
private async writeApiOverview(output: DocumentationOutput): Promise<void> {
|
|
910
|
+
const { MarkdownFormatter } = await import('./MarkdownFormatter.js');
|
|
911
|
+
const formatter = new MarkdownFormatter();
|
|
912
|
+
const content = formatter.generateApiOverview(output);
|
|
913
|
+
|
|
914
|
+
await fs.promises.writeFile(
|
|
915
|
+
path.join(this.config.outputDir, 'README.md'),
|
|
916
|
+
content
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
private async writeToolDocumentation(tool: ToolDocumentation): Promise<void> {
|
|
921
|
+
const { MarkdownFormatter } = await import('./MarkdownFormatter.js');
|
|
922
|
+
const formatter = new MarkdownFormatter();
|
|
923
|
+
const content = formatter.generateToolDocumentation(tool);
|
|
924
|
+
|
|
925
|
+
await fs.promises.writeFile(
|
|
926
|
+
path.join(this.config.outputDir, 'tools', `${tool.name}.md`),
|
|
927
|
+
content
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
private async writeCategoryDocumentation(category: CategoryDocumentation): Promise<void> {
|
|
932
|
+
const { MarkdownFormatter } = await import('./MarkdownFormatter.js');
|
|
933
|
+
const formatter = new MarkdownFormatter();
|
|
934
|
+
const content = formatter.generateCategoryDocumentation(category);
|
|
935
|
+
|
|
936
|
+
await fs.promises.writeFile(
|
|
937
|
+
path.join(this.config.outputDir, 'categories', `${category.name.toLowerCase()}.md`),
|
|
938
|
+
content
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
private async writeTypeDocumentation(type: TypeDocumentation): Promise<void> {
|
|
943
|
+
const { MarkdownFormatter } = await import('./MarkdownFormatter.js');
|
|
944
|
+
const formatter = new MarkdownFormatter();
|
|
945
|
+
const content = formatter.generateTypeDocumentation(type);
|
|
946
|
+
|
|
947
|
+
await fs.promises.writeFile(
|
|
948
|
+
path.join(this.config.outputDir, 'types', `${type.name}.md`),
|
|
949
|
+
content
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
}
|