wp_list_pages
Retrieve and filter WordPress pages from a configured site using parameters like search terms, status, and pagination for site management.
Instructions
Lists pages from a WordPress site, with filters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| per_page | No | Number of items to return per page (max 100). | |
| search | No | Limit results to those matching a search term. | |
| status | No | Filter by page status. |
Implementation Reference
- src/tools/pages.ts:156-170 (handler)The handler function that implements the core logic of the wp_list_pages tool. It queries the WordPress client for pages using provided parameters, formats a list of pages with IDs, titles, status, and links, or returns a no-pages message on empty results.public async handleListPages(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const queryParams = params as unknown as PageQueryParams; try { const pages = await client.getPages(queryParams); if (pages.length === 0) { return "No pages found matching the criteria."; } const content = `Found ${pages.length} pages:\n\n` + pages.map((p) => `- ID ${p.id}: **${p.title.rendered}** (${p.status})\n Link: ${p.link}`).join("\n"); return content; } catch (_error) { throw new Error(`Failed to list pages: ${getErrorMessage(_error)}`); } }
- src/tools/pages.ts:28-50 (registration)The tool registration within PageTools.getTools(), defining the name, description, input parameters schema (per_page, search, status), and binding to the handleListPages handler.{ name: "wp_list_pages", description: "Lists pages from a WordPress site, with filters.", parameters: [ { name: "per_page", type: "number", description: "Number of items to return per page (max 100).", }, { name: "search", type: "string", description: "Limit results to those matching a search term.", }, { name: "status", type: "string", description: "Filter by page status.", enum: ["publish", "future", "draft", "pending", "private"], }, ], handler: this.handleListPages.bind(this), },
- src/server/ToolRegistry.ts:47-62 (registration)Generic registration loop in ToolRegistry.registerAllTools() that instantiates PageTools (imported via * as Tools from '@/tools/index.js'), calls getTools() to retrieve wp_list_pages definition, and registers it with the MCP server via registerTool().Object.values(Tools).forEach((ToolClass) => { let toolInstance: { getTools(): unknown[] }; // Cache and Performance tools need the clients map if (ToolClass.name === "CacheTools" || ToolClass.name === "PerformanceTools") { toolInstance = new ToolClass(this.wordpressClients); } else { toolInstance = new (ToolClass as new () => { getTools(): unknown[] })(); } const tools = toolInstance.getTools(); tools.forEach((tool: unknown) => { this.registerTool(tool as ToolDefinition); }); });