wpnav_execute
Execute WordPress management tools through the WP Navigator MCP server by specifying tool names and required arguments for content and site operations.
Instructions
Execute any WP Navigator tool by name. Use wpnav_search_tools to discover tools and wpnav_describe_tools to get their schemas first.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tool | Yes | Tool name to execute (e.g., "wpnav_create_post", "wpnav_list_pages") | |
| arguments | Yes | Tool arguments matching the tool's inputSchema |
Implementation Reference
- src/tools/core/execute.ts:80-156 (handler)Handler function that implements the wpnav_execute tool logic: validates inputs, checks tool availability and enabled status, executes the specified tool via the registry, and handles errors.* Handler for wpnav_execute * * Executes a tool by name with provided arguments. * Validates tool exists and is enabled before execution. */ export async function executeToolHandler( args: { tool: string; arguments: Record<string, unknown> }, context: ToolExecutionContext ): Promise<ToolResult> { const { tool: toolName, arguments: toolArgs } = args; // Validate input - tool name is required if (!toolName || typeof toolName !== 'string') { return errorResponse('INVALID_INPUT', 'tool parameter is required and must be a string'); } // Validate input - arguments must be an object if (toolArgs === null || typeof toolArgs !== 'object' || Array.isArray(toolArgs)) { return errorResponse('INVALID_INPUT', 'arguments must be an object'); } // 1. Check tool exists const tool = toolRegistry.getTool(toolName); if (!tool) { return errorResponse('TOOL_NOT_FOUND', `Tool '${toolName}' does not exist`, { available_categories: AVAILABLE_CATEGORIES, hint: 'Use wpnav_search_tools to find available tools', }); } // 2. Check tool is enabled (focus modes, role restrictions, feature flags) if (!toolRegistry.isEnabled(toolName)) { // Determine reason for being disabled let reason = 'focus mode or role restrictions'; if (tool.featureFlag) { reason = `feature flag '${tool.featureFlag}' is not enabled`; } return errorResponse('TOOL_DISABLED', `Tool '${toolName}' is disabled by ${reason}`, { hint: 'Check your wpnavigator.jsonc focus mode and role settings', }); } // 3. Execute the tool // Note: Individual tools handle their own schema validation // WPNAV_ENABLE_WRITES is enforced at the tool level, not here try { const result = await toolRegistry.execute(toolName, toolArgs, context); return result; } catch (error) { // Handle execution errors const errorMessage = error instanceof Error ? error.message : String(error); // Check for common error patterns if (errorMessage.includes('required')) { return errorResponse('VALIDATION_FAILED', errorMessage, { hint: 'Use wpnav_describe_tools to get the full schema for this tool', tool: toolName, }); } if (errorMessage.includes('WRITES_DISABLED') || errorMessage.includes('write operations')) { return errorResponse( 'WRITES_DISABLED', 'Write operations are disabled. Set WPNAV_ENABLE_WRITES=1 to enable.', { tool: toolName, } ); } // Generic execution error return errorResponse('EXECUTION_FAILED', `Failed to execute '${toolName}': ${errorMessage}`, { tool: toolName, }); } }
- src/tools/core/execute.ts:33-56 (schema)Input schema definition for the wpnav_execute tool, specifying required 'tool' name and 'arguments' object./** * Tool definition for wpnav_execute */ export const executeToolDefinition = { name: 'wpnav_execute', description: 'Execute any WP Navigator tool by name. Use wpnav_search_tools to discover tools and wpnav_describe_tools to get their schemas first.', inputSchema: { type: 'object' as const, properties: { tool: { type: 'string', description: 'Tool name to execute (e.g., "wpnav_create_post", "wpnav_list_pages")', }, arguments: { type: 'object', description: "Tool arguments matching the tool's inputSchema", additionalProperties: true, }, }, required: ['tool', 'arguments'], }, };
- src/tools/core/execute.ts:158-167 (registration)Local registration function that registers the wpnav_execute tool with its definition and handler into the toolRegistry./** * Register the execute tool meta-tool */ export function registerExecuteTool(): void { toolRegistry.register({ definition: executeToolDefinition, handler: executeToolHandler, category: ToolCategory.CORE, }); }
- src/tools/core/index.ts:336-340 (registration)Invocation of registerExecuteTool() within the registerCoreTools() function, which is part of the core tools registration chain.registerSearchTools(); registerDescribeTools(); registerExecuteTool(); registerContextTool(); }
- src/tools/core/execute.ts:59-77 (helper)Helper function used by the handler to format standardized error responses.*/ function errorResponse(code: string, message: string, extra?: Record<string, unknown>): ToolResult { return { content: [ { type: 'text', text: JSON.stringify( { error: code, message, ...extra, }, null, 2 ), }, ], }; }