claudeus-wp-mcp
Version:
The most comprehensive WordPress MCP server - 145 production-ready tools for complete WordPress management with AI
128 lines • 4.23 kB
JavaScript
/**
* WordPress Search & Discovery API Client
* Handles universal search, oEmbed, and block directory
*/
import axios from 'axios';
export class SearchApiClient {
client;
_site;
constructor(site) {
this._site = site;
this.client = axios.create({
baseURL: `${site.url}/wp-json`, // Base URL points to wp-json root
auth: site.authType === 'basic' ? {
username: site.username,
password: site.auth
} : undefined,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
...(site.authType === 'jwt' ? { 'Authorization': `Bearer ${site.auth}` } : {})
}
});
}
get site() {
return this._site;
}
// ==========================================
// UNIVERSAL SEARCH
// ==========================================
/**
* Universal search across all content types
* @param filters Search filters (search term, type, subtype, pagination)
*/
async search(filters) {
try {
const response = await this.client.get('/wp/v2/search', { params: filters });
return response.data;
}
catch (error) {
throw new Error(`Failed to search: ${error}`);
}
}
// ==========================================
// OEMBED
// ==========================================
/**
* Get oEmbed data for a URL
* @param url The URL to get oEmbed data for
* @param maxwidth Optional maximum width
* @param maxheight Optional maximum height
*/
async getOEmbed(url, maxwidth, maxheight) {
try {
const params = { url };
if (maxwidth)
params.maxwidth = maxwidth;
if (maxheight)
params.maxheight = maxheight;
const response = await this.client.get('/oembed/1.0/embed', { params });
return response.data;
}
catch (error) {
throw new Error(`Failed to get oEmbed data: ${error}`);
}
}
/**
* Get oEmbed data via proxy (for external URLs)
* @param url The external URL to get oEmbed data for
* @param maxwidth Optional maximum width
* @param maxheight Optional maximum height
*/
async getOEmbedProxy(url, maxwidth, maxheight) {
try {
const params = { url };
if (maxwidth)
params.maxwidth = maxwidth;
if (maxheight)
params.maxheight = maxheight;
const response = await this.client.get('/oembed/1.0/proxy', { params });
return response.data;
}
catch (error) {
throw new Error(`Failed to get oEmbed proxy data: ${error}`);
}
}
// ==========================================
// BLOCK EDITOR
// ==========================================
/**
* Get URL details for block editor
* Returns metadata about a URL for use in blocks (like link previews)
* @param url The URL to get details for
*/
async getURLDetails(url) {
try {
const response = await this.client.post('/wp-block-editor/v1/url-details', { url });
return response.data;
}
catch (error) {
throw new Error(`Failed to get URL details: ${error}`);
}
}
// ==========================================
// BLOCK DIRECTORY
// ==========================================
/**
* Search the WordPress.org block directory
* @param term Search term
* @param page Page number
* @param perPage Results per page
*/
async searchBlockDirectory(term, page = 1, perPage = 10) {
try {
const response = await this.client.get('/wp/v2/block-directory/search', {
params: {
term,
page,
per_page: perPage
}
});
return response.data;
}
catch (error) {
throw new Error(`Failed to search block directory: ${error}`);
}
}
}
//# sourceMappingURL=search.js.map