{"version":3,"sources":["../src/index.ts","../src/tools.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport dayjs from 'dayjs';\nimport isoWeek from 'dayjs/plugin/isoWeek.js';\nimport relativeTime from 'dayjs/plugin/relativeTime.js';\nimport timezone from 'dayjs/plugin/timezone.js';\nimport utc from 'dayjs/plugin/utc.js';\nimport weekOfYear from 'dayjs/plugin/weekOfYear.js';\n\nimport {\n  CONVERT_TIME,\n  CURRENT_TIME,\n  DAYS_IN_MONTH,\n  GET_TIMESTAMP,\n  GET_WEEK_YEAR,\n  RELATIVE_TIME,\n} from './tools.js';\n\ndayjs.extend(relativeTime);\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(weekOfYear);\ndayjs.extend(isoWeek);\n\n// Helper functions\nfunction getCurrentTime(format: string, timezone?: string) {\n  const utcTime = dayjs.utc();\n  const localTimezone = timezone ?? dayjs.tz.guess();\n  const localTime = utcTime.tz(localTimezone);\n  return {\n    utc: utcTime.format(format),\n    local: localTime.format(format),\n    timezone: localTimezone,\n  };\n}\n\nfunction getRelativeTime(time: string) {\n  return dayjs(time).fromNow();\n}\n\nfunction getTimestamp(time?: string) {\n  return time ? dayjs.utc(time).valueOf() : dayjs().valueOf();\n}\n\nfunction getDaysInMonth(date?: string) {\n  return date ? dayjs(date).daysInMonth() : dayjs().daysInMonth();\n}\n\nfunction getWeekOfYear(date?: string) {\n  const week = date ? dayjs(date).week() : dayjs().week();\n  const isoWeek = date ? dayjs(date).isoWeek() : dayjs().isoWeek();\n  return {\n    week,\n    isoWeek,\n  };\n}\n\nfunction convertTime(sourceTimezone: string, targetTimezone: string, time?: string) {\n  const sourceTime = time ? dayjs.tz(time, sourceTimezone) : dayjs().tz(sourceTimezone);\n  const targetTime = sourceTime.tz(targetTimezone);\n  const formatString = 'YYYY-MM-DD HH:mm:ss';\n  const timeDiffMinutes = targetTime.utcOffset() - sourceTime.utcOffset();\n  return {\n    sourceTime: sourceTime.format(formatString),\n    targetTime: targetTime.format(formatString),\n    timeDiff: timeDiffMinutes / 60,\n  };\n}\n\nconst server = new McpServer({\n  name: 'time-mcp',\n  version: '1.0.6',\n}, {\n  capabilities: {\n    tools: {},\n    logging: {},\n  },\n});\n\n// Register current_time tool\nserver.registerTool(\n  CURRENT_TIME.name,\n  {\n    description: CURRENT_TIME.description,\n    inputSchema: CURRENT_TIME.schema,\n  },\n  (args) => {\n    const result = getCurrentTime(args.format, args.timezone);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: `Current UTC time is ${result.utc}, and the time in ${result.timezone} is ${result.local}.`,\n        },\n      ],\n    };\n  },\n);\n\n// Register relative_time tool\nserver.registerTool(\n  RELATIVE_TIME.name,\n  {\n    description: RELATIVE_TIME.description,\n    inputSchema: RELATIVE_TIME.schema,\n  },\n  (args) => {\n    const result = getRelativeTime(args.time);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: result,\n        },\n      ],\n    };\n  },\n);\n\n// Register days_in_month tool\nserver.registerTool(\n  DAYS_IN_MONTH.name,\n  {\n    description: DAYS_IN_MONTH.description,\n    inputSchema: DAYS_IN_MONTH.schema,\n  },\n  (args) => {\n    const result = getDaysInMonth(args.date);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: `The number of days in month is ${result}.`,\n        },\n      ],\n    };\n  },\n);\n\n// Register get_timestamp tool\nserver.registerTool(\n  GET_TIMESTAMP.name,\n  {\n    description: GET_TIMESTAMP.description,\n    inputSchema: GET_TIMESTAMP.schema,\n  },\n  (args) => {\n    const result = getTimestamp(args.time);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: args.time\n            ? `The timestamp of ${args.time} (parsed as UTC) is ${result} ms.`\n            : `The current timestamp is ${result} ms.`,\n        },\n      ],\n    };\n  },\n);\n\n// Register convert_time tool\nserver.registerTool(\n  CONVERT_TIME.name,\n  {\n    description: CONVERT_TIME.description,\n    inputSchema: CONVERT_TIME.schema,\n  },\n  (args) => {\n    const { sourceTime, targetTime, timeDiff } = convertTime(args.sourceTimezone, args.targetTimezone, args.time);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: `Current time in ${args.sourceTimezone} is ${sourceTime}, and the time in ${args.targetTimezone} is ${targetTime}. The time difference is ${timeDiff} hours.`,\n        },\n      ],\n    };\n  },\n);\n\n// Register get_week_year tool\nserver.registerTool(\n  GET_WEEK_YEAR.name,\n  {\n    description: GET_WEEK_YEAR.description,\n    inputSchema: GET_WEEK_YEAR.schema,\n  },\n  (args) => {\n    const { week, isoWeek } = getWeekOfYear(args.date);\n    return {\n      content: [\n        {\n          type: 'text' as const,\n          text: `The week of the year is ${week}, and the isoWeek of the year is ${isoWeek}.`,\n        },\n      ],\n    };\n  },\n);\n\nasync function runServer() {\n  try {\n    process.stdout.write('Starting Time MCP server...\\n');\n    const transport = new StdioServerTransport();\n    await server.connect(transport);\n  } catch (error: unknown) {\n    const message = error instanceof Error ? error.message : String(error);\n    process.stderr.write(`Error starting Time MCP server: ${message}\\n`);\n    process.exit(1);\n  }\n}\n\nrunServer().catch(error => {\n  const errorMessage = error instanceof Error ? error.message : String(error);\n  process.stderr.write(`Error running Time MCP server: ${errorMessage}\\n`);\n  process.exit(1);\n});\n","import { z } from 'zod/v4';\n\nexport const CURRENT_TIME = {\n  name: 'current_time',\n  description: 'Get the current date and time.',\n  schema: z.object({\n    format: z.enum([\n      'h:mm A',\n      'h:mm:ss A',\n      'YYYY-MM-DD HH:mm:ss',\n      'YYYY-MM-DD',\n      'YYYY-MM',\n      'MM/DD/YYYY',\n      'MM/DD/YY',\n      'YYYY/MM/DD',\n      'YYYY/MM',\n    ]).describe('The format of the time').default('YYYY-MM-DD HH:mm:ss'),\n    timezone: z.string()\n      .describe('The timezone of the time, IANA timezone name, e.g. Asia/Shanghai')\n      .optional(),\n  }),\n} as const;\n\nexport const RELATIVE_TIME = {\n  name: 'relative_time',\n  description: 'Get the relative time from now.',\n  schema: z.object({\n    time: z.string()\n      .describe('The time to get the relative time from now. Format: YYYY-MM-DD HH:mm:ss'),\n  }),\n} as const;\n\nexport const DAYS_IN_MONTH = {\n  name: 'days_in_month',\n  description: 'Get the number of days in a month. If no date is provided, get the number of days in the current month.',\n  schema: z.object({\n    date: z.string()\n      .describe('The date to get the days in month. Format: YYYY-MM-DD')\n      .optional(),\n  }),\n} as const;\n\nexport const GET_TIMESTAMP = {\n  name: 'get_timestamp',\n  description: 'Get the timestamp for the time.',\n  schema: z.object({\n    time: z.string()\n      .describe('The time to get the timestamp. Format: YYYY-MM-DD HH:mm:ss.SSS')\n      .optional(),\n  }),\n} as const;\n\nexport const CONVERT_TIME = {\n  name: 'convert_time',\n  description: 'Convert time between timezones.',\n  schema: z.object({\n    sourceTimezone: z.string()\n      .describe('The source timezone. IANA timezone name, e.g. Asia/Shanghai'),\n    targetTimezone: z.string()\n      .describe('The target timezone. IANA timezone name, e.g. Europe/London'),\n    time: z.string()\n      .describe('Date and time in 24-hour format. e.g. 2025-03-23 12:30:00'),\n  }),\n} as const;\n\nexport const GET_WEEK_YEAR = {\n  name: 'get_week_year',\n  description: 'Get the week and isoWeek of the year.',\n  schema: z.object({\n    date: z.string()\n      .describe('The date to get the week and isoWeek of the year. e.g. 2025-03-23')\n      .optional(),\n  }),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iBAA0B;AAC1B,mBAAqC;AACrC,mBAAkB;AAClB,qBAAoB;AACpB,0BAAyB;AACzB,sBAAqB;AACrB,iBAAgB;AAChB,wBAAuB;;;ACTvB,gBAAkB;AAEX,IAAM,eAAe;AAAA,EAC1B,MAAM;AAAA,EACN,aAAa;AAAA,EACb,QAAQ,YAAE,OAAO;AAAA,IACf,QAAQ,YAAE,KAAK;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;A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