Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

subtract_time

Calculate a past date by subtracting a specified duration (years, months, days, hours, minutes, or seconds) from any given time, with timezone support.

Instructions

Subtract duration from a date/time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeYesBase time
amountYesAmount to subtract
unitYesUnit of time
timezoneNoTimezone for calculation (default: system timezone)

Implementation Reference

  • The core handler function for the 'subtract_time' tool. It subtracts time by calling addTime with a negative amount, includes caching via withCache, timezone resolution, and debug logging.
    export function subtractTime(params: SubtractTimeParams): SubtractTimeResult {
      debug.timing('subtractTime called with params: %O', params);
    
      const { time, amount, unit, timezone } = params;
      const config = getConfig();
    
      // Determine the effective timezone for cache key
      const effectiveTimezone = resolveTimezone(timezone, config.defaultTimezone);
    
      // Use withCache wrapper instead of manual cache management
      return withCache(
        `subtract_${time}_${amount}_${unit}_${effectiveTimezone}`,
        CacheTTL.CALCULATIONS,
        () => {
          debug.timing('Delegating to addTime with negated amount: %d', -amount);
    
          // Subtraction is just addition with negative amount
          const result = addTime({
            time,
            amount: -amount, // Negate the amount
            unit,
            timezone,
          });
    
          debug.timing('subtractTime returning: %O', result);
          return result;
        }
      );
    }
  • Input schema for the 'subtract_time' tool, defining parameters, types, descriptions, and required fields.
    inputSchema: {
      type: 'object' as const,
      properties: {
        time: { type: 'string' as const, description: 'Base time' },
        amount: { type: 'number' as const, description: 'Amount to subtract' },
        unit: {
          type: 'string' as const,
          enum: ['years', 'months', 'days', 'hours', 'minutes', 'seconds'],
          description: 'Unit of time',
        },
        timezone: {
          type: 'string' as const,
          description: 'Timezone for calculation (default: system timezone)',
        },
      },
      required: ['time', 'amount', 'unit'],
    },
  • src/index.ts:94-114 (registration)
    Registration of the 'subtract_time' tool in TOOL_DEFINITIONS array, including name, description, and schema.
    {
      name: 'subtract_time',
      description: 'Subtract duration from a date/time',
      inputSchema: {
        type: 'object' as const,
        properties: {
          time: { type: 'string' as const, description: 'Base time' },
          amount: { type: 'number' as const, description: 'Amount to subtract' },
          unit: {
            type: 'string' as const,
            enum: ['years', 'months', 'days', 'hours', 'minutes', 'seconds'],
            description: 'Unit of time',
          },
          timezone: {
            type: 'string' as const,
            description: 'Timezone for calculation (default: system timezone)',
          },
        },
        required: ['time', 'amount', 'unit'],
      },
    },
  • src/index.ts:263-263 (registration)
    Mapping of 'subtract_time' to the subtractTime handler function in TOOL_FUNCTIONS object.
    subtract_time: (params: unknown) => subtractTime(params as Parameters<typeof subtractTime>[0]),
  • TypeScript type definitions for SubtractTimeParams (aliases AddTimeParams) and SubtractTimeResult (aliases TimeCalculationResult). Note: full AddTimeParams and TimeCalculationResult defined above in lines 58-72.
    export type SubtractTimeParams = AddTimeParams;
    
    export interface TimeCalculationResult {
      original: string;
      result: string;
      unix_original: number;
      unix_result: number;
    }
    
    // Type alias for consistency with test
    export type AddTimeResult = TimeCalculationResult;
    export type SubtractTimeResult = TimeCalculationResult;
  • src/tools/index.ts:5-5 (registration)
    Export of subtractTime function from its module for use in src/index.ts.
    export { subtractTime } from './subtractTime';
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the operation but doesn't cover error handling, timezone implications beyond the schema's default note, or output format (e.g., whether it returns a string or object). This is inadequate for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste—it directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, earning full marks for conciseness.

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

Completeness2/5

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

Given the tool's complexity (date/time manipulation with multiple parameters) and lack of annotations and output schema, the description is insufficient. It doesn't explain the return value, error conditions, or behavioral nuances, leaving significant gaps for the agent to operate effectively.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional meaning beyond what's in the schema (e.g., no examples or edge cases), meeting the baseline of 3 where the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('subtract') and resource ('duration from a date/time'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'add_time' beyond the opposite operation, missing explicit comparison that would earn a 5.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'add_time' or 'calculate_duration'. The description lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

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/pshempel/mcp-time-server-node'

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