Skip to main content
Glama

list-posts

Retrieve and filter WordPress posts by parameters like author, date, status, or search term using secure API authentication. Manage post collections programmatically with pagination and sorting options.

Instructions

Get a list of posts with comprehensive filtering options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
afterNoLimit response to posts published after a given ISO8601 compliant date
authorNoLimit result set to posts assigned to specific authors
authorExcludeNoEnsure result set excludes posts assigned to specific authors
beforeNoLimit response to posts published before a given ISO8601 compliant date
categoriesNoLimit result set to items with specific terms assigned in the categories taxonomy
categoriesExcludeNoLimit result set to items except those with specific terms assigned in the categories taxonomy
contextNoScope under which the request is madeview
excludeNoEnsure result set excludes specific IDs
includeNoLimit result set to specific IDs
modifiedAfterNoLimit response to posts modified after a given ISO8601 compliant date
modifiedBeforeNoLimit response to posts modified before a given ISO8601 compliant date
offsetNoOffset the result set by a specific number of items
orderNoOrder sort attribute ascending or descendingdesc
orderbyNoSort collection by post attributedate
pageNoCurrent page of the collection
passwordYesWordPress application password
perPageNoMaximum number of items to be returned
searchNoLimit results to those matching a string
searchColumnsNoArray of column names to be searched
siteUrlYesWordPress site URL
slugNoLimit result set to posts with one or more specific slugs
statusNoLimit result set to posts assigned one or more statuses
stickyNoLimit result set to items that are sticky
tagsNoLimit result set to items with specific terms assigned in the tags taxonomy
tagsExcludeNoLimit result set to items except those with specific terms assigned in the tags taxonomy
taxRelationNoLimit result set based on relationship between multiple taxonomies
usernameYesWordPress username

