get-nytimes-news
Retrieve New York Times articles in English or Chinese, covering international politics, economics, culture, technology, and arts. Choose region and section for targeted news access.
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 main 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 retrieve the news items.func: async (args) => { const url = nytimesRequestSchema.parse(args); return getRssItems(url); },
- src/tools/nytimes.ts:4-23 (schema)Zod schema defining the input parameters (region and section) and transforming them into the appropriate New York Times RSS URL.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)Tool registration using defineToolConfig, specifying name, description, schema, and handler function.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)Helper function that fetches an RSS feed using getRss, parses the XML, and extracts structured news items (title, description, category, author, publish_time, 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, }; }); };