Skip to main content
Glama

wp_get_post

Retrieve detailed WordPress post information including metadata, content statistics, and management links. Optionally include full HTML content for editing purposes.

Instructions

Retrieves detailed information about a single post including metadata, content statistics, and management links. Optionally includes full HTML content for editing.

Usage Examples: • Basic metadata: wp_get_post --id=123 • With full content: wp_get_post --id=123 --include_content=true

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteNoThe ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured.
idYesThe unique identifier for the post.
include_contentNoIf true, includes the full HTML content of the post for editing. Default: false

Implementation Reference

  • Core execution logic for wp_get_post tool: validates ID, fetches post via WordPressClient.getPost, enriches with author/categories/tags info, computes word count, formats detailed Markdown response including optional full content and admin links.
    export async function handleGetPost(
      client: WordPressClient,
      params: { id: number; include_content?: boolean },
    ): Promise<WordPressPost | string> {
      try {
        const postId = validateId(params.id, "post ID");
        const post = await client.getPost(postId);
    
        // Get additional metadata for comprehensive response
        const [author, categories, tags] = await Promise.all([
          // Get author information
          post.author
            ? client.getUser(post.author).catch(() => ({ name: `User ${post.author}`, username: `user${post.author}` }))
            : null,
          // Get categories
          post.categories && post.categories.length > 0
            ? Promise.all(post.categories.map((id) => client.getCategory(id).catch(() => ({ id, name: `Category ${id}` }))))
            : [],
          // Get tags
          post.tags && post.tags.length > 0
            ? Promise.all(post.tags.map((id) => client.getTag(id).catch(() => ({ id, name: `Tag ${id}` }))))
            : [],
        ]);
    
        // Format post content
        const date = new Date(post.date);
        const modifiedDate = new Date(post.modified);
        const formattedDate = date.toLocaleDateString("en-US", {
          year: "numeric",
          month: "short",
          day: "numeric",
          hour: "2-digit",
          minute: "2-digit",
        });
        const formattedModified = modifiedDate.toLocaleDateString("en-US", {
          year: "numeric",
          month: "short",
          day: "numeric",
          hour: "2-digit",
          minute: "2-digit",
        });
    
        const content = post.content?.rendered || "";
        const excerpt = post.excerpt?.rendered ? sanitizeHtml(post.excerpt.rendered).trim() : "";
        const wordCount = sanitizeHtml(content).split(/\s+/).filter(Boolean).length;
    
        // Build comprehensive response
        let response = `# ${post.title.rendered}\n\n`;
        response += `**Post ID**: ${post.id}\n`;
        response += `**Status**: ${post.status}\n`;
        response += `**Author**: ${author?.name || author?.username || `User ${post.author}`}\n`;
        response += `**Published**: ${formattedDate}\n`;
        response += `**Modified**: ${formattedModified}\n`;
    
        if (categories.length > 0) {
          response += `**Categories**: ${categories.map((c) => c.name).join(", ")}\n`;
        }
    
        if (tags.length > 0) {
          response += `**Tags**: ${tags.map((t) => t.name).join(", ")}\n`;
        }
    
        response += `**Word Count**: ${wordCount}\n`;
        response += `**Link**: ${post.link}\n`;
    
        if (excerpt) {
          response += `\n## Excerpt\n${excerpt}\n`;
        }
    
        // Only include full content if explicitly requested (for backward compatibility, default to true)
        const includeContent = params.include_content !== false;
        if (content && includeContent) {
          response += `\n## Content\n${content}\n`;
        }
    
        // Add management links and metadata
        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`;
          response += `- **Preview**: ${siteUrl}/?p=${post.id}&preview=true\n`;
        }
    
        return response;
      } catch (_error) {
        if (_error instanceof Error && _error.message.includes("404")) {
          return `Post with ID ${params.id} not found. Please verify the ID and try again.`;
        }
        throw new Error(`Failed to get post: ${getErrorMessage(_error)}`);
      }
    }
  • Input schema and description definition for the wp_get_post tool, including parameters id (required) and include_content (optional).
    export const getPostTool: MCPTool = {
      name: "wp_get_post",
      description:
        "Retrieves detailed information about a single post including metadata, content statistics, and management links. Optionally includes full HTML content for editing.\n\n" +
        "**Usage Examples:**\n" +
        "• Basic metadata: `wp_get_post --id=123`\n" +
        "• With full content: `wp_get_post --id=123 --include_content=true`",
      inputSchema: {
        type: "object",
        properties: {
          id: {
            type: "number",
            description: "The unique identifier for the post.",
          },
          include_content: {
            type: "boolean",
            description: "If true, includes the full HTML content of the post for editing. Default: false",
          },
        },
        required: ["id"],
      },
    };
  • Registers the wp_get_post tool by mapping its definition to the bound handler this.handleGetPost in PostTools.getTools(), which is used for MCP tool registration.
    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 method in PostTools class that extracts parameters and delegates to the core handleGetPost function from PostHandlers.
    public async handleGetPost(
      client: WordPressClient,
      params: { id: number } | Record<string, unknown>,
    ): Promise<WordPressPost | string> {
      // Extract only the relevant parameters
      const postParams = {
        id: params.id as number,
      };
    
      return handleGetPost(client, postParams);
    }
  • Includes wp_get_post tool definition (getPostTool) in the array of post tool definitions used for registration.
    export const postToolDefinitions = [
      listPostsTool,
      getPostTool,
      createPostTool,
      updatePostTool,
      deletePostTool,
      getPostRevisionsTool,
    ];
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It states this is a retrieval operation (implied read-only) and mentions optional HTML content inclusion, but doesn't disclose authentication requirements, rate limits, error conditions, or what happens if the post doesn't exist. It adds some behavioral context but leaves gaps.

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

Conciseness4/5

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

The description is appropriately sized with two sentences that state purpose and key feature, followed by usage examples. The examples are helpful but slightly verbose; every sentence earns its place by providing concrete guidance.

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

Completeness3/5

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

For a read operation with 3 parameters and 100% schema coverage but no output schema, the description is adequate but has gaps. It explains what the tool retrieves but doesn't describe the return format, error handling, or authentication needs. With no annotations and no output schema, more completeness would be beneficial.

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 three parameters thoroughly. The description mentions the include_content parameter's effect ('includes the full HTML content of the post for editing'), which adds marginal value beyond the schema's 'If true, includes the full HTML content of the post for editing. Default: false'. Baseline 3 is appropriate when schema does the heavy lifting.

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 verb 'retrieves' and the resource 'detailed information about a single post', specifying it includes metadata, content statistics, and management links. It distinguishes from sibling tools like wp_list_posts (which lists multiple posts) and wp_get_post_revisions (which gets revisions).

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 for when to use this tool (to get detailed info about a single post) and includes usage examples. However, it doesn't explicitly state when NOT to use it or name specific alternatives like wp_get_page for pages or wp_list_posts for multiple posts.

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