获取当前时间及A股交易日信息
get_current_timeRetrieves current system time and A-share market trading day status. Use before tools requiring date parameters to ensure accurate timing.
Instructions
获取当前系统时间及A股交易日信息,建议在调用其他需要日期参数的工具前使用该工具
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_aktools/__init__.py:209-212 (registration)Tool 'get_current_time' is registered via the @mcp.tool decorator with title '获取当前时间及A股交易日信息'.
@mcp.tool( title="获取当前时间及A股交易日信息", description="获取当前系统时间及A股交易日信息,建议在调用其他需要日期参数的工具前使用该工具", ) - mcp_aktools/__init__.py:213-227 (handler)Handler function 'get_current_time' that gets current system time, weekday, and recent A-stock trading days from akshare.
def get_current_time(): now = datetime.now() week = "日一二三四五六日"[now.isoweekday()] texts = [f"当前时间: {now.isoformat()}, 星期{week}"] dfs = ak_cache(ak.tool_trade_date_hist_sina, ttl=43200) if dfs is not None: start = now.date() - timedelta(days=5) ended = now.date() + timedelta(days=5) dates = [ d.strftime("%Y-%m-%d") for d in dfs["trade_date"] if start <= d <= ended ] texts.append(f", 最近交易日有: {','.join(dates)}") return "".join(texts) - mcp_aktools/__init__.py:564-579 (helper)Helper 'ak_cache' used by the handler to cache results from akshare API calls with TTL.
def ak_cache(fun, *args, **kwargs) -> pd.DataFrame | None: key = kwargs.pop("key", None) if not key: key = f"{fun.__name__}-{args}-{kwargs}" ttl1 = kwargs.pop("ttl", 86400) ttl2 = kwargs.pop("ttl2", None) cache = CacheKey.init(key, ttl1, ttl2) all = cache.get() if all is None: try: _LOGGER.info("Request akshare: %s", [key, args, kwargs]) all = fun(*args, **kwargs) cache.set(all) except Exception as exc: _LOGGER.exception(str(exc)) return all