|
| 1 | +import type { PromptArgument } from '@modelcontextprotocol/sdk/types.js'; |
| 2 | + |
| 3 | +import { fixedAjvCompile } from '../tools/utils.js'; |
| 4 | +import type { PromptBase } from '../types.js'; |
| 5 | +import { ajv } from '../utils/ajv.js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Prompt MCP arguments list. |
| 9 | + */ |
| 10 | +const args: PromptArgument[] = [ |
| 11 | + { |
| 12 | + name: 'topic', |
| 13 | + description: 'The topic to retrieve the latest news on.', |
| 14 | + required: true, |
| 15 | + }, |
| 16 | + { |
| 17 | + name: 'timespan', |
| 18 | + description: 'The timespan for which to retrieve news articles. Defaults to "7 days". For example "1 day", "3 days", "7 days", "1 month", etc.', |
| 19 | + required: false, |
| 20 | + }, |
| 21 | +]; |
| 22 | + |
| 23 | +/** |
| 24 | + * Prompt AJV arguments schema for validation. |
| 25 | + */ |
| 26 | +const argsSchema = fixedAjvCompile(ajv, { |
| 27 | + type: 'object', |
| 28 | + properties: { |
| 29 | + ...Object.fromEntries(args.map((arg) => [arg.name, { |
| 30 | + type: 'string', |
| 31 | + description: arg.description, |
| 32 | + default: arg.default, |
| 33 | + examples: arg.examples, |
| 34 | + }])), |
| 35 | + }, |
| 36 | + required: [...args.filter((arg) => arg.required).map((arg) => arg.name)], |
| 37 | +}); |
| 38 | + |
| 39 | +/** |
| 40 | + * Actual prompt definition. |
| 41 | + */ |
| 42 | +export const latestNewsOnTopicPrompt: PromptBase = { |
| 43 | + name: 'GetLatestNewsOnTopic', |
| 44 | + description: 'This prompt retrieves the latest news articles on a selected topic.', |
| 45 | + arguments: args, |
| 46 | + ajvValidate: argsSchema, |
| 47 | + render: (data) => { |
| 48 | + const currentDateUtc = new Date().toISOString().split('T')[0]; |
| 49 | + const timespan = data.timespan && data.timespan.trim() !== '' ? data.timespan : '7 days'; |
| 50 | + return `I want you to use the RAG web browser to search the web for the latest news on the "${data.topic}" topic. Retrieve news from the last ${timespan}. The RAG web browser accepts a query parameter that supports all Google input, including filters and flags—be sure to use them to accomplish my goal. Today is ${currentDateUtc} UTC.`; |
| 51 | + }, |
| 52 | +}; |
0 commit comments