guardian_get_article_tags
Extract topic tags and categorization data from Guardian articles to analyze content themes and organization.
Instructions
Get detailed tag information for a specific Guardian article
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| article_id | Yes | Guardian article ID or full URL to inspect tags for |
Implementation Reference
- The main handler function that executes the tool logic: validates input, fetches article data with tags, groups tags by type, and formats a detailed response.export async function guardianGetArticleTags(client: GuardianClient, args: any): Promise<string> { const params = GetArticleTagsParamsSchema.parse(args); // Parse URL if provided instead of article ID const articleId = parseGuardianUrl(params.article_id); const response = await client.getArticle(articleId, { 'show-tags': 'all', 'show-fields': 'headline' }); const content = response.response.content; if (!content) { return 'Article not found.'; } const tags = content.tags || []; if (tags.length === 0) { return `Article "${content.webTitle || 'Unknown'}" has no tags.`; } let result = `Tags for "${content.webTitle || 'Unknown'}" (${tags.length} total):\n\n`; // Group tags by type for better organization const tagsByType: Record<string, any[]> = {}; tags.forEach(tag => { const type = tag.type || 'unknown'; if (!tagsByType[type]) { tagsByType[type] = []; } tagsByType[type].push(tag); }); // Display tags organized by type Object.entries(tagsByType).forEach(([type, typeTags]) => { result += `**${type.charAt(0).toUpperCase() + type.slice(1)} (${typeTags.length})**\n`; typeTags.forEach(tag => { result += `• ${tag.webTitle} (${tag.id})\n`; }); result += '\n'; }); result += `These tags are used for similarity matching in guardian_find_related tool.`; return result; }
- Internal Zod schema for input validation within the handler.const GetArticleTagsParamsSchema = z.object({ article_id: z.string(), });
- src/tools/index.ts:21-40 (registration)The registerTools function registers all tool handlers, mapping 'guardian_get_article_tags' to the guardianGetArticleTags function.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), guardian_get_article_tags: (args) => guardianGetArticleTags(client, args), guardian_content_timeline: (args) => guardianContentTimeline(client, args), guardian_author_profile: (args) => guardianAuthorProfile(client, args), guardian_topic_trends: (args) => guardianTopicTrends(client, args), guardian_top_stories_by_date: (args) => guardianTopStoriesByDate(client, args), guardian_recommend_longreads: (args) => guardianRecommendLongreads(client, args), }; }
- src/index.ts:388-400 (schema)MCP tool schema definition provided in ListTools response, including name, description, and input schema.name: 'guardian_get_article_tags', description: 'Get detailed tag information for a specific Guardian article', inputSchema: { type: 'object', properties: { article_id: { type: 'string', description: 'Guardian article ID or full URL to inspect tags for', }, }, required: ['article_id'], }, },