Skip to main content
Glama
funinii

TrendRadar

by funinii

resolve_date_range

Convert natural language date expressions like 'this week' or 'last 7 days' into precise date ranges for consistent analysis in TrendRadar.

Instructions

【推荐优先调用】将自然语言日期表达式解析为标准日期范围

为什么需要这个工具? 用户经常使用"本周"、"最近7天"等自然语言表达日期,但 AI 模型自己计算日期 可能导致不一致的结果。此工具在服务器端使用精确的当前时间计算,确保所有 AI 模型获得一致的日期范围。

推荐使用流程:

  1. 用户说"分析AI本周的情感倾向"

  2. AI 调用 resolve_date_range("本周") → 获取精确日期范围

  3. AI 调用 analyze_sentiment(topic="ai", date_range=上一步返回的date_range)

Args: expression: 自然语言日期表达式,支持: - 单日: "今天", "昨天", "today", "yesterday" - 周: "本周", "上周", "this week", "last week" - 月: "本月", "上月", "this month", "last month" - 最近N天: "最近7天", "最近30天", "last 7 days", "last 30 days" - 动态: "最近5天", "last 10 days"(任意天数)

Returns: JSON格式的日期范围,可直接用于其他工具的 date_range 参数: { "success": true, "expression": "本周", "date_range": { "start": "2025-11-18", "end": "2025-11-26" }, "current_date": "2025-11-26", "description": "本周(周一到周日,11-18 至 11-26)" }

Examples: 用户:"分析AI本周的情感倾向" AI调用步骤: 1. resolve_date_range("本周") → {"date_range": {"start": "2025-11-18", "end": "2025-11-26"}, ...} 2. analyze_sentiment(topic="ai", date_range={"start": "2025-11-18", "end": "2025-11-26"})

用户:"看看最近7天的特斯拉新闻"
AI调用步骤:
1. resolve_date_range("最近7天")
   → {"date_range": {"start": "2025-11-20", "end": "2025-11-26"}, ...}
