guardian_longread
Filter and search The Guardian's Long Read articles by query, date range, and page size to access in-depth journalism efficiently.
Instructions
Search specifically for articles from The Long Read series
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | No | Start date (YYYY-MM-DD format) | |
| page | No | Page number (default: 1) | |
| page_size | No | Results per page, max 200 (default: 10) | |
| query | No | Search terms within Long Read articles | |
| to_date | No | End date (YYYY-MM-DD format) |
Implementation Reference
- src/tools/guardian-longread.ts:5-41 (handler)Core handler function that searches for Guardian Long Read articles using the specific series tag, validates and applies date/query filters, and returns formatted paginated results.export async function guardianLongread(client: GuardianClient, args: any): Promise<string> { const params = LongReadParamsSchema.parse(args); // Search for Long Read articles using the specific tag const searchParams: Record<string, any> = { tag: 'news/series/the-long-read', 'page-size': params.page_size || 10, page: params.page || 1, 'show-fields': 'headline,standfirst,body,byline,thumbnail,publication,firstPublicationDate' }; if (params.query) { searchParams.q = params.query; } 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; } 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:85-91 (schema)Zod schema used for input validation in the guardian_longread handler.export const LongReadParamsSchema = z.object({ query: 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(), page_size: z.number().min(1).max(200).optional(), page: z.number().min(1).optional(), });
- src/tools/index.ts:25-25 (registration)Registers the guardian_longread tool by wrapping the handler function with client injection.guardian_longread: (args) => guardianLongread(client, args),
- src/index.ts:141-172 (registration)MCP tool registration including name, description, and input schema advertised in ListTools response.{ name: 'guardian_longread', description: 'Search specifically for articles from The Long Read series', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search terms within Long Read articles', }, from_date: { type: 'string', description: 'Start date (YYYY-MM-DD format)', }, to_date: { type: 'string', description: 'End date (YYYY-MM-DD format)', }, page_size: { type: 'integer', description: 'Results per page, max 200 (default: 10)', minimum: 1, maximum: 200, }, page: { type: 'integer', description: 'Page number (default: 1)', minimum: 1, }, }, }, },
- src/tools/guardian-longread.ts:38-40 (helper)Uses formatArticleResponse helper to format the search results (imported from utils/formatters.js). Note: full helper in separate file but referenced here.// For search results, default to truncated content for performance const formatOptions = { truncate: true, maxLength: 500 }; return formatArticleResponse(articles, pagination, formatOptions);