# API Reference Complete technical reference for the MCP WordPress Server API, tools, and interfaces. ## ๐Ÿ”ง Core API Classes ### WordPressClient Primary interface for WordPress REST API communication. ```typescript class WordPressClient { constructor(config: ClientConfig); // Core managers auth: AuthenticationManager; request: RequestManager; cache: CacheManager; // Content APIs posts: PostsAPI; pages: PagesAPI; media: MediaAPI; users: UsersAPI; comments: CommentsAPI; taxonomies: TaxonomiesAPI; // Site management settings: SettingsAPI; plugins: PluginsAPI; themes: ThemesAPI; } ``` **Configuration Interface**: ```typescript interface ClientConfig { siteUrl: string; username: string; password?: string; appPassword?: string; authMethod?: "app-password" | "jwt" | "basic" | "api-key"; timeout?: number; retryAttempts?: number; cacheEnabled?: boolean; debug?: boolean; } ``` ### AuthenticationManager Handles multiple WordPress authentication methods. ```typescript class AuthenticationManager { // Authentication methods async authenticateWithAppPassword(username: string, password: string): Promise; async authenticateWithJWT(username: string, password: string): Promise; async authenticateWithBasic(username: string, password: string): Promise; async authenticateWithApiKey(apiKey: string): Promise; // Token management async refreshToken(): Promise; async validateToken(token: string): Promise; async revokeToken(token: string): Promise; // Headers getAuthHeaders(): Record; isAuthenticated(): boolean; } ``` ### RequestManager HTTP request handling with retry logic and rate limiting. ```typescript class RequestManager { // HTTP methods async get(endpoint: string, params?: QueryParams): Promise; async post(endpoint: string, data?: any): Promise; async put(endpoint: string, data?: any): Promise; async patch(endpoint: string, data?: any): Promise; async delete(endpoint: string): Promise; // Batch operations async batchRequest(requests: BatchRequest[]): Promise; // File uploads async uploadFile(file: File, options?: UploadOptions): Promise; // Rate limiting async waitForRateLimit(): Promise; getRateLimitStatus(): RateLimitStatus; } ``` ## ๐Ÿ“ MCP Tools API ### Tool Categories #### Posts Tools (PostTools) ```typescript class PostTools { // Content management async createPost(params: CreatePostParams): Promise; async updatePost(params: UpdatePostParams): Promise; async deletePost(params: DeletePostParams): Promise; async getPost(params: GetPostParams): Promise; async listPosts(params: ListPostsParams): Promise; async getPostRevisions(params: GetPostRevisionsParams): Promise; } ``` **Parameter Interfaces**: ```typescript interface CreatePostParams { title: string; content?: string; excerpt?: string; status?: "draft" | "publish" | "private" | "pending"; author?: number; categories?: number[]; tags?: number[]; featured_media?: number; meta?: Record; site?: string; // Multi-site support } interface PostResult { id: number; title: string; content: string; excerpt: string; status: string; author: number; date: string; modified: string; link: string; slug: string; categories: number[]; tags: number[]; featured_media: number; meta: Record; } ``` #### Pages Tools (PageTools) ```typescript class PageTools { async createPage(params: CreatePageParams): Promise; async updatePage(params: UpdatePageParams): Promise; async deletePage(params: DeletePageParams): Promise; async getPage(params: GetPageParams): Promise; async listPages(params: ListPagesParams): Promise; async getPageRevisions(params: GetPageRevisionsParams): Promise; } ``` #### Media Tools (MediaTools) ```typescript class MediaTools { async uploadMedia(params: UploadMediaParams): Promise; async updateMedia(params: UpdateMediaParams): Promise; async deleteMedia(params: DeleteMediaParams): Promise; async getMedia(params: GetMediaParams): Promise; async listMedia(params: ListMediaParams): Promise; } ``` **Upload Parameters**: ```typescript interface UploadMediaParams { file: string | Buffer; // File path or buffer filename?: string; title?: string; alt_text?: string; caption?: string; description?: string; post?: number; // Attach to specific post site?: string; } ``` #### Users Tools (UserTools) ```typescript class UserTools { async createUser(params: CreateUserParams): Promise; async updateUser(params: UpdateUserParams): Promise; async deleteUser(params: DeleteUserParams): Promise; async getUser(params: GetUserParams): Promise; async listUsers(params: ListUsersParams): Promise; async getCurrentUser(params: GetCurrentUserParams): Promise; } ``` #### Comments Tools (CommentTools) ```typescript class CommentTools { async createComment(params: CreateCommentParams): Promise; async updateComment(params: UpdateCommentParams): Promise; async deleteComment(params: DeleteCommentParams): Promise; async getComment(params: GetCommentParams): Promise; async listComments(params: ListCommentsParams): Promise; async moderateComment(params: ModerateCommentParams): Promise; async bulkModerateComments(params: BulkModerateCommentsParams): Promise; } ``` #### Taxonomies Tools (TaxonomyTools) ```typescript class TaxonomyTools { // Categories async createCategory(params: CreateCategoryParams): Promise; async updateCategory(params: UpdateCategoryParams): Promise; async deleteCategory(params: DeleteCategoryParams): Promise; async getCategory(params: GetCategoryParams): Promise; async listCategories(params: ListCategoriesParams): Promise; // Tags async createTag(params: CreateTagParams): Promise; async updateTag(params: UpdateTagParams): Promise; async deleteTag(params: DeleteTagParams): Promise; async getTag(params: GetTagParams): Promise; async listTags(params: ListTagsParams): Promise; } ``` #### Site Tools (SiteTools) ```typescript class SiteTools { async getSiteInfo(params: GetSiteInfoParams): Promise; async updateSiteSettings(params: UpdateSiteSettingsParams): Promise; async getSiteStats(params: GetSiteStatsParams): Promise; async getPlugins(params: GetPluginsParams): Promise; async getThemes(params: GetThemesParams): Promise; async searchContent(params: SearchContentParams): Promise; } ``` #### Authentication Tools (AuthTools) ```typescript class AuthTools { async testAuth(params: TestAuthParams): Promise; async refreshToken(params: RefreshTokenParams): Promise; async validatePermissions(params: ValidatePermissionsParams): Promise; } ``` #### Cache Tools (CacheTools) ```typescript class CacheTools { async getCacheStats(params: GetCacheStatsParams): Promise; async clearCache(params: ClearCacheParams): Promise; async warmCache(params: WarmCacheParams): Promise; async setCacheConfig(params: SetCacheConfigParams): Promise; } ``` #### Performance Tools (PerformanceTools) ```typescript class PerformanceTools { async getPerformanceMetrics(params: GetPerformanceMetricsParams): Promise; async runPerformanceTest(params: RunPerformanceTestParams): Promise; async getSystemHealth(params: GetSystemHealthParams): Promise; async benchmarkOperations(params: BenchmarkOperationsParams): Promise; async getOptimizationSuggestions(params: GetOptimizationSuggestionsParams): Promise; async monitorRealTimeMetrics(params: MonitorRealTimeMetricsParams): Promise; } ``` ## ๐Ÿ”’ Security API ### Input Validation All tools use Zod schemas for parameter validation: ```typescript const createPostSchema = z.object({ title: z.string().min(1).max(200), content: z.string().optional(), status: z.enum(["draft", "publish", "private", "pending"]).optional(), author: z.number().positive().optional(), categories: z.array(z.number().positive()).optional(), tags: z.array(z.number().positive()).optional(), site: z.string().optional(), }); ``` ### Error Handling ```typescript interface APIError { code: string; message: string; details?: any; statusCode?: number; } class WordPressAPIError extends Error { constructor( public code: string, message: string, public statusCode?: number, public details?: any, ) { super(message); this.name = "WordPressAPIError"; } } ``` ### Rate Limiting ```typescript interface RateLimitStatus { limit: number; remaining: number; reset: Date; retryAfter?: number; } class RateLimitManager { async checkRateLimit(endpoint: string): Promise; async waitForRateLimit(endpoint: string): Promise; isRateLimited(endpoint: string): boolean; } ``` ## ๐Ÿ“Š Performance API ### Metrics Collection ```typescript interface PerformanceMetric { timestamp: Date; operation: string; duration: number; endpoint: string; success: boolean; cacheHit?: boolean; error?: string; } class MetricsCollector { collect(metric: PerformanceMetric): void; getMetrics(filter?: MetricFilter): PerformanceMetric[]; getAggregatedMetrics(period: TimePeriod): AggregatedMetrics; } ``` ### Cache Management ```typescript interface CacheEntry { key: string; value: T; timestamp: Date; ttl: number; size: number; } class CacheManager { async get(key: string): Promise; async set(key: string, value: T, ttl?: number): Promise; async del(key: string): Promise; async clear(pattern?: string): Promise; // Cache statistics getStats(): CacheStats; getSize(): number; getHitRate(): number; } ``` ## ๐Ÿ› ๏ธ Configuration API ### Multi-Site Configuration ```typescript interface MultiSiteConfig { sites: SiteConfig[]; } interface SiteConfig { id: string; name: string; config: { WORDPRESS_SITE_URL: string; WORDPRESS_USERNAME: string; WORDPRESS_APP_PASSWORD: string; WORDPRESS_AUTH_METHOD?: AuthMethod; }; } ``` ### Environment Configuration ```typescript interface EnvironmentConfig { WORDPRESS_SITE_URL: string; WORDPRESS_USERNAME: string; WORDPRESS_APP_PASSWORD?: string; WORDPRESS_AUTH_METHOD?: AuthMethod; DEBUG?: boolean; CACHE_ENABLED?: boolean; CACHE_TTL?: number; REQUEST_TIMEOUT?: number; RETRY_ATTEMPTS?: number; } ``` ## ๐Ÿงช Testing API ### Test Utilities ```typescript class TestUtils { static createMockClient(config?: Partial): WordPressClient; static createMockPost(overrides?: Partial): Post; static createMockUser(overrides?: Partial): User; static generateTestData(schema: ZodSchema): T; } ``` ### Test Fixtures ```typescript interface TestFixtures { posts: Post[]; users: User[]; comments: Comment[]; categories: Category[]; tags: Tag[]; media: MediaItem[]; } class FixtureManager { static loadFixtures(): TestFixtures; static createTestSite(): Promise; static cleanupTestSite(site: TestSite): Promise; } ``` ## ๐Ÿ“š Type Definitions ### WordPress Types ```typescript interface Post { id: number; title: string; content: string; excerpt: string; status: PostStatus; author: number; date: string; modified: string; link: string; slug: string; categories: number[]; tags: number[]; featured_media: number; meta: Record; } interface User { id: number; username: string; email: string; first_name: string; last_name: string; nickname: string; description: string; link: string; avatar_urls: Record; roles: string[]; capabilities: Record; meta: Record; } interface Comment { id: number; post: number; parent: number; author: number; author_name: string; author_email: string; author_url: string; content: string; date: string; status: CommentStatus; meta: Record; } ``` ### MCP Types ```typescript interface MCPTool { name: string; description: string; inputSchema: JSONSchema; handler: ToolHandler; } interface ToolHandler { (params: any): Promise; } interface ToolResult { success: boolean; data?: any; error?: string; metadata?: Record; } ``` ## ๐Ÿ” Debugging API ### Debug Utilities ```typescript class DebugLogger { static log(level: LogLevel, message: string, context?: any): void; static error(error: Error, context?: any): void; static performance(operation: string, duration: number): void; static http(method: string, url: string, status: number, duration: number): void; } ``` ### Health Check API ```typescript interface HealthCheck { status: "healthy" | "degraded" | "unhealthy"; checks: { database: HealthStatus; cache: HealthStatus; authentication: HealthStatus; performance: HealthStatus; }; timestamp: Date; } class HealthChecker { async checkHealth(): Promise; async checkDatabase(): Promise; async checkCache(): Promise; async checkAuthentication(): Promise; } ``` ## ๐Ÿ“– Usage Examples ### Basic Client Usage ```typescript import { WordPressClient } from "mcp-wordpress"; const client = new WordPressClient({ siteUrl: "https://your-site.com", username: "admin", appPassword: "xxxx xxxx xxxx xxxx xxxx xxxx", authMethod: "app-password", }); // Create a post const post = await client.posts.create({ title: "My New Post", content: "This is the post content", status: "publish", }); ``` ### Multi-Site Usage ```typescript import { MCPWordPressServer } from "mcp-wordpress"; const server = new MCPWordPressServer({ sites: [ { id: "site1", name: "Main Site", config: { WORDPRESS_SITE_URL: "https://site1.com", WORDPRESS_USERNAME: "admin", WORDPRESS_APP_PASSWORD: "password1", }, }, { id: "site2", name: "Blog Site", config: { WORDPRESS_SITE_URL: "https://site2.com", WORDPRESS_USERNAME: "editor", WORDPRESS_APP_PASSWORD: "password2", }, }, ], }); ``` ## ๐Ÿ“š Further Reading - **[Architecture Guide](ARCHITECTURE.md)** - System design and patterns - **[Testing Guide](TESTING.md)** - Test suite and best practices - **[Security Guidelines](SECURITY_DEVELOPMENT.md)** - Security best practices - **[Performance Guide](PERFORMANCE_DEVELOPMENT.md)** - Performance optimization --- **Need more details?** This API reference covers the complete technical interface. For implementation examples, see the source code in `src/` directory.