2. search_news(query="特斯拉", date_range={"start": "2025-11-20", "end": "2025-11-26"})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool `resolve_date_range` is defined here as an MCP tool, which acts as a wrapper calling `DateParser.resolve_date_range_expression` and returning a JSON string.
    @mcp.tool
    async def resolve_date_range(
        expression: str
    ) -> str:
        """
        【推荐优先调用】将自然语言日期表达式解析为标准日期范围
    
        **为什么需要这个工具?**
        用户经常使用"本周"、"最近7天"等自然语言表达日期,但 AI 模型自己计算日期
        可能导致不一致的结果。此工具在服务器端使用精确的当前时间计算,确保所有
        AI 模型获得一致的日期范围。
    
        **推荐使用流程:**
        1. 用户说"分析AI本周的情感倾向"
        2. AI 调用 resolve_date_range("本周") → 获取精确日期范围
        3. AI 调用 analyze_sentiment(topic="ai", date_range=上一步返回的date_range)
    
        Args:
            expression: 自然语言日期表达式,支持:
                - 单日: "今天", "昨天", "today", "yesterday"
                - 周: "本周", "上周", "this week", "last week"
                - 月: "本月", "上月", "this month", "last month"
                - 最近N天: "最近7天", "最近30天", "last 7 days", "last 30 days"
                - 动态: "最近5天", "last 10 days"(任意天数)
    
        Returns:
            JSON格式的日期范围,可直接用于其他工具的 date_range 参数:
            {
                "success": true,
                "expression": "本周",
                "date_range": {
                    "start": "2025-11-18",
                    "end": "2025-11-26"
                },
                "current_date": "2025-11-26",
                "description": "本周(周一到周日,11-18 至 11-26)"
            }
    
        Examples:
            用户:"分析AI本周的情感倾向"
            AI调用步骤:
            1. resolve_date_range("本周")
               → {"date_range": {"start": "2025-11-18", "end": "2025-11-26"}, ...}
            2. analyze_sentiment(topic="ai", date_range={"start": "2025-11-18", "end": "2025-11-26"})
    
            用户:"看看最近7天的特斯拉新闻"
            AI调用步骤:
            1. resolve_date_range("最近7天")
               → {"date_range": {"start": "2025-11-20", "end": "2025-11-26"}, ...}
            2. search_news(query="特斯拉", date_range={"start": "2025-11-20", "end": "2025-11-26"})
        """
        try:
            result = DateParser.resolve_date_range_expression(expression)
            return json.dumps(result, ensure_ascii=False, indent=2)
        except MCPError as e:
            return json.dumps({
                "success": False,
                "error": e.to_dict()
            }, ensure_ascii=False, indent=2)
  • This is the core logic method `resolve_date_range_expression` that parses the natural language input and computes the actual date range.
    def resolve_date_range_expression(expression: str) -> Dict:
        """
        将自然语言日期表达式解析为标准日期范围
    
        这是专门为 MCP 工具设计的方法,用于在服务器端解析日期表达式,
        避免 AI 模型自己计算日期导致的不一致问题。
    
        Args:
            expression: 自然语言日期表达式,支持:
                - 单日: "今天", "昨天", "today", "yesterday"
                - 本周/上周: "本周", "上周", "this week", "last week"
                - 本月/上月: "本月", "上月", "this month", "last month"
                - 最近N天: "最近7天", "最近30天", "last 7 days", "last 30 days"
                - 动态N天: "最近5天", "last 10 days"
    
        Returns:
            解析结果字典:
            {
                "success": True,
                "expression": "本周",
                "normalized": "this_week",
                "date_range": {
                    "start": "2025-11-18",
                    "end": "2025-11-24"
                },
                "current_date": "2025-11-26",
                "description": "本周(周一到周日)"
            }
    
        Raises:
            InvalidParameterError: 无法识别的日期表达式
    
        Examples:
            >>> DateParser.resolve_date_range_expression("本周")
            {"success": True, "date_range": {"start": "2025-11-18", "end": "2025-11-24"}, ...}
    
            >>> DateParser.resolve_date_range_expression("最近7天")
            {"success": True, "date_range": {"start": "2025-11-20", "end": "2025-11-26"}, ...}
        """
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it's a read-only transformation tool (no destructive hints implied), uses server-side time for consistency, returns JSON with success status and structured date range, and includes current_date and description fields. It doesn't mention rate limits or auth needs, but covers core operational behavior well.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, why needed, usage flow, Args, Returns, Examples) but is somewhat lengthy. Every section adds value: the workflow examples are particularly helpful. It could be slightly more concise in the examples section, but overall it's efficiently organized with front-loaded key information.

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

Completeness5/5

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

Given the tool's complexity (natural language parsing with multiple pattern types), no annotations, and an output schema that documents the return structure, the description is complete. It covers purpose, usage, parameters, return format with examples, and integration with sibling tools. The output schema handles return value documentation, so the description appropriately focuses on operational context.

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

Parameters5/5

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

The schema has 0% description coverage (just 'expression: string'), so the description must fully compensate. It provides extensive parameter semantics: defines 'expression' as natural language date expressions, lists supported patterns (single day, week, month, recent N days, dynamic), gives specific examples in both Chinese and English, and explains the format directly in the Args section.

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

Purpose5/5

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

The description clearly states the tool's purpose: '将自然语言日期表达式解析为标准日期范围' (parse natural language date expressions into standard date ranges). It specifies the verb ('解析' - parse) and resource ('自然语言日期表达式' - natural language date expressions), and distinguishes itself from siblings by focusing on date resolution rather than analysis, search, or other operations.

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

Usage Guidelines5/5

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

The description explicitly provides usage guidelines: it recommends prioritizing this tool ('推荐优先调用') for natural language date expressions to ensure consistency. It gives a clear workflow example with steps and alternatives (e.g., using analyze_sentiment or search_news after resolution), and explains why it's needed versus AI model self-calculation.

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/funinii/TrendRadar'

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