Skip to main content
Glama
lianshuang-photo

SearchAPI MCP Server

get_current_time

Retrieve current time with customizable date formats, offsets, and future date options for scheduling and time-sensitive applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNo日期格式iso
days_offsetNo日期偏移量0
return_future_datesNo是否返回未来日期false
future_daysNo未来天数7

Implementation Reference

  • The handler function for the 'get_current_time' tool. It parses input arguments, computes current time and offset date in multiple formats (ISO, slash, Chinese, timestamp, full), weekdays, builds comprehensive date info, generates travel date suggestions and hotel stay suggestions, optionally generates future dates list, and returns JSON stringified result.
    async (args) => {
      const now = new Date();
      
      // 将字符串参数转换为对应的数据类型
      let daysOffsetInt;
      try {
        daysOffsetInt = args.days_offset ? parseInt(args.days_offset, 10) : 0;
      } catch (e) {
        return {
          content: [{ type: 'text', text: JSON.stringify({ error: 'days_offset必须是整数' }) }],
          isError: true
        };
      }
    
      const returnFutureDatesBool = args.return_future_dates ? args.return_future_dates.toLowerCase() === 'true' : false;
    
      let futureDaysInt;
      try {
        futureDaysInt = args.future_days ? parseInt(args.future_days, 10) : 7;
      } catch (e) {
        return {
          content: [{ type: 'text', text: JSON.stringify({ error: 'future_days必须是整数' }) }],
          isError: true
        };
      }
      
      // 计算目标日期
      const targetDate = new Date(now);
      targetDate.setDate(targetDate.getDate() + daysOffsetInt);
      
      // 格式化日期的辅助函数
      const formatDate = (date, format) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        
        switch (format) {
          case 'iso':
            return `${year}-${month}-${day}`;
          case 'slash':
            return `${day}/${month}/${year}`;
          case 'chinese':
            return `${year}年${month}月${day}日`;
          case 'timestamp':
            return Math.floor(date.getTime() / 1000);
          case 'full':
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
          default:
            return `${year}-${month}-${day}`;
        }
      };
      
      // 获取星期几
      const getWeekday = (date, short = false) => {
        const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
        const shortWeekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
        return short ? shortWeekdays[date.getDay()] : weekdays[date.getDay()];
      };
      
      // 构建结果对象
      const result = {
        now: {
          iso: formatDate(now, 'iso'),
          slash: formatDate(now, 'slash'),
          chinese: formatDate(now, 'chinese'),
          timestamp: formatDate(now, 'timestamp'),
          full: formatDate(now, 'full'),
          time: `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`,
          weekday: getWeekday(now),
          weekday_short: getWeekday(now, true),
          year: now.getFullYear(),
          month: now.getMonth() + 1,
          day: now.getDate(),
          hour: now.getHours(),
          minute: now.getMinutes(),
          second: now.getSeconds()
        },
        target_date: {
          iso: formatDate(targetDate, 'iso'),
          slash: formatDate(targetDate, 'slash'),
          chinese: formatDate(targetDate, 'chinese'),
          timestamp: formatDate(targetDate, 'timestamp'),
          full: formatDate(targetDate, 'full'),
          time: `${String(targetDate.getHours()).padStart(2, '0')}:${String(targetDate.getMinutes()).padStart(2, '0')}:${String(targetDate.getSeconds()).padStart(2, '0')}`,
          weekday: getWeekday(targetDate),
          weekday_short: getWeekday(targetDate, true),
          year: targetDate.getFullYear(),
          month: targetDate.getMonth() + 1,
          day: targetDate.getDate(),
          hour: targetDate.getHours(),
          minute: targetDate.getMinutes(),
          second: targetDate.getSeconds()
        }
      };
      
      // 旅行场景常用日期
      const tomorrow = new Date(now);
      tomorrow.setDate(tomorrow.getDate() + 1);
      
      const nextWeek = new Date(now);
      nextWeek.setDate(nextWeek.getDate() + 7);
      
      const nextMonth = new Date(now);
      nextMonth.setDate(nextMonth.getDate() + 30);
      
      // 计算下一个周五(周末开始)
      const weekend = new Date(now);
      weekend.setDate(weekend.getDate() + ((5 - weekend.getDay() + 7) % 7));
      
      // 计算下一个周日(周末结束)
      const weekendEnd = new Date(now);
      weekendEnd.setDate(weekendEnd.getDate() + ((0 - weekendEnd.getDay() + 7) % 7));
      
      result.travel_dates = {
        today: formatDate(now, 'iso'),
        tomorrow: formatDate(tomorrow, 'iso'),
        next_week: formatDate(nextWeek, 'iso'),
        next_month: formatDate(nextMonth, 'iso'),
        weekend: formatDate(weekend, 'iso'),
        weekend_end: formatDate(weekendEnd, 'iso')
      };
      
      // 对于旅行预订常用的入住-退房日期对
      const tomorrow2Days = new Date(tomorrow);
      tomorrow2Days.setDate(tomorrow2Days.getDate() + 2);
      
      const tomorrow7Days = new Date(tomorrow);
      tomorrow7Days.setDate(tomorrow7Days.getDate() + 7);
      
      const nextMonth2Days = new Date(nextMonth);
      nextMonth2Days.setDate(nextMonth2Days.getDate() + 2);
      
      result.hotel_stay_suggestions = [
        {
          check_in: formatDate(tomorrow, 'iso'),
          check_out: formatDate(tomorrow2Days, 'iso'),
          nights: 2,
          description: '短暂周末度假'
        },
        {
          check_in: formatDate(tomorrow, 'iso'),
          check_out: formatDate(tomorrow7Days, 'iso'),
          nights: 7,
          description: '一周度假'
        },
        {
          check_in: formatDate(nextMonth, 'iso'),
          check_out: formatDate(nextMonth2Days, 'iso'),
          nights: 2,
          description: '下个月短暂出行'
        }
      ];
      
      // 如果需要一系列未来日期
      if (returnFutureDatesBool) {
        const futureDates = [];
        for (let i = 0; i < futureDaysInt; i++) {
          const futureDate = new Date(now);
          futureDate.setDate(futureDate.getDate() + i);
          futureDates.push({
            iso: formatDate(futureDate, 'iso'),
            slash: formatDate(futureDate, 'slash'),
            chinese: formatDate(futureDate, 'chinese'),
            weekday: getWeekday(futureDate),
            weekday_short: getWeekday(futureDate, true),
            days_from_now: i
          });
        }
        result.future_dates = futureDates;
      }
      
      // 使用请求的格式作为主要返回值
      result.date = formatDate(targetDate, args.format || 'iso');
      
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
      };
    }
  • Zod schema for input parameters of the get_current_time tool: format (default 'iso'), days_offset (default '0'), return_future_dates (default 'false'), future_days (default '7').
    {
      format: z.string().default('iso').describe('日期格式'),
      days_offset: z.string().default('0').describe('日期偏移量'),
      return_future_dates: z.string().default('false').describe('是否返回未来日期'),
      future_days: z.string().default('7').describe('未来天数')
    },
  • src/index.js:384-572 (registration)
    Registration of the 'get_current_time' tool using server.tool(name, inputSchema, handlerFn).
      'get_current_time',
      {
        format: z.string().default('iso').describe('日期格式'),
        days_offset: z.string().default('0').describe('日期偏移量'),
        return_future_dates: z.string().default('false').describe('是否返回未来日期'),
        future_days: z.string().default('7').describe('未来天数')
      },
      async (args) => {
        const now = new Date();
        
        // 将字符串参数转换为对应的数据类型
        let daysOffsetInt;
        try {
          daysOffsetInt = args.days_offset ? parseInt(args.days_offset, 10) : 0;
        } catch (e) {
          return {
            content: [{ type: 'text', text: JSON.stringify({ error: 'days_offset必须是整数' }) }],
            isError: true
          };
        }
    
        const returnFutureDatesBool = args.return_future_dates ? args.return_future_dates.toLowerCase() === 'true' : false;
    
        let futureDaysInt;
        try {
          futureDaysInt = args.future_days ? parseInt(args.future_days, 10) : 7;
        } catch (e) {
          return {
            content: [{ type: 'text', text: JSON.stringify({ error: 'future_days必须是整数' }) }],
            isError: true
          };
        }
        
        // 计算目标日期
        const targetDate = new Date(now);
        targetDate.setDate(targetDate.getDate() + daysOffsetInt);
        
        // 格式化日期的辅助函数
        const formatDate = (date, format) => {
          const year = date.getFullYear();
          const month = String(date.getMonth() + 1).padStart(2, '0');
          const day = String(date.getDate()).padStart(2, '0');
          const hours = String(date.getHours()).padStart(2, '0');
          const minutes = String(date.getMinutes()).padStart(2, '0');
          const seconds = String(date.getSeconds()).padStart(2, '0');
          
          switch (format) {
            case 'iso':
              return `${year}-${month}-${day}`;
            case 'slash':
              return `${day}/${month}/${year}`;
            case 'chinese':
              return `${year}年${month}月${day}日`;
            case 'timestamp':
              return Math.floor(date.getTime() / 1000);
            case 'full':
              return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            default:
              return `${year}-${month}-${day}`;
          }
        };
        
        // 获取星期几
        const getWeekday = (date, short = false) => {
          const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
          const shortWeekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
          return short ? shortWeekdays[date.getDay()] : weekdays[date.getDay()];
        };
        
        // 构建结果对象
        const result = {
          now: {
            iso: formatDate(now, 'iso'),
            slash: formatDate(now, 'slash'),
            chinese: formatDate(now, 'chinese'),
            timestamp: formatDate(now, 'timestamp'),
            full: formatDate(now, 'full'),
            time: `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`,
            weekday: getWeekday(now),
            weekday_short: getWeekday(now, true),
            year: now.getFullYear(),
            month: now.getMonth() + 1,
            day: now.getDate(),
            hour: now.getHours(),
            minute: now.getMinutes(),
            second: now.getSeconds()
          },
          target_date: {
            iso: formatDate(targetDate, 'iso'),
            slash: formatDate(targetDate, 'slash'),
            chinese: formatDate(targetDate, 'chinese'),
            timestamp: formatDate(targetDate, 'timestamp'),
            full: formatDate(targetDate, 'full'),
            time: `${String(targetDate.getHours()).padStart(2, '0')}:${String(targetDate.getMinutes()).padStart(2, '0')}:${String(targetDate.getSeconds()).padStart(2, '0')}`,
            weekday: getWeekday(targetDate),
            weekday_short: getWeekday(targetDate, true),
            year: targetDate.getFullYear(),
            month: targetDate.getMonth() + 1,
            day: targetDate.getDate(),
            hour: targetDate.getHours(),
            minute: targetDate.getMinutes(),
            second: targetDate.getSeconds()
          }
        };
        
        // 旅行场景常用日期
        const tomorrow = new Date(now);
        tomorrow.setDate(tomorrow.getDate() + 1);
        
        const nextWeek = new Date(now);
        nextWeek.setDate(nextWeek.getDate() + 7);
        
        const nextMonth = new Date(now);
        nextMonth.setDate(nextMonth.getDate() + 30);
        
        // 计算下一个周五(周末开始)
        const weekend = new Date(now);
        weekend.setDate(weekend.getDate() + ((5 - weekend.getDay() + 7) % 7));
        
        // 计算下一个周日(周末结束)
        const weekendEnd = new Date(now);
        weekendEnd.setDate(weekendEnd.getDate() + ((0 - weekendEnd.getDay() + 7) % 7));
        
        result.travel_dates = {
          today: formatDate(now, 'iso'),
          tomorrow: formatDate(tomorrow, 'iso'),
          next_week: formatDate(nextWeek, 'iso'),
          next_month: formatDate(nextMonth, 'iso'),
          weekend: formatDate(weekend, 'iso'),
          weekend_end: formatDate(weekendEnd, 'iso')
        };
        
        // 对于旅行预订常用的入住-退房日期对
        const tomorrow2Days = new Date(tomorrow);
        tomorrow2Days.setDate(tomorrow2Days.getDate() + 2);
        
        const tomorrow7Days = new Date(tomorrow);
        tomorrow7Days.setDate(tomorrow7Days.getDate() + 7);
        
        const nextMonth2Days = new Date(nextMonth);
        nextMonth2Days.setDate(nextMonth2Days.getDate() + 2);
        
        result.hotel_stay_suggestions = [
          {
            check_in: formatDate(tomorrow, 'iso'),
            check_out: formatDate(tomorrow2Days, 'iso'),
            nights: 2,
            description: '短暂周末度假'
          },
          {
            check_in: formatDate(tomorrow, 'iso'),
            check_out: formatDate(tomorrow7Days, 'iso'),
            nights: 7,
            description: '一周度假'
          },
          {
            check_in: formatDate(nextMonth, 'iso'),
            check_out: formatDate(nextMonth2Days, 'iso'),
            nights: 2,
            description: '下个月短暂出行'
          }
        ];
        
        // 如果需要一系列未来日期
        if (returnFutureDatesBool) {
          const futureDates = [];
          for (let i = 0; i < futureDaysInt; i++) {
            const futureDate = new Date(now);
            futureDate.setDate(futureDate.getDate() + i);
            futureDates.push({
              iso: formatDate(futureDate, 'iso'),
              slash: formatDate(futureDate, 'slash'),
              chinese: formatDate(futureDate, 'chinese'),
              weekday: getWeekday(futureDate),
              weekday_short: getWeekday(futureDate, true),
              days_from_now: i
            });
          }
          result.future_dates = futureDates;
        }
        
        // 使用请求的格式作为主要返回值
        result.date = formatDate(targetDate, args.format || 'iso');
        
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
        };
      }
    );
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lianshuang-photo/searchapi-mcp-nodejs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server