Skip to main content
Glama
jbenton

guardian-mcp-server

by jbenton

guardian_search

Search and filter Guardian newspaper articles from 1999 onward using queries, dates, sections, tags, and sorting options.

Instructions

Search Guardian articles with flexible filtering options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoSearch terms (can be empty to browse all content)
sectionNoFilter by section ID (get available sections via guardian_get_sections)
tagNoFilter by tag (over 50,000 available tags)
from_dateNoStart date (YYYY-MM-DD format)
to_dateNoEnd date (YYYY-MM-DD format)
order_byNoSort order: 'newest', 'oldest', 'relevance' (default: 'relevance')
page_sizeNoResults per page, max 200 (default: 20)
pageNoPage number (default: 1)
show_fieldsNoComma-separated fields to include (headline,standfirst,body,byline,thumbnail,publication)
production_officeNoFilter by office: 'uk', 'us', 'au'
detail_levelNoResponse detail level: 'minimal' (fast), 'standard' (default), 'full' (complete)

Implementation Reference

  • Main handler function that parses input args using SearchParamsSchema, builds Guardian API search parameters based on options like query, section, dates, order, detail level, calls client.search(), and formats the response using formatArticleResponse.
    export async function guardianSearch(client: GuardianClient, args: any): Promise<string> {
      const params = SearchParamsSchema.parse(args);
    
      // Build search parameters for Guardian API
      const searchParams: Record<string, any> = {};
    
      if (params.query) {
        searchParams.q = params.query;
      }
      if (params.section) {
        searchParams.section = params.section;
      }
      if (params.tag) {
        searchParams.tag = params.tag;
      }
      if (params.from_date) {
        const fromDate = validateDate(params.from_date);
        if (!fromDate) {
          throw new Error(`Invalid from_date format: ${params.from_date}. Use YYYY-MM-DD format.`);
        }
        searchParams['from-date'] = fromDate;
      }
      if (params.to_date) {
        const toDate = validateDate(params.to_date);
        if (!toDate) {
          throw new Error(`Invalid to_date format: ${params.to_date}. Use YYYY-MM-DD format.`);
        }
        searchParams['to-date'] = toDate;
      }
      
      searchParams['order-by'] = params.order_by || 'relevance';
      searchParams['page-size'] = params.page_size || 20;
      searchParams.page = params.page || 1;
      
      // Handle detail_level for performance optimization
      const detailLevel = params.detail_level || 'minimal';
      let showFields = params.show_fields;
      
      if (!showFields) {
        switch (detailLevel) {
          case 'minimal':
            showFields = 'headline,sectionName,webPublicationDate';
            break;
          case 'standard':
            showFields = 'headline,standfirst,byline,publication,firstPublicationDate';
            break;
          case 'full':
            showFields = 'headline,standfirst,body,byline,publication,firstPublicationDate,wordcount';
            break;
        }
      }
      
      searchParams['show-fields'] = showFields;
      
      if (params.production_office) {
        searchParams['production-office'] = params.production_office;
      }
    
      const response = await client.search(searchParams);
      const articles = response.response.results;
      const pagination = response.response;
    
      // Apply truncation based on detail level
      const formatOptions = {
        truncate: detailLevel !== 'full', // Only show full content for 'full' detail level
        maxLength: 500
      };
      return formatArticleResponse(articles, pagination, formatOptions);
    }
  • Zod schema for validating and typing the input parameters to the guardian_search tool.
    export const SearchParamsSchema = z.object({
      query: z.string().optional(),
      section: z.string().optional(),
      tag: z.string().optional(),
      from_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
      to_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
      order_by: z.enum(['newest', 'oldest', 'relevance']).optional(),
      page_size: z.number().min(1).max(200).optional(),
      page: z.number().min(1).optional(),
      show_fields: z.string().optional(),
      production_office: z.enum(['uk', 'us', 'au']).optional(),
      detail_level: z.enum(['minimal', 'standard', 'full']).optional(),
    });
  • Function that registers all tools including guardian_search by mapping the name to the handler function wrapped with the GuardianClient.
    export function registerTools(client: GuardianClient): Record<string, ToolHandler> {
      return {
        guardian_search: (args) => guardianSearch(client, args),
        guardian_get_article: (args) => guardianGetArticle(client, args),
        guardian_longread: (args) => guardianLongread(client, args),
        guardian_lookback: (args) => guardianLookback(client, args),
        guardian_browse_section: (args) => guardianBrowseSection(client, args),
        guardian_get_sections: (args) => guardianGetSections(client, args),
        guardian_search_tags: (args) => guardianSearchTags(client, args),
        guardian_search_by_length: (args) => guardianSearchByLength(client, args),
        guardian_search_by_author: (args) => guardianSearchByAuthor(client, args),
        guardian_find_related: (args) => guardianFindRelated(client, args),
        guardian_get_article_tags: (args) => guardianGetArticleTags(client, args),
        guardian_content_timeline: (args) => guardianContentTimeline(client, args),
        guardian_author_profile: (args) => guardianAuthorProfile(client, args),
        guardian_topic_trends: (args) => guardianTopicTrends(client, args),
        guardian_top_stories_by_date: (args) => guardianTopStoriesByDate(client, args),
        guardian_recommend_longreads: (args) => guardianRecommendLongreads(client, args),
      };
  • src/index.ts:61-118 (registration)
    MCP tool registration in the ListTools response, defining the name, description, and input schema for guardian_search.
      name: 'guardian_search',
      description: 'Search Guardian articles with flexible filtering options',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search terms (can be empty to browse all content)',
          },
          section: {
            type: 'string',
            description: 'Filter by section ID (get available sections via guardian_get_sections)',
          },
          tag: {
            type: 'string',
            description: 'Filter by tag (over 50,000 available tags)',
          },
          from_date: {
            type: 'string',
            description: 'Start date (YYYY-MM-DD format)',
          },
          to_date: {
            type: 'string',
            description: 'End date (YYYY-MM-DD format)',
          },
          order_by: {
            type: 'string',
            description: "Sort order: 'newest', 'oldest', 'relevance' (default: 'relevance')",
            enum: ['newest', 'oldest', 'relevance'],
          },
          page_size: {
            type: 'integer',
            description: 'Results per page, max 200 (default: 20)',
            minimum: 1,
            maximum: 200,
          },
          page: {
            type: 'integer',
            description: 'Page number (default: 1)',
            minimum: 1,
          },
          show_fields: {
            type: 'string',
            description: 'Comma-separated fields to include (headline,standfirst,body,byline,thumbnail,publication)',
          },
          production_office: {
            type: 'string',
            description: "Filter by office: 'uk', 'us', 'au'",
            enum: ['uk', 'us', 'au'],
          },
          detail_level: {
            type: 'string',
            description: "Response detail level: 'minimal' (fast), 'standard' (default), 'full' (complete)",
            enum: ['minimal', 'standard', 'full'],
          },
        },
      },
    },
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. While 'Search' implies a read operation, the description doesn't address important behavioral aspects like rate limits, authentication requirements, response format, pagination behavior (beyond what's in the schema), or whether this is a real-time search versus cached results. For a complex 11-parameter search tool, this is insufficient behavioral context.

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 immediately communicates the core function. There's no wasted verbiage or unnecessary elaboration. It's appropriately sized for a search tool and front-loads the essential information.

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?

Given the complexity (11 parameters, no annotations, no output schema, and 15 sibling tools), the description is inadequate. It doesn't help the agent understand what this search returns (no output schema), how it differs from specialized sibling searches, or important behavioral constraints. For a tool in this rich ecosystem, the description should provide more contextual guidance about when and how to use it effectively.

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 schema description coverage is 100%, so all parameters are well-documented in the schema itself. The description adds minimal value beyond what's already in the schema - it mentions 'flexible filtering options' which aligns with the many filter parameters, but doesn't provide additional semantic context about how these filters interact or which combinations are most useful. This meets the baseline expectation when schema coverage is complete.

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 verb ('Search') and resource ('Guardian articles'), making the purpose immediately understandable. It also mentions 'flexible filtering options' which hints at capabilities. However, it doesn't specifically differentiate this tool from its many siblings (like guardian_search_by_author or guardian_search_by_length), which would be needed for a perfect score.

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 the many sibling search tools available. With 15 sibling tools including multiple specialized search variants (by author, by length, tags, etc.), the agent receives no help in selecting the appropriate search tool for different scenarios. The mention of 'flexible filtering options' is too vague to serve as meaningful usage 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

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/jbenton/guardian-mcp-server'

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