Skip to main content
Glama

wp_create_post

Create WordPress posts with validation and management links. Set titles, content, status, categories, tags, featured images, and scheduling.

Instructions

Creates a new WordPress post with comprehensive validation and detailed success feedback including management links.

Usage Examples: • Simple post: wp_create_post --title="My New Post" --content="<p>Hello World!</p>" • Draft post: wp_create_post --title="Draft Post" --status="draft" • Categorized post: wp_create_post --title="Tech News" --categories=[1,5] --tags=[10,20] • Post with featured image: wp_create_post --title="My Post" --content="<p>Content</p>" --featured_media=42 • Remove featured image: wp_create_post --title="My Post" --featured_media=0 • Scheduled post: wp_create_post --title="Future Post" --status="future" --date="2024-12-25T10:00:00" • Complete post: wp_create_post --title="Complete Post" --content="<p>Content</p>" --excerpt="Summary" --status="publish"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteNoThe ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured.
titleYesThe title for the post.
contentNoThe content for the post, in HTML format.
statusNoThe publishing status for the post.
excerptNoThe excerpt for the post.
categoriesNoAn array of category IDs to assign to the post.
tagsNoAn array of tag IDs to assign to the post.
featured_mediaNoThe ID of the featured media (image). Use 0 to remove featured media.
dateNoThe date the post was published, in the site's timezone (ISO 8601 format).

