Skip to main content
Glama
hafizrahman

Weather & WordPress MCP Server

by hafizrahman

get-latest-posts

Retrieve the 10 most recent posts from hafiz.blog (WordPress.com) using this tool, designed for quick access to updated content.

Instructions

Get the 10 most recent posts from hafiz.blog (WordPress.com)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that fetches the 10 latest posts from the hafiz.blog WordPress API, formats each post's title, date, link, and excerpt (stripping HTML), and returns a formatted text response.
    async () => { const postsUrl = `${WP_COM_API_BASE}/posts?per_page=10&_fields=id,title,link,date,excerpt`; const posts = await fetchJson<WPPost[]>(postsUrl); if (!posts || posts.length === 0) { return { content: [{ type: "text", text: "No posts found or failed to fetch." }], }; } const formattedPosts = posts.map((post) => [ `Title: ${post.title.rendered}`, `Date: ${new Date(post.date).toLocaleString()}`, `Link: ${post.link}`, `Excerpt: ${stripHTML(post.excerpt.rendered).slice(0, 200)}...`, "---", ].join("\n") ); return { content: [{ type: "text", text: `Latest posts from hafiz.blog:\n\n${formattedPosts.join("\n")}` }], }; }
  • Input schema for the tool: empty object indicating no input parameters are required.
    {},
  • src/index.ts:179-207 (registration)
    Registration of the 'get-latest-posts' tool using server.tool, including name, description, input schema, and inline handler function.
    server.tool( "get-latest-posts", "Get the 10 most recent posts from hafiz.blog (WordPress.com)", {}, async () => { const postsUrl = `${WP_COM_API_BASE}/posts?per_page=10&_fields=id,title,link,date,excerpt`; const posts = await fetchJson<WPPost[]>(postsUrl); if (!posts || posts.length === 0) { return { content: [{ type: "text", text: "No posts found or failed to fetch." }], }; } const formattedPosts = posts.map((post) => [ `Title: ${post.title.rendered}`, `Date: ${new Date(post.date).toLocaleString()}`, `Link: ${post.link}`, `Excerpt: ${stripHTML(post.excerpt.rendered).slice(0, 200)}...`, "---", ].join("\n") ); return { content: [{ type: "text", text: `Latest posts from hafiz.blog:\n\n${formattedPosts.join("\n")}` }], }; } );
  • Helper function to strip HTML tags and &nbsp; entities from post excerpt text for clean display.
    function stripHTML(html: string): string { return html.replace(/<\/?[^>]+(>|$)/g, "").replace(/&nbsp;/g, " "); }
  • TypeScript interface defining the shape of WordPress post objects used in the tool's API response parsing.
    interface WPPost { id: number; title: { rendered: string }; link: string; date: string; excerpt: { rendered: string }; }

Other Tools

Related 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/hafizrahman/wp-mcp'

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