Skip to main content
Glama
cds-id

MCP Server Boilerplate

by cds-id

timestamp

Generate current timestamps in ISO, Unix, or readable formats for standardized time data in MCP server applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoiso

Implementation Reference

  • The handler function that computes the current timestamp in the specified format ('iso', 'unix', or 'readable') and returns it as a text content block.
    async ({ format }) => {
      const now = new Date();
      let formattedTime: string;
    
      switch (format) {
        case 'unix':
          formattedTime = Math.floor(now.getTime() / 1000).toString();
          break;
        case 'readable':
          formattedTime = now.toLocaleString();
          break;
        case 'iso':
        default:
          formattedTime = now.toISOString();
          break;
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Current timestamp (${format}): ${formattedTime}`,
          },
        ],
      };
    }
  • Input schema using Zod, defining an optional 'format' parameter with enum values ['iso', 'unix', 'readable'] defaulting to 'iso'.
    {
      format: z.enum(['iso', 'unix', 'readable']).optional().default('iso'),
    },
  • The timestampTool function registers the 'timestamp' tool on the MCP server, specifying the tool name, input schema, and handler function.
    export function timestampTool(server: McpServer): void {
      server.tool(
        'timestamp',
        {
          format: z.enum(['iso', 'unix', 'readable']).optional().default('iso'),
        },
        async ({ format }) => {
          const now = new Date();
          let formattedTime: string;
    
          switch (format) {
            case 'unix':
              formattedTime = Math.floor(now.getTime() / 1000).toString();
              break;
            case 'readable':
              formattedTime = now.toLocaleString();
              break;
            case 'iso':
            default:
              formattedTime = now.toISOString();
              break;
          }
    
          return {
            content: [
              {
                type: 'text',
                text: `Current timestamp (${format}): ${formattedTime}`,
              },
            ],
          };
        }
      );
    }
  • Within registerTools, calls timestampTool(server) to register the timestamp tool.
    // Register timestamp tool
    timestampTool(server);
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/cds-id/mcp-server-boilerplate'

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