Skip to main content
Glama

get-post

Retrieve a specific WordPress post by ID using site URL, credentials, and optional parameters like post password or context (view, embed, edit).

Instructions

Get a specific post by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoScope under which the request is madeview
passwordYesWordPress application password
postIdYesID of the post to retrieve
postPasswordNoThe password for the post if it is password protected
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • The handler function that executes the 'get-post' tool logic. It makes an authenticated API request to retrieve a specific WordPress post by ID, handles optional parameters like context and postPassword, formats the post details into a text response, and catches any errors.
    async ({ siteUrl, username, password, postId, context, postPassword }) => { try { const params: Record<string, any> = { context }; if (postPassword) params.password = postPassword; const post = await makeWPRequest<WPPost>({ siteUrl, endpoint: `posts/${postId}`, auth: { username, password }, params }); return { content: [ { type: "text", text: `Post Details:\nID: ${post.id}\nTitle: ${post.title?.rendered || "No title"}\nDate: ${post.date || "No date"}\nStatus: ${post.status || "unknown"}\nAuthor: ${post.author || "Unknown"}\nContent: ${post.content?.rendered || "No content"}\nExcerpt: ${post.excerpt?.rendered || "No excerpt"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving post: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod input schema defining the parameters for the 'get-post' tool: required siteUrl, username, password, postId; optional context and postPassword.
    { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), postId: z.number().describe("ID of the post to retrieve"), context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"), postPassword: z.string().optional().describe("The password for the post if it is password protected"), },
  • src/index.ts:704-745 (registration)
    Registration of the 'get-post' tool on the MCP server using server.tool(), specifying name, description, input schema, and handler function.
    "get-post", "Get a specific post by ID", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), postId: z.number().describe("ID of the post to retrieve"), context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"), postPassword: z.string().optional().describe("The password for the post if it is password protected"), }, async ({ siteUrl, username, password, postId, context, postPassword }) => { try { const params: Record<string, any> = { context }; if (postPassword) params.password = postPassword; const post = await makeWPRequest<WPPost>({ siteUrl, endpoint: `posts/${postId}`, auth: { username, password }, params }); return { content: [ { type: "text", text: `Post Details:\nID: ${post.id}\nTitle: ${post.title?.rendered || "No title"}\nDate: ${post.date || "No date"}\nStatus: ${post.status || "unknown"}\nAuthor: ${post.author || "Unknown"}\nContent: ${post.content?.rendered || "No content"}\nExcerpt: ${post.excerpt?.rendered || "No excerpt"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving post: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • TypeScript interface WPPost defining the structure of WordPress post objects used in the get-post tool response typing.
    interface WPPost { id: number; date?: string; date_gmt?: string; guid?: { rendered: string; }; modified?: string; modified_gmt?: string; slug?: string; status?: 'publish' | 'future' | 'draft' | 'pending' | 'private'; type?: string; link?: string; title?: { rendered: string; }; content?: { rendered: string; protected?: boolean; }; excerpt?: { rendered: string; protected?: boolean; }; author?: number; featured_media?: number; comment_status?: 'open' | 'closed'; ping_status?: 'open' | 'closed'; sticky?: boolean; template?: string; format?: 'standard' | 'aside' | 'chat' | 'gallery' | 'link' | 'image' | 'quote' | 'status' | 'video' | 'audio'; meta?: Record<string, any>; _links?: { self?: Array<{ href: string }>; collection?: Array<{ href: string }>; about?: Array<{ href: string }>; author?: Array<{ href: string; embeddable: boolean }>; replies?: Array<{ href: string; embeddable: boolean }>; 'version-history'?: Array<{ href: string }>; 'predecessor-version'?: Array<{ href: string; id: number }>; 'wp:featuredmedia'?: Array<{ href: string; embeddable: boolean }>; 'wp:attachment'?: Array<{ href: string }>; 'wp:term'?: Array<{ href: string; taxonomy: string; embeddable: boolean }>; curies?: Array<{ name: string; href: string; templated: boolean }>; }; categories?: number[]; tags?: number[]; }
  • Shared helper function makeWPRequest that performs authenticated HTTP requests to the WordPress REST API, used by the get-post handler.
    async function makeWPRequest<T>({ siteUrl, endpoint, method = 'GET', auth, data = null, params = null }: { siteUrl: string; endpoint: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; auth: { username: string; password: string }; data?: any; params?: any; }): Promise<T> { const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64'); try { const response = await axios({ method, url: `${siteUrl}/wp-json/wp/v2/${endpoint}`, headers: { 'Authorization': `Basic ${authString}`, 'Content-Type': 'application/json', }, data: data, params: params }); return response.data as T; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`); } throw error; } }

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/prathammanocha/wordpress-mcp-server'

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