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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:183-206 (handler)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")}` }], }; }
- src/index.ts:182-182 (schema)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")}` }], }; } );
- src/index.ts:175-177 (helper)Helper function to strip HTML tags and entities from post excerpt text for clean display.function stripHTML(html: string): string { return html.replace(/<\/?[^>]+(>|$)/g, "").replace(/ /g, " "); }
- src/index.ts:167-173 (schema)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 }; }