@myea/wordpress-mcp-handler
Version:
Advanced WordPress MCP request handler with intelligent search, multi-locale support, and comprehensive content management capabilities
121 lines • 4.08 kB
JavaScript
export const DEFAULT_WP_CONFIG = {
host: process.env.WP_HOST || 'http://localhost:8080',
endpoints: {
posts: '/wp-json/wp/v2/posts',
pages: '/wp-json/wp/v2/pages',
media: '/wp-json/wp/v2/media',
users: '/wp-json/wp/v2/users',
categories: '/wp-json/wp/v2/categories',
tags: '/wp-json/wp/v2/tags',
comments: '/wp-json/wp/v2/comments',
settings: '/wp-json/wp/v2/settings',
themes: '/wp-json/wp/v2/themes',
plugins: '/wp-json/wp/v2/plugins',
search: '/wp-json/wp/v2/search',
},
authentication: {
type: process.env.WP_AUTH_TYPE || 'application_password',
username: process.env.WP_USERNAME || 'admin',
password: process.env.WP_PASSWORD || '',
applicationPassword: process.env.WP_APPLICATION_PASSWORD || '',
jwtSecret: process.env.WP_JWT_SECRET || '',
jwtToken: process.env.WP_JWT_TOKEN || '',
},
content: {
allowedPostTypes: process.env.WP_ALLOWED_POST_TYPES?.split(',') || [
'post',
'page',
'attachment',
'revision',
'nav_menu_item'
],
allowedStatuses: process.env.WP_ALLOWED_STATUSES?.split(',') || [
'publish',
'draft',
'private',
'pending',
'future'
],
defaultPostType: process.env.WP_DEFAULT_POST_TYPE || 'post',
maxUploadSize: parseInt(process.env.WP_MAX_UPLOAD_SIZE || '10485760'), // 10MB
allowedMimeTypes: process.env.WP_ALLOWED_MIME_TYPES?.split(',') || [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'application/pdf',
'text/plain',
'video/mp4',
'audio/mpeg'
],
},
queries: {
maxLimit: parseInt(process.env.WP_QUERY_MAX_LIMIT || '100'),
defaultLimit: parseInt(process.env.WP_QUERY_DEFAULT_LIMIT || '20'),
timeoutMs: parseInt(process.env.WP_QUERY_TIMEOUT || '30000'),
retryAttempts: parseInt(process.env.WP_RETRY_ATTEMPTS || '3'),
},
validation: {
maxDepth: parseInt(process.env.WP_MAX_DEPTH || '5'),
allowedLocales: process.env.WP_ALLOWED_LOCALES?.split(',') || [
'en_US', 'en_GB', 'fr_FR', 'de_DE', 'es_ES', 'it_IT', 'ja', 'ko_KR', 'zh_CN', 'pt_BR'
],
requireAuth: process.env.WP_REQUIRE_AUTH === 'true',
},
features: {
multisite: process.env.WP_MULTISITE === 'true',
customFields: process.env.WP_CUSTOM_FIELDS !== 'false',
taxonomies: process.env.WP_TAXONOMIES !== 'false',
media: process.env.WP_MEDIA !== 'false',
comments: process.env.WP_COMMENTS !== 'false',
},
};
/**
* Get WordPress configuration with environment overrides
*/
export function getWordPressConfig() {
return DEFAULT_WP_CONFIG;
}
/**
* Validate if a post type is allowed
*/
export function isValidPostType(postType, config = DEFAULT_WP_CONFIG) {
return config.content.allowedPostTypes.includes(postType);
}
/**
* Validate if a status is allowed
*/
export function isValidStatus(status, config = DEFAULT_WP_CONFIG) {
return config.content.allowedStatuses.includes(status);
}
/**
* Validate if a locale is supported
*/
export function isValidLocale(locale, config = DEFAULT_WP_CONFIG) {
return config.validation.allowedLocales.includes(locale);
}
/**
* Validate if a MIME type is allowed
*/
export function isValidMimeType(mimeType, config = DEFAULT_WP_CONFIG) {
return config.content.allowedMimeTypes.includes(mimeType);
}
/**
* Get the full URL for an endpoint
*/
export function getEndpointUrl(endpoint, config = DEFAULT_WP_CONFIG) {
return `${config.host}${config.endpoints[endpoint]}`;
}
/**
* Validate WordPress host URL
*/
export function isValidWordPressHost(host) {
try {
const url = new URL(host);
return ['http:', 'https:'].includes(url.protocol);
}
catch {
return false;
}
}
//# sourceMappingURL=wordpress-config.js.map