Skip to main content
Glama
gaupoit

WordPress MCP Server

by gaupoit

wp_get_posts

Retrieve WordPress posts by status, quantity, or search term to access content data like titles, excerpts, and links.

Instructions

Get posts from WordPress.

Args:
    status: Post status filter - 'publish', 'draft', or 'all'. Default is 'publish'.
    per_page: Number of posts to return (1-100). Default is 10.
    search: Search term to filter posts by title/content.

Returns:
    List of posts with id, title, status, date, slug, excerpt, and link.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
statusNopublish
per_pageNo
searchNo

Implementation Reference

  • The main handler function for the 'wp_get_posts' tool. It is registered via the @mcp.tool() decorator. Defines input parameters with type hints and docstring serving as schema. Delegates to WordPressClient.get_posts().
    @mcp.tool()
    def wp_get_posts(
        status: str = "publish",
        per_page: int = 10,
        search: str | None = None,
    ) -> list[dict]:
        """Get posts from WordPress.
    
        Args:
            status: Post status filter - 'publish', 'draft', or 'all'. Default is 'publish'.
            per_page: Number of posts to return (1-100). Default is 10.
            search: Search term to filter posts by title/content.
    
        Returns:
            List of posts with id, title, status, date, slug, excerpt, and link.
        """
        client = get_client()
        return client.get_posts(status=status, per_page=per_page, search=search)
  • Supporting method in WordPressClient that implements the core logic: constructs API parameters, handles authentication requirements, calls the WordPress REST API endpoint /posts, and formats the response into a list of simplified post dictionaries.
    def get_posts(
        self,
        status: str = "publish",
        per_page: int = 10,
        search: str | None = None,
    ) -> list[dict]:
        """Get posts from WordPress."""
        params = {"per_page": per_page}
    
        if status != "all":
            params["status"] = status
    
        if search:
            params["search"] = search
    
        # Status other than 'publish' requires auth
        require_auth = status != "publish"
    
        posts = self._get("posts", params, require_auth)
    
        return [
            {
                "id": p["id"],
                "title": p["title"]["rendered"],
                "status": p["status"],
                "date": p["date"],
                "slug": p["slug"],
                "excerpt": p["excerpt"]["rendered"][:200] if p.get("excerpt") else "",
                "link": p["link"],
            }
            for p in posts
        ]

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

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