get-nytimes-news
Access The New York Times news with articles on international politics, economics, culture, technology, and arts. Choose regions (CN or global) and customize sections for tailored updates.
Instructions
获取纽约时报新闻,包含国际政治、经济金融、社会文化、科学技术及艺术评论的高质量英文或中文国际新闻资讯
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | cn | |
| section | No | 分类,当 `region` 为 `cn` 时无效。可选值: Africa, Americas, ArtandDesign, Arts, AsiaPacific, Automobiles, Baseball, Books/Review, Business, Climate, CollegeBasketball, CollegeFootball, Dance, Dealbook, DiningandWine, Economy, Education, EnergyEnvironment, Europe, FashionandStyle, Golf, Health, Hockey, HomePage, Jobs, Lens, MediaandAdvertising, MiddleEast, MostEmailed, MostShared, MostViewed, Movies, Music, NYRegion, Obituaries, PersonalTech, Politics, ProBasketball, ProFootball, RealEstate, Science, SmallBusiness, Soccer, Space, Sports, SundayBookReview, Sunday-Review, Technology, Television, Tennis, Theater, TMagazine, Travel, Upshot, US, Weddings, Well, World, YourMoney | HomePage |
Implementation Reference
- src/tools/nytimes.ts:29-32 (handler)The handler function for the 'get-nytimes-news' tool. It parses the input arguments using the schema to obtain the RSS URL and calls the getRssItems helper to fetch the news items.func: async (args) => { const url = nytimesRequestSchema.parse(args); return getRssItems(url); },
- src/tools/nytimes.ts:4-23 (schema)Zod schema for input validation and transformation to RSS URL based on region (cn/global) and optional section.const nytimesRequestSchema = z .object({ region: z .union([z.literal('cn').describe('中文'), z.literal('global').describe('全球')]) .optional() .default('cn'), section: z .string() .optional() .default('HomePage') .describe( '分类,当 `region` 为 `cn` 时无效。可选值: Africa, Americas, ArtandDesign, Arts, AsiaPacific, Automobiles, Baseball, Books/Review, Business, Climate, CollegeBasketball, CollegeFootball, Dance, Dealbook, DiningandWine, Economy, Education, EnergyEnvironment, Europe, FashionandStyle, Golf, Health, Hockey, HomePage, Jobs, Lens, MediaandAdvertising, MiddleEast, MostEmailed, MostShared, MostViewed, Movies, Music, NYRegion, Obituaries, PersonalTech, Politics, ProBasketball, ProFootball, RealEstate, Science, SmallBusiness, Soccer, Space, Sports, SundayBookReview, Sunday-Review, Technology, Television, Tennis, Theater, TMagazine, Travel, Upshot, US, Weddings, Well, World, YourMoney', ), }) .transform((values) => { if (values.region === 'cn') { return 'https://cn.nytimes.com/rss/'; } return `https://rss.nytimes.com/services/xml/rss/nyt/${values.section || 'HomePage'}.xml`; });
- src/tools/nytimes.ts:25-33 (registration)Registration of the 'get-nytimes-news' tool using defineToolConfig, including name, description, schema reference, and handler.export default defineToolConfig({ name: 'get-nytimes-news', description: '获取纽约时报新闻,包含国际政治、经济金融、社会文化、科学技术及艺术评论的高质量英文或中文国际新闻资讯', zodSchema: nytimesRequestSchema, func: async (args) => { const url = nytimesRequestSchema.parse(args); return getRssItems(url); }, });
- src/utils/rss.ts:10-32 (helper)Shared helper function that fetches RSS feed using getRss, parses items, and extracts title, description, category, author, publish_time, and link.export const getRssItems = async (url: string) => { const data = await getRss(url); if (!Array.isArray(data.rss?.channel?.item)) { return []; } return (data.rss.channel.item as any[]).map((item) => { let category = ''; if (typeof item.category === 'string') { category = item.category; } if (Array.isArray(item.category)) { category = item.category.join(', '); } return { title: item.title, description: item.description, category, author: item.author || item['dc:creator'], publish_time: item.pubDate, link: item.link, }; }); };