guardian_browse_section
Retrieve recent articles from a specific Guardian section by specifying the section ID, days back, and page size. Access full-text archives dating back to 1999 for comprehensive research or news tracking.
Instructions
Browse recent articles from a specific Guardian section
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days_back | No | How many days back to search (default: 7) | |
| page_size | No | Number of results, max 200 (default: 20) | |
| section | Yes | Section ID (use guardian_get_sections to find valid IDs) |
Implementation Reference
- The core handler function that implements the guardian_browse_section tool. It validates input args using BrowseSectionParamsSchema, computes the from-date based on days_back, constructs Guardian API search parameters filtered by section and recency, fetches articles, and returns a formatted response with truncated content for performance.export async function guardianBrowseSection(client: GuardianClient, args: any): Promise<string> { const params = BrowseSectionParamsSchema.parse(args); const daysBack = params.days_back || 7; const fromDate = calculateDateFromDaysBack(daysBack); const searchParams: Record<string, any> = { section: params.section, 'from-date': fromDate, 'order-by': 'newest', 'page-size': params.page_size || 20, 'show-fields': 'headline,standfirst,byline,publication,firstPublicationDate' }; const response = await client.search(searchParams); const articles = response.response.results; const pagination = response.response; // For search results, default to truncated content for performance const formatOptions = { truncate: true, maxLength: 500 }; return formatArticleResponse(articles, pagination, formatOptions); }
- src/types/guardian.ts:100-104 (schema)Zod input validation schema used by the handler to parse and validate arguments for the guardian_browse_section tool.export const BrowseSectionParamsSchema = z.object({ section: z.string(), days_back: z.number().min(1).max(365).optional(), page_size: z.number().min(1).max(200).optional(), });
- src/tools/index.ts:27-27 (registration)Registers the guardian_browse_section handler function in the central tools registry returned by registerTools(client).guardian_browse_section: (args) => guardianBrowseSection(client, args),
- src/index.ts:202-226 (schema)MCP protocol input schema definition for the guardian_browse_section tool, provided in the ListTools response for client validation.name: 'guardian_browse_section', description: 'Browse recent articles from a specific Guardian section', inputSchema: { type: 'object', properties: { section: { type: 'string', description: 'Section ID (use guardian_get_sections to find valid IDs)', }, days_back: { type: 'integer', description: 'How many days back to search (default: 7)', minimum: 1, maximum: 365, }, page_size: { type: 'integer', description: 'Number of results, max 200 (default: 20)', minimum: 1, maximum: 200, }, }, required: ['section'], }, },
- src/index.ts:576-584 (registration)The handleToolCall method that dynamically retrieves and executes the registered tool handler (including guardian_browse_section) based on the tool name from CallTool requests.const tools = registerTools(this.guardianClient); const tool = tools[toolName]; if (!tool) { throw new Error(`Unknown tool: ${toolName}`); } return await tool(args); }