Skip to main content
Glama
jbenton

guardian-mcp-server

by jbenton

guardian_top_stories_by_date

Retrieve top-ranked Guardian news stories for a specific date using editorial prioritization, with optional filtering by section and story count.

Instructions

Get intelligently ranked top stories for a specific date using editorial prioritization

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYesDate to analyze (YYYY-MM-DD)
story_countNoNumber of top stories to return (default: 10, max: 20)
sectionNoFilter by section (optional)

Implementation Reference

  • Main handler function implementing the tool: parses args, validates date, searches Guardian API for articles on that date, scores them using intelligent criteria (section, length, pub time, headline keywords, tags, byline), ranks top stories, provides analysis, and formats output.
    export async function guardianTopStoriesByDate(client: GuardianClient, args: any): Promise<string> {
      const params = TopStoriesByDateParamsSchema.parse(args);
    
      const date = validateDate(params.date);
      if (!date) {
        throw new Error(`Invalid date format: ${params.date}. Use YYYY-MM-DD format.`);
      }
    
      const storyCount = params.story_count || 10;
    
      // Get all articles from the specified date
      const searchParams: Record<string, any> = {
        'from-date': date,
        'to-date': date,
        'page-size': 200, // Get as many as possible for intelligent ranking
        'show-fields': 'headline,standfirst,byline,wordcount,firstPublicationDate',
        'show-tags': 'keyword,type',
        'order-by': 'newest'
      };
    
      if (params.section) {
        searchParams.section = params.section;
      }
    
      const response = await client.search(searchParams);
      const articles = response.response.results;
    
      if (articles.length === 0) {
        return `No articles found for ${date}${params.section ? ` in section "${params.section}"` : ''}.`;
      }
    
      // Score and rank articles using intelligent prioritization
      const scoredStories = articles.map(article => scoreStory(article, date));
      const topStories = scoredStories
        .sort((a, b) => b.score - a.score)
        .slice(0, storyCount);
    
      // Format results
      let result = `Top ${storyCount} Stories for ${formatDateForDisplay(date)}:\n`;
      
      if (params.section) {
        result += `Section: ${params.section}\n`;
      }
      
      result += `\n**Intelligent Story Ranking** (based on editorial importance, complexity, and newsworthiness)\n\n`;
    
      topStories.forEach((story, index) => {
        const article = story.article;
        const rank = index + 1;
        const trophy = rank === 1 ? '🏆 ' : rank === 2 ? '🥈 ' : rank === 3 ? '🥉 ' : `${rank}. `;
        
        result += `${trophy}**${article.webTitle || 'Untitled'}**\n`;
        result += `Score: ${story.score.toFixed(1)} (${story.reasons.join(', ')})\n`;
        
        if (article.fields) {
          const { fields } = article;
          
          if (fields.byline) {
            result += `By: ${fields.byline}\n`;
          }
          
          if (fields.standfirst) {
            result += `Summary: ${fields.standfirst}\n`;
          }
          
          if (fields.wordcount) {
            result += `Length: ${fields.wordcount} words\n`;
          }
        }
        
        result += `Section: ${article.sectionName || 'Unknown'}\n`;
        result += `URL: ${article.webUrl || 'N/A'}\n`;
        result += `Guardian ID: ${article.id || 'N/A'}\n\n`;
      });
    
      // Add analysis of the day's news landscape
      result += `**Day's News Analysis**:\n`;
      result += `• Total articles: ${articles.length}\n`;
      
      const sectionBreakdown = getSectionBreakdown(articles);
      result += `• Top sections: ${sectionBreakdown.slice(0, 3).map(s => `${s.section} (${s.count})`).join(', ')}\n`;
      
      const avgScore = topStories.reduce((sum, story) => sum + story.score, 0) / topStories.length;
      result += `• Average story importance: ${avgScore.toFixed(1)}/100\n`;
    
      const complexStories = topStories.filter(s => s.reasons.includes('high complexity')).length;
      if (complexStories > 0) {
        result += `• Major breaking news events: ${complexStories}\n`;
      }
    
      return result;
    }
  • Zod input schema used for validating tool arguments: requires 'date' in YYYY-MM-DD format, optional 'story_count' (1-20), optional 'section'.
    export const TopStoriesByDateParamsSchema = z.object({
      date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
      story_count: z.number().min(1).max(20).optional(),
      section: z.string().optional(),
    });
    
    export const RecommendLongreadsParamsSchema = z.object({
      count: z.number().min(1).max(10).optional(),
      context: z.string().optional(),
      from_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
      topic_preference: z.string().optional(),
    });
    
    export type ContentTimelineParams = z.infer<typeof ContentTimelineParamsSchema>;
    export type AuthorProfileParams = z.infer<typeof AuthorProfileParamsSchema>;
    export type TopicTrendsParams = z.infer<typeof TopicTrendsParamsSchema>;
    export type TopStoriesByDateParams = z.infer<typeof TopStoriesByDateParamsSchema>;
  • Tool registration in the registerTools function, mapping the tool name to its handler.
    guardian_top_stories_by_date: (args) => guardianTopStoriesByDate(client, args),
  • src/index.ts:491-512 (registration)
    MCP server tool list registration including name, description, and input schema for ListToolsRequest.
    name: 'guardian_top_stories_by_date',
    description: 'Get intelligently ranked top stories for a specific date using editorial prioritization',
    inputSchema: {
      type: 'object',
      properties: {
        date: {
          type: 'string',
          description: 'Date to analyze (YYYY-MM-DD)',
        },
        story_count: {
          type: 'integer',
          description: 'Number of top stories to return (default: 10, max: 20)',
          minimum: 1,
          maximum: 20,
        },
        section: {
          type: 'string',
          description: 'Filter by section (optional)',
        },
      },
      required: ['date'],
    },
  • Core helper function scoring each story's importance for ranking based on section priority, article length, publication timing, headline analysis, tags, and author seniority.
    function scoreStory(article: any, date: string): StoryScore {
      let score = 0;
      const reasons: string[] = [];
    
      // Base score from section importance
      const sectionScore = getSectionImportance(article.sectionName);
      score += sectionScore.score;
      if (sectionScore.reason) reasons.push(sectionScore.reason);
    
      // Word count indicates story complexity and importance
      const wordCount = article.fields?.wordcount ? parseInt(article.fields.wordcount) : 0;
      if (wordCount > 1500) {
        score += 20;
        reasons.push('high complexity');
      } else if (wordCount > 800) {
        score += 10;
        reasons.push('detailed coverage');
      } else if (wordCount < 300) {
        score -= 5; // Brief items are less likely to be top stories
      }
    
      // Breaking news patterns (published early in the day often indicates urgency)
      if (article.fields?.firstPublicationDate) {
        const pubTime = new Date(article.fields.firstPublicationDate);
        const hour = pubTime.getHours();
        
        if (hour >= 6 && hour <= 10) {
          score += 15;
          reasons.push('morning breaking news');
        } else if (hour >= 11 && hour <= 14) {
          score += 10;
          reasons.push('midday update');
        }
      }
    
      // Headline analysis for importance indicators
      const headline = article.webTitle?.toLowerCase() || '';
      const importanceKeywords = [
        { words: ['breaking', 'urgent', 'exclusive'], score: 25, label: 'breaking news' },
        { words: ['crisis', 'scandal', 'investigation'], score: 20, label: 'major story' },
        { words: ['election', 'vote', 'poll'], score: 18, label: 'political significance' },
        { words: ['dies', 'dead', 'death', 'killed'], score: 18, label: 'major news' },
        { words: ['wins', 'victory', 'defeat'], score: 15, label: 'significant outcome' },
        { words: ['announces', 'reveals', 'confirms'], score: 12, label: 'official news' },
        { words: ['budget', 'economy', 'recession'], score: 15, label: 'economic importance' },
        { words: ['war', 'attack', 'conflict'], score: 22, label: 'international crisis' },
        { words: ['climate', 'environment', 'warming'], score: 12, label: 'environmental story' }
      ];
    
      for (const keyword of importanceKeywords) {
        if (keyword.words.some(word => headline.includes(word))) {
          score += keyword.score;
          reasons.push(keyword.label);
          break; // Only count one category per headline
        }
      }
    
      // Tag analysis for topic importance
      if (article.tags) {
        const importantTags = article.tags.filter((tag: any) => 
          ['politics', 'world', 'brexit', 'trump', 'climate', 'coronavirus', 'economy'].some(important => 
            tag.id.toLowerCase().includes(important)
          )
        );
        
        if (importantTags.length > 0) {
          score += importantTags.length * 8;
          reasons.push('major topic');
        }
      }
    
      // Byline analysis - senior correspondents often handle bigger stories
      const byline = article.fields?.byline?.toLowerCase() || '';
      const seniorIndicators = ['editor', 'correspondent', 'chief', 'political', 'foreign', 'diplomatic'];
      if (seniorIndicators.some(indicator => byline.includes(indicator))) {
        score += 10;
        reasons.push('senior correspondent');
      }
    
      // Ensure score is within reasonable bounds
      score = Math.max(0, Math.min(100, score));
    
      return { article, score, reasons };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'intelligently ranked' and 'editorial prioritization,' hinting at ranking behavior, but lacks details on what this entails (e.g., criteria, source of prioritization). It doesn't disclose rate limits, authentication needs, error handling, or output format (no output schema exists), which are critical for a read operation with ranking logic.

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 front-loads the core purpose. Every word earns its place: 'Get' (action), 'intelligently ranked top stories' (resource and behavior), 'for a specific date' (key constraint), 'using editorial prioritization' (method). No redundancy or fluff, making it highly scannable and informative.

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

Completeness3/5

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

Given 3 parameters with full schema coverage and no output schema, the description is minimally adequate. It clarifies the tool's focus on date-based, ranked stories but lacks details on ranking mechanics, output structure, or sibling differentiation. For a read-only tool with editorial logic, more behavioral context would improve completeness, though the concise purpose statement meets basic needs.

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?

Schema description coverage is 100%, so the schema fully documents parameters (date, story_count, section). The description adds no parameter-specific semantics beyond implying date relevance and ranking. It doesn't explain optional vs. required parameters or interactions between them, relying entirely on the schema. Baseline 3 is appropriate as the schema handles parameter documentation.

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: 'Get intelligently ranked top stories for a specific date using editorial prioritization.' It specifies the action ('Get'), resource ('top stories'), and key constraints ('for a specific date', 'intelligently ranked', 'editorial prioritization'). However, it doesn't explicitly differentiate from siblings like guardian_search or guardian_content_timeline, which might also retrieve stories by date.

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 guardian_search (which might search stories by date) or guardian_content_timeline (which might provide chronological content). There's no indication of prerequisites, exclusions, or comparative advantages, leaving the agent to infer usage context.

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