Skip to main content
Glama
hafizrahman

Weather & WordPress MCP Server

by hafizrahman

get-latest-posts

Retrieve recent posts from a WordPress blog to access current content updates and information.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:179-207 (registration)
    Registration of the 'get-latest-posts' tool, including description, empty input schema, and the complete inline handler function that fetches and formats the latest 10 blog posts.
    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")}` }],
            };
        }
    );
  • The core handler function for executing the 'get-latest-posts' tool. It retrieves the 10 most recent posts via the WordPress.com API, handles errors, formats each post with title, date, link, and truncated excerpt, and returns formatted text content.
    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")}` }],
        };
    }
  • TypeScript interface (schema) defining the expected structure of WordPress post objects used in the get-latest-posts handler.
    interface WPPost {
        id: number;
        title: { rendered: string };
        link: string;
        date: string;
        excerpt: { rendered: string };
    }
  • Helper utility function to remove HTML tags and normalize spaces from post excerpt text, used in post formatting.
    function stripHTML(html: string): string {
        return html.replace(/<\/?[^>]+(>|$)/g, "").replace(/ /g, " ");
    }
  • Shared helper function for fetching JSON from APIs with User-Agent header and error handling, used by the tool to retrieve posts.
    async function fetchJson<T>(url: string, headers: Record<string, string> = {}): Promise<T | null> {
        try {
            const response = await fetch(url, { headers: { "User-Agent": USER_AGENT, ...headers } });
            if (!response.ok) throw new Error(`HTTP error ${response.status}`);
            return (await response.json()) as T;
        } catch (err) {
            console.error("Fetch error:", err);
            return null;
        }
    }
Behavior2/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 the tool retrieves posts but does not disclose behavioral traits such as rate limits, authentication needs, pagination, error handling, or what happens if no posts exist. This is a significant gap for a tool with no annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core functionality ('Get the 10 most recent posts') and includes essential context ('from hafiz.blog (WordPress.com)'). There is zero waste, and every word earns its place.

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?

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is adequate for basic understanding but incomplete. It lacks details on return format, error cases, or behavioral constraints, which are important even for simple tools without structured data to compensate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately does not discuss parameters, and the baseline score is 4 for tools with no parameters, as it avoids unnecessary information.

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 specific action ('Get'), resource ('10 most recent posts'), and source ('hafiz.blog (WordPress.com)'). It precisely distinguishes this tool from sibling tools like get-categories or get-posts-by-category by specifying it fetches recent posts rather than categories or filtered posts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for retrieving recent posts from a specific blog, but it does not explicitly state when to use this tool versus alternatives like get-posts-by-category or provide any exclusions. The context is clear but lacks explicit guidance on tool selection.

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

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