Skip to main content
Glama
jbenton

guardian-mcp-server

by jbenton

guardian_find_related

Find Guardian articles related to a specific article by analyzing shared tags, with options to filter by recency, section, and similarity threshold.

Instructions

Find articles related to a given article using shared tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
article_idYesGuardian article ID or full URL to find related articles for
similarity_thresholdNoMinimum number of shared tags required (default: 2)
exclude_same_sectionNoExclude articles from the same section (default: false)
max_days_oldNoOnly find articles within this many days of the original (default: unlimited)
page_sizeNoResults per page, max 50 (default: 10)

Implementation Reference

  • The main handler function that executes the guardian_find_related tool: parses args, fetches original article tags, searches for articles sharing tags, ranks by shared tag count, filters, and returns formatted list of related articles.
    export async function guardianFindRelated(client: GuardianClient, args: any): Promise<string> {
      const params = FindRelatedParamsSchema.parse(args);
    
      // First, get the original article with all its tags
      const parsedId = parseGuardianUrl(params.article_id);
      const articleId = parsedId.startsWith('/') ? parsedId : `/${parsedId}`;
      
      const response = await client.getArticle(articleId, {
        'show-tags': 'all',
        'show-fields': 'headline,firstPublicationDate'
      });
    
      const originalArticle = response.response.content;
      if (!originalArticle) {
        return 'Original article not found.';
      }
    
      const originalTags = originalArticle.tags || [];
      const originalSection = originalArticle.sectionId;
      const originalDate = originalArticle.webPublicationDate;
    
      if (originalTags.length === 0) {
        return 'Original article has no tags for similarity matching.';
      }
    
      // Extract useful tags (excluding very generic ones)
      const usefulTags = originalTags
        .filter(tag => {
          const tagType = tag.type;
          const tagId = tag.id;
          // Focus on more specific tags
          return ['keyword', 'contributor', 'series'].includes(tagType) && tagId.split('/').length >= 2;
        })
        .map(tag => tag.id);
    
      if (usefulTags.length === 0) {
        return 'Original article has no specific tags for similarity matching.';
      }
    
      // Search for articles with shared tags
      const similarityThreshold = params.similarity_threshold || 2;
      const excludeSameSection = params.exclude_same_section || false;
      const maxDaysOld = params.max_days_old;
    
      const relatedArticles: any[] = [];
    
      // Search for each tag and collect results (limit to first 5 tags to avoid too many API calls)
      for (const tag of usefulTags.slice(0, 5)) {
        const searchParams: Record<string, any> = {
          tag: tag,
          'show-tags': 'all',
          'show-fields': 'headline,standfirst,byline,publication,firstPublicationDate',
          'page-size': 20
        };
    
        if (maxDaysOld && originalDate) {
          // Calculate date range
          const origDate = new Date(originalDate);
          const minDate = new Date(origDate.getTime() - maxDaysOld * 24 * 60 * 60 * 1000);
          const maxDate = new Date(origDate.getTime() + maxDaysOld * 24 * 60 * 60 * 1000);
          
          searchParams['from-date'] = minDate.toISOString().substring(0, 10);
          searchParams['to-date'] = maxDate.toISOString().substring(0, 10);
        }
    
        try {
          const tagResponse = await client.search(searchParams);
          const articles = tagResponse.response.results;
          
          for (const article of articles) {
            if (article.id !== originalArticle.id) { // Exclude original
              relatedArticles.push(article);
            }
          }
        } catch (error) {
          // Continue with other tags if one fails
          continue;
        }
      }
    
      // Count shared tags and rank by similarity
      const similarityScores: Record<string, { article: any; sharedTags: number }> = {};
      
      for (const article of relatedArticles) {
        const articleId = article.id;
        if (!(articleId in similarityScores)) {
          const articleTags = (article.tags || []).map((tag: any) => tag.id);
          const sharedCount = usefulTags.filter(tag => articleTags.includes(tag)).length;
    
          // Apply filters
          if (excludeSameSection && article.sectionId === originalSection) {
            continue;
          }
    
          if (sharedCount >= similarityThreshold) {
            similarityScores[articleId] = {
              article: article,
              sharedTags: sharedCount
            };
          }
        }
      }
    
      // Sort by similarity and limit results
      const pageSize = params.page_size || 10;
      const sortedSimilar = Object.values(similarityScores)
        .sort((a, b) => b.sharedTags - a.sharedTags)
        .slice(0, pageSize);
    
      if (sortedSimilar.length > 0) {
        let result = `Found ${sortedSimilar.length} related article(s) to '${originalArticle.webTitle || 'Unknown'}':\n\n`;
    
        sortedSimilar.forEach((item, index) => {
          const article = item.article;
          const sharedCount = item.sharedTags;
    
          result += `**${index + 1}. ${article.webTitle || 'Untitled'}** (Similarity: ${sharedCount} shared tags)\n`;
    
          // Show shared tags for transparency
          const articleTags = (article.tags || []).map((tag: any) => tag.id);
          const sharedTags = usefulTags.filter(tag => articleTags.includes(tag));
          if (sharedTags.length > 0) {
            result += `Shared tags: ${sharedTags.slice(0, 3).join(', ')}${sharedTags.length > 3 ? ' (+' + (sharedTags.length - 3) + ' more)' : ''}\n`;
          }
    
          if (article.fields) {
            const { fields } = article;
            
            if (fields.byline) {
              result += `By: ${fields.byline}\n`;
            }
            
            if (fields.firstPublicationDate) {
              const pubDate = fields.firstPublicationDate.substring(0, 10);
              result += `Published: ${pubDate}\n`;
            }
            
            if (fields.standfirst) {
              result += `Summary: ${fields.standfirst}\n`;
            }
          }
    
          result += `Section: ${article.sectionName || 'Unknown'}\n`;
          result += `URL: ${article.webUrl || 'N/A'}\n\n`;
        });
    
        return result;
      } else {
        return `No related articles found with at least ${similarityThreshold} shared tags.`;
      }
    }
  • Zod schema for validating input parameters to the guardian_find_related tool.
    export const FindRelatedParamsSchema = z.object({
      article_id: z.string(),
      similarity_threshold: z.number().min(1).max(10).optional(),
      exclude_same_section: z.boolean().optional(),
      max_days_old: z.number().min(1).optional(),
      page_size: z.number().min(1).max(50).optional(),
    });
  • Registration of the tool handler in the tools registry: imports the handler and maps 'guardian_find_related' to it within registerTools function.
    import { guardianFindRelated } from './guardian-find-related.js';
    import { guardianGetArticleTags } from './guardian-get-article-tags.js';
    import { guardianContentTimeline } from './guardian-content-timeline.js';
    import { guardianAuthorProfile } from './guardian-author-profile.js';
    import { guardianTopicTrends } from './guardian-topic-trends.js';
    import { guardianTopStoriesByDate } from './guardian-top-stories-by-date.js';
    import { guardianRecommendLongreads } from './guardian-recommend-longreads.js';
    
    export type ToolHandler = (args: any) => Promise<string>;
    
    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),
  • src/index.ts:353-386 (registration)
    MCP tool registration in ListToolsRequestSchema handler: defines the tool name, description, and input schema for the protocol.
      name: 'guardian_find_related',
      description: 'Find articles related to a given article using shared tags',
      inputSchema: {
        type: 'object',
        properties: {
          article_id: {
            type: 'string',
            description: 'Guardian article ID or full URL to find related articles for',
          },
          similarity_threshold: {
            type: 'integer',
            description: 'Minimum number of shared tags required (default: 2)',
            minimum: 1,
            maximum: 10,
          },
          exclude_same_section: {
            type: 'boolean',
            description: 'Exclude articles from the same section (default: false)',
          },
          max_days_old: {
            type: 'integer',
            description: 'Only find articles within this many days of the original (default: unlimited)',
            minimum: 1,
          },
          page_size: {
            type: 'integer',
            description: 'Results per page, max 50 (default: 10)',
            minimum: 1,
            maximum: 50,
          },
        },
        required: ['article_id'],
      },
    },
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 of behavioral disclosure. It states the tool finds articles based on shared tags but doesn't cover critical aspects like whether this is a read-only operation, potential rate limits, authentication needs, error handling, or the format of returned results. For a tool with 5 parameters and no output schema, this is a significant gap in transparency.

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: 'Find articles related to a given article using shared tags.' It's front-loaded with the core purpose, has zero redundant words, and appropriately sized for the tool's complexity, making it highly concise and well-structured.

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 tool's moderate complexity (5 parameters, no annotations, no output schema), the description is incomplete. It lacks information on behavioral traits (e.g., read-only status, error handling), output format, and usage distinctions from siblings. While the schema covers parameters well, the overall context for an agent to invoke the tool effectively is insufficient.

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 input schema has 100% description coverage, providing clear details for all 5 parameters (e.g., 'article_id' as Guardian ID or URL, 'similarity_threshold' as minimum shared tags). The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 for high schema coverage without compensating value.

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: 'Find articles related to a given article using shared tags.' It specifies the verb ('Find'), resource ('articles'), and mechanism ('using shared tags'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'guardian_search' or 'guardian_search_tags,' which could also retrieve articles based on tags, leaving some room for improvement in sibling distinction.

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 context by mentioning 'related to a given article' and 'shared tags,' suggesting it's for finding semantically similar articles rather than general searches. However, it lacks explicit guidance on when to use this tool versus alternatives like 'guardian_search' or 'guardian_search_tags,' and doesn't mention prerequisites or exclusions, leaving the agent to infer usage scenarios.

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