Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel

subtract_time

Calculate a new date/time by subtracting a specified duration from a base time. Supports years, months, days, hours, minutes, and seconds with optional timezone adjustments for accurate results.

Instructions

Subtract duration from a date/time

Input Schema

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

Implementation Reference

  • The core handler function for the 'subtract_time' tool. It delegates subtraction to the 'addTime' function by negating the amount, with caching and debugging.
    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 definition for the 'subtract_time' tool within the TOOL_DEFINITIONS array, used for tools/list response.
    { 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)
    Registration of the subtract_time handler in the TOOL_FUNCTIONS map, used by the tools/call handler.
    subtract_time: (params: unknown) => subtractTime(params as Parameters<typeof subtractTime>[0]),
  • Type definitions for SubtractTimeParams (aliases AddTimeParams) and SubtractTimeResult (aliases TimeCalculationResult), used by the handler.
    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/index.ts:9-12 (registration)
    Import of subtractTime from './tools' in src/index.ts, bringing the handler into the main server scope for registration.
    getCurrentTime, convertTimezone, addTime, subtractTime,

Other Tools

Related 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