get_week_year
Retrieve the week and ISO week of the year for a specific date using this tool. Enhance time-sensitive applications by accurately determining week-based temporal data.
Instructions
Get the week and isoWeek of the year.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | The date to get the week and isoWeek of the year. e.g. 2025-03-23 |
Implementation Reference
- src/index.ts:183-189 (handler)Core handler function that computes the week and ISO week of the year for the given date or current date using dayjs.week() and dayjs.isoWeek().function getWeekOfYear(date?: string) { const week = date ? dayjs(date).week() : dayjs().week(); const isoWeek = date ? dayjs(date).isoWeek() : dayjs().isoWeek(); return { week, isoWeek, };
- src/tools.ts:101-113 (schema)Defines the tool's metadata: name, description, and input schema (optional date string).export const GET_WEEK_YEAR: Tool = { name: 'get_week_year', description: 'Get the week and isoWeek of the year.', inputSchema: { type: 'object', properties: { date: { type: 'string', description: 'The date to get the week and isoWeek of the year. e.g. 2025-03-23', }, }, }, };
- src/index.ts:125-140 (handler)Tool call dispatcher case: validates arguments, calls getWeekOfYear, and formats the response.case 'get_week_year': { if (!checkWeekOfYearArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const { date } = args; const { week, isoWeek } = getWeekOfYear(date); return { success: true, content: [ { type: 'text', text: `The week of the year is ${week}, and the isoWeek of the year is ${isoWeek}.`, }, ], }; }
- src/index.ts:30-34 (registration)Registers the tool in the ListToolsRequestHandler by including it in the tools array.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], }; });
- src/index.ts:254-260 (helper)Input validation helper for get_week_year tool arguments (checks if date is string or absent).function checkWeekOfYearArgs(args: unknown): args is { date: string } { return ( typeof args === 'object' && args !== null && ('date' in args ? typeof args.date === 'string' : true) ); }