guardian_get_article
Retrieve the full content and metadata of specific Guardian articles using their ID or URL, customizable with fields like headline, body, and publication date.
Instructions
Retrieve full content of a specific Guardian article
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| article_id | Yes | The Guardian article ID or full URL (e.g., "politics/2024/dec/01/example" or "https://www.theguardian.com/politics/2024/dec/01/example") | |
| show_fields | No | Fields to include (default: headline,standfirst,body,byline,publication,firstPublicationDate) | |
| truncate | No | Whether to truncate content to preview length (default: false for full content) |
Implementation Reference
- src/tools/guardian-get-article.ts:5-30 (handler)The main handler function that executes the tool logic: parses input, fetches article from Guardian API, formats and returns the content.export async function guardianGetArticle(client: GuardianClient, args: any): Promise<string> { const params = GetArticleParamsSchema.parse(args); // Parse URL if provided instead of article ID const articleId = parseGuardianUrl(params.article_id); const showFields = params.show_fields || 'headline,standfirst,body,byline,publication,firstPublicationDate'; const response = await client.getArticle(articleId, { 'show-fields': showFields, 'show-tags': 'all' }); const content = response.response.content; if (content) { // For v2.0: Default to full content, allow truncation if explicitly requested const formatOptions = { truncate: params.truncate ?? false, maxLength: 500, showTags: true }; return formatArticleResponse([content], undefined, formatOptions); } else { return 'Article not found.'; } }
- src/types/guardian.ts:79-83 (schema)Zod schema for input validation used within the handler.export const GetArticleParamsSchema = z.object({ article_id: z.string(), show_fields: z.string().optional(), truncate: z.boolean().optional(), });
- src/index.ts:119-140 (schema)Public JSON schema for the tool input as defined in the MCP server ListTools response.{ name: 'guardian_get_article', description: 'Retrieve full content of a specific Guardian article', inputSchema: { type: 'object', properties: { article_id: { type: 'string', description: 'The Guardian article ID or full URL (e.g., "politics/2024/dec/01/example" or "https://www.theguardian.com/politics/2024/dec/01/example")', }, show_fields: { type: 'string', description: 'Fields to include (default: headline,standfirst,body,byline,publication,firstPublicationDate)', }, truncate: { type: 'boolean', description: 'Whether to truncate content to preview length (default: false for full content)', }, }, required: ['article_id'], }, },
- src/tools/index.ts:24-24 (registration)Registration of the handler function in the tools map returned by registerTools.guardian_get_article: (args) => guardianGetArticle(client, args),