Implementation Reference

  • The main handler function that executes the list-posts tool: constructs API parameters from inputs, calls the WordPress REST API /posts endpoint, formats the WPPost objects into a readable list, and returns a text response.
    async ({ 
      siteUrl, 
      username, 
      password,
      context,
      page,
      perPage,
      search,
      after,
      modifiedAfter,
      author,
      authorExclude,
      before,
      modifiedBefore,
      exclude,
      include,
      offset,
      order,
      orderby,
      searchColumns,
      slug,
      status,
      taxRelation,
      categories,
      categoriesExclude,
      tags,
      tagsExclude,
      sticky,
    }) => {
      try {
        const params: Record<string, any> = {
          context,
          page,
          per_page: perPage,
          order,
          orderby,
          status: status?.join(','),
        };
    
        if (search) params.search = search;
        if (after) params.after = after;
        if (modifiedAfter) params.modified_after = modifiedAfter;
        if (author) params.author = author.join(',');
        if (authorExclude) params.author_exclude = authorExclude.join(',');
        if (before) params.before = before;
        if (modifiedBefore) params.modified_before = modifiedBefore;
        if (exclude) params.exclude = exclude.join(',');
        if (include) params.include = include.join(',');
        if (offset) params.offset = offset;
        if (searchColumns) params.search_columns = searchColumns.join(',');
        if (slug) params.slug = slug.join(',');
        if (taxRelation) params.tax_relation = taxRelation;
        if (categories) params.categories = categories.join(',');
        if (categoriesExclude) params.categories_exclude = categoriesExclude.join(',');
        if (tags) params.tags = tags.join(',');
        if (tagsExclude) params.tags_exclude = tagsExclude.join(',');
        if (sticky !== undefined) params.sticky = sticky;
    
        const posts = await makeWPRequest<WPPost[]>({
          siteUrl,
          endpoint: "posts",
          auth: { username, password },
          params
        });
        
        const formattedPosts = Array.isArray(posts) ? posts.map(post => ({
          id: post.id,
          title: post.title?.rendered || "No title",
          date: post.date || "No date",
          status: post.status || "unknown",
          author: post.author || "Unknown",
          excerpt: post.excerpt?.rendered || "No excerpt"
        })) : [];
        
        const postsText = formattedPosts.length > 0
          ? formattedPosts.map(post => 
              `ID: ${post.id}\nTitle: ${post.title}\nDate: ${post.date}\nStatus: ${post.status}\nAuthor: ${post.author}\nExcerpt: ${post.excerpt}\n---`
            ).join("\n")
          : "No posts found";
        
        return {
          content: [
            {
              type: "text",
              text: `Posts from ${siteUrl}:\n\n${postsText}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error retrieving posts: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Zod schema for input validation of the list-posts tool, supporting comprehensive WordPress post filtering (pagination, search, date ranges, authors, categories, tags, status, etc.).
    {
      siteUrl: z.string().url().describe("WordPress site URL"),
      username: z.string().describe("WordPress username"),
      password: z.string().describe("WordPress application password"),
      context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"),
      page: z.number().min(1).optional().default(1).describe("Current page of the collection"),
      perPage: z.number().min(1).max(100).optional().default(10).describe("Maximum number of items to be returned"),
      search: z.string().optional().describe("Limit results to those matching a string"),
      after: z.string().optional().describe("Limit response to posts published after a given ISO8601 compliant date"),
      modifiedAfter: z.string().optional().describe("Limit response to posts modified after a given ISO8601 compliant date"),
      author: z.array(z.number()).optional().describe("Limit result set to posts assigned to specific authors"),
      authorExclude: z.array(z.number()).optional().describe("Ensure result set excludes posts assigned to specific authors"),
      before: z.string().optional().describe("Limit response to posts published before a given ISO8601 compliant date"),
      modifiedBefore: z.string().optional().describe("Limit response to posts modified before a given ISO8601 compliant date"),
      exclude: z.array(z.number()).optional().describe("Ensure result set excludes specific IDs"),
      include: z.array(z.number()).optional().describe("Limit result set to specific IDs"),
      offset: z.number().optional().describe("Offset the result set by a specific number of items"),
      order: z.enum(["asc", "desc"]).optional().default("desc").describe("Order sort attribute ascending or descending"),
      orderby: z.enum(["author", "date", "id", "include", "modified", "parent", "relevance", "slug", "include_slugs", "title"]).optional().default("date").describe("Sort collection by post attribute"),
      searchColumns: z.array(z.string()).optional().describe("Array of column names to be searched"),
      slug: z.array(z.string()).optional().describe("Limit result set to posts with one or more specific slugs"),
      status: z.array(z.enum(["publish", "future", "draft", "pending", "private"])).optional().default(["publish"]).describe("Limit result set to posts assigned one or more statuses"),
      taxRelation: z.enum(["AND", "OR"]).optional().describe("Limit result set based on relationship between multiple taxonomies"),
      categories: z.array(z.number()).optional().describe("Limit result set to items with specific terms assigned in the categories taxonomy"),
      categoriesExclude: z.array(z.number()).optional().describe("Limit result set to items except those with specific terms assigned in the categories taxonomy"),
      tags: z.array(z.number()).optional().describe("Limit result set to items with specific terms assigned in the tags taxonomy"),
      tagsExclude: z.array(z.number()).optional().describe("Limit result set to items except those with specific terms assigned in the tags taxonomy"),
      sticky: z.boolean().optional().describe("Limit result set to items that are sticky"),
    },
  • src/index.ts:569-571 (registration)
    MCP server registration of the 'list-posts' tool, specifying name, description, input schema, and handler function.
    server.tool(
      "list-posts",
      "Get a list of posts with comprehensive filtering options",
  • TypeScript interface defining the structure of WordPress post objects returned by the API and used in the handler.
    interface WPPost {
      id: number;
      date?: string;
      date_gmt?: string;
      guid?: {
        rendered: string;
      };
      modified?: string;
      modified_gmt?: string;
      slug?: string;
      status?: 'publish' | 'future' | 'draft' | 'pending' | 'private';
      type?: string;
      link?: string;
      title?: {
        rendered: string;
      };
      content?: {
        rendered: string;
        protected?: boolean;
      };
      excerpt?: {
        rendered: string;
        protected?: boolean;
      };
      author?: number;
      featured_media?: number;
      comment_status?: 'open' | 'closed';
      ping_status?: 'open' | 'closed';
      sticky?: boolean;
      template?: string;
      format?: 'standard' | 'aside' | 'chat' | 'gallery' | 'link' | 'image' | 'quote' | 'status' | 'video' | 'audio';
      meta?: Record<string, any>;
      _links?: {
        self?: Array<{ href: string }>;
        collection?: Array<{ href: string }>;
        about?: Array<{ href: string }>;
        author?: Array<{ href: string; embeddable: boolean }>;
        replies?: Array<{ href: string; embeddable: boolean }>;
        'version-history'?: Array<{ href: string }>;
        'predecessor-version'?: Array<{ href: string; id: number }>;
        'wp:featuredmedia'?: Array<{ href: string; embeddable: boolean }>;
        'wp:attachment'?: Array<{ href: string }>;
        'wp:term'?: Array<{ href: string; taxonomy: string; embeddable: boolean }>;
        curies?: Array<{ name: string; href: string; templated: boolean }>;
      };
      categories?: number[];
      tags?: number[];
    }
  • Reusable helper function for authenticated HTTP requests to the WordPress REST API v2, used by all tools including list-posts.
    async function makeWPRequest<T>({
      siteUrl, 
      endpoint,
      method = 'GET',
      auth,
      data = null,
      params = null
    }: {
      siteUrl: string;
      endpoint: string;
      method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
      auth: { username: string; password: string };
      data?: any;
      params?: any;
    }): Promise<T> {
      const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64');
      
      try {
        const response = await axios({
          method,
          url: `${siteUrl}/wp-json/wp/v2/${endpoint}`,
          headers: {
            'Authorization': `Basic ${authString}`,
            'Content-Type': 'application/json',
          },
          data: data,
          params: params
        });
        
        return response.data as T;
      } catch (error) {
        if (axios.isAxiosError(error) && error.response) {
          throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`);
        }
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It doesn't mention that this is a read-only operation (implied by 'Get'), doesn't discuss authentication requirements (though schema shows required credentials), doesn't mention pagination behavior (implied by 'page' and 'perPage' parameters), and doesn't describe rate limits or error conditions. The description adds almost no behavioral context beyond what's already obvious from the tool name.

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 extremely concise - a single sentence that efficiently communicates the core purpose. It's front-loaded with the main action ('Get a list of posts') and adds only the essential qualifying information ('with comprehensive filtering options'). There's zero wasted verbiage or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 27 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what kind of data is returned (post objects with what fields?), doesn't mention authentication requirements (though schema shows them), and doesn't provide any context about WordPress-specific behaviors. The description fails to compensate for the lack of annotations and output schema documentation.

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

Parameters3/5

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

The description mentions 'comprehensive filtering options' which aligns with the 27 parameters in the schema, but adds no specific parameter semantics beyond what the schema already provides. With 100% schema description coverage where each parameter is well-documented, the description doesn't need to compensate, but also doesn't add value. This meets the baseline of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('list of posts'), making it immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'get-post' or 'get-top-posts' by specifying that this is for comprehensive filtering rather than single-post retrieval or specific analytics.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get-post' for single posts, 'get-top-posts' for analytics, or 'search' tools that might exist elsewhere. The phrase 'comprehensive filtering options' hints at usage context but doesn't provide explicit when/when-not guidance.

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

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

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