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, ];

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