Skip to content

Time/date operations #1909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bartolli
Copy link

Adds date calculation capabilities to the MCP time server with two new tools for performing date arithmetic and determining days of the week.

Description

This PR enhances the time server with date operation functionality through two new tools:

  • calculate_date: Performs date arithmetic by adding or subtracting days from a given date
  • get_day_of_week: Determines the day of the week for any given date

Both tools support multiple date formats (YYYY-MM-DD, Month DD YYYY, MM/DD/YYYY, etc.) and provide clear error messages with format hints when parsing fails.

Server Details

  • Server: time
  • Changes to: tools (added 2 new tools)

Motivation and Context

LLMs often struggle with date arithmetic, leading to calculation errors and hallucinations when asked, "What date is 5 days from today?" This PR addresses this by providing deterministic, mathematically accurate date calculations.

Previously, the time server only handled current time and timezone conversions. These new tools enable:

  • Accurate date arithmetic: LLMs can now reliably calculate future/past dates without
    hallucination risks
  • Agentic workflows: Agents can schedule tasks, set reminders, and manage deadlines with
    confidence
  • Memory operations: When storing dated information, agents can calculate relative dates (e.g.,
    "remind me in 10 days")
  • Calendar operations: Verify days of the week for scheduling meetings or events
  • Data processing: Handle date-based queries in datasets with mathematical precision

Example: Instead of an LLM guessing that "today + 5 days = May 30, 2025", it now receives a verified calculation with day-of-week confirmation (Friday), eliminating common errors like incorrect month transitions or leap year mistakes.

Also fixes a bug where McpError was incorrectly initialized with a string instead of an ErrorData object.

How Has This Been Tested?

  • Added 17 comprehensive unit tests covering:
    • Basic date addition/subtraction
    • Month and year boundary crossing
    • Leap year handling
    • Multiple date format support
    • Invalid date error handling
  • All existing tests continue to pass (42 tests total)
  • Manually tested with various date formats and edge cases

Breaking Changes

No breaking changes. This is a non-breaking addition of new functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

  • Date calculations are timezone-aware to ensure accuracy across different time zones
  • The DateCalculationResult includes a calculation_details field that provides human-readable feedback about what operation was performed
  • Error messages include all supported date formats to help LLMS correct input errors

bartolli added 3 commits May 25, 2025 17:15
…te tool for adding/subtracting days from dates\n- Add get_day_of_week tool to determine day of week for any date\n- Support multiple date formats (YYYY-MM-DD, Month DD YYYY, MM/DD/YYYY, etc.)\n- Fix McpError initialization to use ErrorData type correctly\n- Add comprehensive tests for new date operations\n- Update documentation with new tools and examples\n\nThese tools enable accurate date calculations with timezone awareness and provide clear feedback on calculation results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant