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
| Name | Required | Description | Default |
|---|---|---|---|
| status | No | publish | |
| per_page | No | ||
| search | No |
Implementation Reference
- src/wordpress_mcp/server.py:24-42 (handler)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)
- src/wordpress_mcp/client.py:65-97 (helper)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 ]