@iflow-mcp/joshuaboys-datetime-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 joshuaboys
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # datetime-mcp
2
+
3
+ A lightweight MCP (Model Context Protocol) server that provides date/time tools via stdio transport.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g datetime-mcp
9
+ ```
10
+
11
+ Or use directly with npx:
12
+
13
+ ```bash
14
+ npx datetime-mcp
15
+ ```
16
+
17
+ ## Tools
18
+
19
+ ### datetime.now
20
+
21
+ Returns the current date/time from the host OS clock.
22
+
23
+ **Parameters:**
24
+ - `tz` (optional): IANA timezone string (e.g., `Australia/Perth`, `America/New_York`)
25
+
26
+ **Returns:**
27
+ ```json
28
+ {
29
+ "tz": "Australia/Perth",
30
+ "utcIso": "2026-01-22T03:30:00.000Z",
31
+ "epochMs": 1737516600000,
32
+ "human": "Thu, 22 Jan 2026, 11:30:00 AWST"
33
+ }
34
+ ```
35
+
36
+ ### datetime.health
37
+
38
+ Returns server health information including monotonic time (won't jump with NTP adjustments).
39
+
40
+ **Returns:**
41
+ ```json
42
+ {
43
+ "wallEpochMs": 1737516600000,
44
+ "monotonicMs": 12345678,
45
+ "processUptimeMs": 5000
46
+ }
47
+ ```
48
+
49
+ ### datetime.parse
50
+
51
+ Parses a date/time string and returns canonical forms.
52
+
53
+ **Parameters:**
54
+ - `value` (required): A date/time string parseable by JavaScript's `Date` constructor
55
+ - `tz` (optional): IANA timezone for human-readable output
56
+
57
+ **Returns:**
58
+ ```json
59
+ {
60
+ "input": "2026-01-22",
61
+ "tz": "Australia/Perth",
62
+ "utcIso": "2026-01-22T00:00:00.000Z",
63
+ "epochMs": 1737504000000,
64
+ "human": "Thu, 22 Jan 2026, 08:00:00 AWST"
65
+ }
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ ### Claude Code / Claude Desktop
71
+
72
+ Add to your MCP settings:
73
+
74
+ ```json
75
+ {
76
+ "mcpServers": {
77
+ "datetime": {
78
+ "command": "npx",
79
+ "args": ["-y", "datetime-mcp"],
80
+ "env": {
81
+ "MCP_TZ": "Australia/Perth"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ Or with global install:
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "datetime": {
94
+ "command": "datetime-mcp",
95
+ "env": {
96
+ "MCP_TZ": "Australia/Perth"
97
+ }
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Environment Variables
104
+
105
+ - `MCP_TZ`: Default IANA timezone (defaults to `Australia/Perth`)
106
+
107
+ ## Development
108
+
109
+ ```bash
110
+ # Install dependencies
111
+ pnpm install
112
+
113
+ # Run in development mode
114
+ pnpm dev
115
+
116
+ # Build
117
+ pnpm build
118
+
119
+ # Start built server
120
+ pnpm start
121
+ ```
122
+
123
+ ## License
124
+
125
+ MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+ const DEFAULT_TZ = process.env.MCP_TZ?.trim() || "Australia/Perth";
6
+ function formatHuman(date, tz) {
7
+ // Uses the runtime's Intl/ICU timezone database to render in a specific IANA timezone.
8
+ try {
9
+ return new Intl.DateTimeFormat("en-GB", {
10
+ timeZone: tz,
11
+ weekday: "short",
12
+ year: "numeric",
13
+ month: "short",
14
+ day: "2-digit",
15
+ hour: "2-digit",
16
+ minute: "2-digit",
17
+ second: "2-digit",
18
+ hour12: false,
19
+ timeZoneName: "short",
20
+ }).format(date);
21
+ }
22
+ catch (err) {
23
+ if (err instanceof RangeError) {
24
+ throw new Error(`Invalid IANA timezone: ${tz}`);
25
+ }
26
+ throw err;
27
+ }
28
+ }
29
+ function nowPayload(tz) {
30
+ const d = new Date(); // <-- comes from the host OS clock
31
+ return {
32
+ tz,
33
+ utcIso: d.toISOString(),
34
+ epochMs: d.getTime(),
35
+ human: formatHuman(d, tz),
36
+ };
37
+ }
38
+ const MAX_INPUT_LENGTH_FOR_ERROR = 200;
39
+ function formatInputForError(value) {
40
+ // Normalize whitespace to keep logs readable and bounded.
41
+ const normalized = value.replace(/\s+/g, " ").trim();
42
+ if (normalized.length <= MAX_INPUT_LENGTH_FOR_ERROR) {
43
+ return normalized;
44
+ }
45
+ return (normalized.slice(0, MAX_INPUT_LENGTH_FOR_ERROR) +
46
+ `… [truncated, original length=${normalized.length}]`);
47
+ }
48
+ function parsePayload(value, tz) {
49
+ const d = new Date(value);
50
+ if (Number.isNaN(d.getTime())) {
51
+ throw new Error(`Unable to parse date value: ${formatInputForError(value)}`);
52
+ }
53
+ return {
54
+ input: value,
55
+ tz,
56
+ utcIso: d.toISOString(),
57
+ epochMs: d.getTime(),
58
+ human: formatHuman(d, tz),
59
+ };
60
+ }
61
+ function healthPayload() {
62
+ // Monotonic time (won't jump backwards/forwards with NTP clock changes)
63
+ const monotonicMs = Number(process.hrtime.bigint() / 1000000n);
64
+ const wallEpochMs = Date.now();
65
+ const processUptimeMs = Math.round(process.uptime() * 1000);
66
+ return { wallEpochMs, monotonicMs, processUptimeMs };
67
+ }
68
+ async function main() {
69
+ const server = new McpServer({
70
+ name: "datetime-mcp",
71
+ version: "0.1.0",
72
+ });
73
+ server.tool("datetime.now", {
74
+ tz: z.string().optional().describe("IANA timezone, e.g. Australia/Perth"),
75
+ }, async ({ tz }) => {
76
+ const zone = tz || DEFAULT_TZ;
77
+ const payload = nowPayload(zone);
78
+ return {
79
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
80
+ };
81
+ });
82
+ server.tool("datetime.health", {}, async () => {
83
+ const payload = healthPayload();
84
+ return {
85
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
86
+ };
87
+ });
88
+ server.tool("datetime.parse", {
89
+ value: z.string().describe("A date/time string parseable by JS Date"),
90
+ tz: z.string().optional().describe("IANA timezone, e.g. Australia/Perth"),
91
+ }, async ({ value, tz }) => {
92
+ const zone = tz || DEFAULT_TZ;
93
+ const payload = parsePayload(value, zone);
94
+ return {
95
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
96
+ };
97
+ });
98
+ const transport = new StdioServerTransport();
99
+ await server.connect(transport);
100
+ // stderr is safe for logs under stdio transport (clients may show/ignore it)
101
+ console.error(`datetime-mcp running (default TZ=${DEFAULT_TZ}) via stdio`);
102
+ }
103
+ main().catch((err) => {
104
+ console.error("datetime-mcp fatal error:", err);
105
+ process.exit(1);
106
+ });
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "@iflow-mcp/joshuaboys-datetime-mcp", "version": "0.1.0", "description": "MCP server that returns current date/time information via stdio transport", "type": "module", "main": "dist/server.js", "types": "dist/server.d.ts", "license": "MIT", "author": "joshuaboys", "repository": {"type": "git", "url": "git+https://github.com/joshuaboys/datetime-mcp.git"}, "homepage": "https://github.com/joshuaboys/datetime-mcp#readme", "bugs": {"url": "https://github.com/joshuaboys/datetime-mcp/issues"}, "keywords": ["mcp", "model-context-protocol", "datetime", "time", "timezone", "claude", "anthropic"], "engines": {"node": ">=18.0.0"}, "files": ["dist", "src", "LICENSE"], "bin": {"iflow-mcp_joshuaboys-datetime-mcp": "dist/server.js"}, "scripts": {"build": "tsc -p tsconfig.json", "start": "node dist/server.js", "dev": "tsx src/server.ts", "prepublishOnly": "pnpm run build"}, "dependencies": {"@modelcontextprotocol/sdk": "^1.0.0", "zod": "^3.25.0"}, "devDependencies": {"@types/node": "^22.0.0", "tsx": "^4.0.0", "typescript": "^5.0.0"}}
package/src/server.ts ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+
6
+ const DEFAULT_TZ = process.env.MCP_TZ?.trim() || "Australia/Perth";
7
+
8
+ function formatHuman(date: Date, tz: string): string {
9
+ // Uses the runtime's Intl/ICU timezone database to render in a specific IANA timezone.
10
+ try {
11
+ return new Intl.DateTimeFormat("en-GB", {
12
+ timeZone: tz,
13
+ weekday: "short",
14
+ year: "numeric",
15
+ month: "short",
16
+ day: "2-digit",
17
+ hour: "2-digit",
18
+ minute: "2-digit",
19
+ second: "2-digit",
20
+ hour12: false,
21
+ timeZoneName: "short",
22
+ }).format(date);
23
+ } catch (err) {
24
+ if (err instanceof RangeError) {
25
+ throw new Error(`Invalid IANA timezone: ${tz}`);
26
+ }
27
+ throw err;
28
+ }
29
+ }
30
+
31
+ function nowPayload(tz: string) {
32
+ const d = new Date(); // <-- comes from the host OS clock
33
+ return {
34
+ tz,
35
+ utcIso: d.toISOString(),
36
+ epochMs: d.getTime(),
37
+ human: formatHuman(d, tz),
38
+ };
39
+ }
40
+
41
+ const MAX_INPUT_LENGTH_FOR_ERROR = 200;
42
+
43
+ function formatInputForError(value: string): string {
44
+ // Normalize whitespace to keep logs readable and bounded.
45
+ const normalized = value.replace(/\s+/g, " ").trim();
46
+ if (normalized.length <= MAX_INPUT_LENGTH_FOR_ERROR) {
47
+ return normalized;
48
+ }
49
+ return (
50
+ normalized.slice(0, MAX_INPUT_LENGTH_FOR_ERROR) +
51
+ `… [truncated, original length=${normalized.length}]`
52
+ );
53
+ }
54
+
55
+ function parsePayload(value: string, tz: string) {
56
+ const d = new Date(value);
57
+ if (Number.isNaN(d.getTime())) {
58
+ throw new Error(
59
+ `Unable to parse date value: ${formatInputForError(value)}`
60
+ );
61
+ }
62
+ return {
63
+ input: value,
64
+ tz,
65
+ utcIso: d.toISOString(),
66
+ epochMs: d.getTime(),
67
+ human: formatHuman(d, tz),
68
+ };
69
+ }
70
+
71
+ function healthPayload() {
72
+ // Monotonic time (won't jump backwards/forwards with NTP clock changes)
73
+ const monotonicMs = Number(process.hrtime.bigint() / 1_000_000n);
74
+ const wallEpochMs = Date.now();
75
+ const processUptimeMs = Math.round(process.uptime() * 1000);
76
+
77
+ return { wallEpochMs, monotonicMs, processUptimeMs };
78
+ }
79
+
80
+ async function main() {
81
+ const server = new McpServer({
82
+ name: "datetime-mcp",
83
+ version: "0.1.0",
84
+ });
85
+
86
+ server.tool(
87
+ "datetime.now",
88
+ {
89
+ tz: z.string().optional().describe("IANA timezone, e.g. Australia/Perth"),
90
+ },
91
+ async ({ tz }) => {
92
+ const zone = tz || DEFAULT_TZ;
93
+ const payload = nowPayload(zone);
94
+
95
+ return {
96
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
97
+ };
98
+ }
99
+ );
100
+
101
+ server.tool("datetime.health", {}, async () => {
102
+ const payload = healthPayload();
103
+ return {
104
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
105
+ };
106
+ });
107
+
108
+ server.tool(
109
+ "datetime.parse",
110
+ {
111
+ value: z.string().describe("A date/time string parseable by JS Date"),
112
+ tz: z.string().optional().describe("IANA timezone, e.g. Australia/Perth"),
113
+ },
114
+ async ({ value, tz }) => {
115
+ const zone = tz || DEFAULT_TZ;
116
+ const payload = parsePayload(value, zone);
117
+
118
+ return {
119
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
120
+ };
121
+ }
122
+ );
123
+
124
+ const transport = new StdioServerTransport();
125
+ await server.connect(transport);
126
+
127
+ // stderr is safe for logs under stdio transport (clients may show/ignore it)
128
+ console.error(`datetime-mcp running (default TZ=${DEFAULT_TZ}) via stdio`);
129
+ }
130
+
131
+ main().catch((err) => {
132
+ console.error("datetime-mcp fatal error:", err);
133
+ process.exit(1);
134
+ });