Implementation Reference

  • Core handler implementation for wp_create_post tool. Validates input parameters, creates the post via WordPressClient, and returns formatted success response with post details and admin links.
    export async function handleCreatePost(
      client: WordPressClient,
      params: CreatePostRequest,
    ): Promise<WordPressPost | string> {
      try {
        validatePostParams(params);
        const post = await client.createPost(params);
    
        // Build success response with management links
        let response = `✅ **Post Created Successfully**\n\n`;
        response += `**Title**: ${post.title.rendered}\n`;
        response += `**ID**: ${post.id}\n`;
        response += `**Status**: ${post.status}\n`;
        response += `**Link**: ${post.link}\n`;
    
        // Add management links
        const siteUrl = client.getSiteUrl ? client.getSiteUrl() : "";
        if (siteUrl) {
          response += `\n**Management**:\n`;
          response += `- Edit: ${siteUrl}/wp-admin/post.php?post=${post.id}&action=edit\n`;
          if (post.status === "publish") {
            response += `- View: ${post.link}\n`;
          } else {
            response += `- Preview: ${siteUrl}/?p=${post.id}&preview=true\n`;
          }
        }
    
        return response;
      } catch (_error) {
        throw new Error(`Failed to create post: ${getErrorMessage(_error)}`);
      }
    }
  • Tool schema definition including name, detailed description with usage examples, and inputSchema with parameters, validation (required title, optional others), and enums.
    export const createPostTool: MCPTool = {
      name: "wp_create_post",
      description:
        "Creates a new WordPress post with comprehensive validation and detailed success feedback including management links.\n\n" +
        "**Usage Examples:**\n" +
        '• Simple post: `wp_create_post --title="My New Post" --content="<p>Hello World!</p>"`\n' +
        '• Draft post: `wp_create_post --title="Draft Post" --status="draft"`\n' +
        '• Categorized post: `wp_create_post --title="Tech News" --categories=[1,5] --tags=[10,20]`\n' +
        '• Post with featured image: `wp_create_post --title="My Post" --content="<p>Content</p>" --featured_media=42`\n' +
        '• Remove featured image: `wp_create_post --title="My Post" --featured_media=0`\n' +
        '• Scheduled post: `wp_create_post --title="Future Post" --status="future" --date="2024-12-25T10:00:00"`\n' +
        '• Complete post: `wp_create_post --title="Complete Post" --content="<p>Content</p>" --excerpt="Summary" --status="publish"`',
      inputSchema: {
        type: "object",
        properties: {
          title: {
            type: "string",
            description: "The title for the post.",
          },
          content: {
            type: "string",
            description: "The content for the post, in HTML format.",
          },
          status: {
            type: "string",
            description: "The publishing status for the post.",
            enum: ["publish", "draft", "pending", "private"],
          },
          excerpt: {
            type: "string",
            description: "The excerpt for the post.",
          },
          categories: {
            type: "array",
            items: { type: "number" },
            description: "An array of category IDs to assign to the post.",
          },
          tags: {
            type: "array",
            items: { type: "number" },
            description: "An array of tag IDs to assign to the post.",
          },
          featured_media: {
            type: "number",
            description: "The ID of the featured media (image). Use 0 to remove featured media.",
          },
          date: {
            type: "string",
            description: "The date the post was published, in the site's timezone (ISO 8601 format).",
          },
        },
        required: ["title"],
      },
    };
  • Registration mapping: binds the tool name 'wp_create_post' to the handleCreatePost method in the PostTools class's getHandlerForTool switch statement, used by getTools() to attach handlers to tool definitions.
    private getHandlerForTool(toolName: string) {
      switch (toolName) {
        case "wp_list_posts":
          return this.handleListPosts.bind(this);
        case "wp_get_post":
          return this.handleGetPost.bind(this);
        case "wp_create_post":
          return this.handleCreatePost.bind(this);
        case "wp_update_post":
          return this.handleUpdatePost.bind(this);
        case "wp_delete_post":
          return this.handleDeletePost.bind(this);
        case "wp_get_post_revisions":
          return this.handleGetPostRevisions.bind(this);
        default:
          throw new Error(`Unknown tool: ${toolName}`);
      }
    }
  • Wrapper handler in PostTools class that extracts and type-casts MCP input parameters before delegating to the core handleCreatePost function.
    public async handleCreatePost(
      client: WordPressClient,
      params: CreatePostRequest | Record<string, unknown>,
    ): Promise<WordPressPost | string> {
      // Extract only the relevant post creation parameters, excluding MCP-specific fields like 'site'
      const postParams: CreatePostRequest = {
        title: params.title as string,
      };
    
      if (params.content !== undefined) postParams.content = params.content as string;
      if (params.status !== undefined) postParams.status = params.status as PostStatus;
      if (params.excerpt !== undefined) postParams.excerpt = params.excerpt as string;
      if (params.categories !== undefined) postParams.categories = params.categories as number[];
      if (params.tags !== undefined) postParams.tags = params.tags as number[];
      if (params.featured_media !== undefined) postParams.featured_media = params.featured_media as number;
      if (params.date !== undefined) postParams.date = params.date as string;
    
      return handleCreatePost(client, postParams);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by mentioning 'comprehensive validation' and 'detailed success feedback including management links.' It doesn't fully cover behavioral aspects like error handling, authentication requirements, or rate limits, but provides more than minimal disclosure for a creation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Perfectly structured with a clear purpose statement followed by organized usage examples. Every sentence earns its place by demonstrating practical applications. The examples are front-loaded and efficiently cover common scenarios without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with no annotations and no output schema, the description provides good context through examples showing various parameter combinations. It could be more complete by mentioning authentication requirements or error scenarios, but covers the core functionality well given the comprehensive parameter schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 9 parameters thoroughly. The description adds value through usage examples that illustrate practical parameter combinations (e.g., featured_media=0 to remove, status='future' with date), but doesn't add semantic meaning beyond what the schema provides. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool 'Creates a new WordPress post' with specific verb+resource. It distinguishes from siblings like wp_create_page, wp_create_comment, etc., by focusing specifically on posts rather than other content types. The mention of 'comprehensive validation and detailed success feedback' adds specificity beyond the basic action.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context through multiple usage examples showing when to use this tool (for creating posts with various configurations). However, it doesn't explicitly state when NOT to use it or mention alternatives like wp_create_page for pages or wp_update_post for updates, though the sibling list makes alternatives obvious.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/docdyhr/mcp-wordpress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server