caldav-mcp 0.10.3 → 0.11.1

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/README.md CHANGED
@@ -11,6 +11,10 @@
11
11
  [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-purple.svg)](https://modelcontextprotocol.io)
12
12
  [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
13
13
 
14
+ Maintained by the team behind Langmail. Want mail, calendar and contacts for your agent over one hosted MCP, with OAuth and nothing to run? → [langmail.me](https://langmail.me/?ref=caldav-mcp)
15
+
16
+ Using caldav-mcp? [Tell us how in three minutes](https://tally.so/r/GepQM2?source=readme).
17
+
14
18
  </div>
15
19
 
16
20
  ## ✨ Features
@@ -68,6 +72,61 @@ npx tsc
68
72
  node dist/index.js
69
73
  ```
70
74
 
75
+ ## Transports
76
+
77
+ The server supports two transports, selected at startup:
78
+
79
+ - **stdio** (default): JSON-RPC over stdin/stdout, suitable for the standard MCP client configuration shown in [Setup](#setup).
80
+ ```bash
81
+ npx caldav-mcp
82
+ ```
83
+ - **Streamable HTTP** (`--http`): runs as a long-lived server that remote MCP clients connect to at `POST /mcp`. Each request is handled statelessly, and `GET /health` answers `ok` for health checks.
84
+ ```bash
85
+ MCP_AUTH_TOKEN=your-shared-secret npx caldav-mcp --http
86
+ ```
87
+
88
+ | Env var | Default | Description |
89
+ |---|---|---|
90
+ | `MCP_HOST` | `127.0.0.1` | Bind address. Set to `0.0.0.0` to listen on all interfaces. |
91
+ | `MCP_PORT` | `PORT`, else `3000` | TCP port to bind. Falls back to `PORT`, which platforms like Cloud Run set. |
92
+ | `MCP_AUTH_TOKEN` | _(unset)_ | When set, requests must send `Authorization: Bearer <MCP_AUTH_TOKEN>`; others get `401`. Required when `MCP_HOST` is not a loopback address. |
93
+
94
+ Connect a client, for example Claude Code (`.mcp.json`):
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "calendar": {
100
+ "type": "http",
101
+ "url": "http://127.0.0.1:3000/mcp",
102
+ "headers": { "Authorization": "Bearer your-shared-secret" }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ Security notes:
109
+ - One server process serves one CalDAV account. Anyone with the token can read and change that calendar.
110
+ - The server speaks plain HTTP. For remote access, put it behind a reverse proxy that terminates TLS.
111
+ - Requests with an `Origin` header are rejected and there is no CORS support, so browser-based clients can't connect directly.
112
+ - When bound to loopback, only `localhost`/`127.0.0.1`/`[::1]` Host headers are accepted, which blocks DNS rebinding.
113
+
114
+ ## Docker
115
+
116
+ A `Dockerfile` is provided for running the server with the Streamable HTTP transport — useful when hosting the MCP server as a long-running container that remote MCP clients connect to over HTTP, rather than spawning the binary locally via stdio.
117
+
118
+ ```bash
119
+ docker build -t caldav-mcp .
120
+ docker run --rm -p 3000:3000 \
121
+ -e CALDAV_BASE_URL=https://your-caldav-server.com/dav \
122
+ -e CALDAV_USERNAME=your-username \
123
+ -e CALDAV_PASSWORD=your-password \
124
+ -e MCP_AUTH_TOKEN=your-shared-secret \
125
+ caldav-mcp
126
+ ```
127
+
128
+ The image binds to `0.0.0.0:3000` (or the port in `MCP_PORT`/`PORT`), serves `POST /mcp`, and reports its health from `GET /health`. Because it listens on all interfaces, `MCP_AUTH_TOKEN` is required: without it the container exits at startup (see [Transports](#transports)). The container is not needed for the default stdio setup in [Setup](#setup) above.
129
+
71
130
  ## Available Tools
72
131
 
73
132
  <!-- TOOLS:START - generated by scripts/gen-tool-docs.ts -->
@@ -85,9 +144,9 @@ Returns:
85
144
  List all events between start and end date in the calendar specified by its URL
86
145
 
87
146
  Parameters:
88
- - `start`: string — Start date (ISO 8601)
89
- - `end`: string — End date (ISO 8601)
90
147
  - `calendarUrl`: string
148
+ - `end`: string — End date (ISO 8601)
149
+ - `start`: string — Start date (ISO 8601)
91
150
 
92
151
  Returns:
93
152
  - A list of events that fall within the given timeframe, each containing `uid`, `summary`, `start`, `end`, and optionally `description` and `location`
@@ -97,21 +156,21 @@ Returns:
97
156
  Creates an event in the calendar specified by its URL. For all-day events, set `wholeDay` to true. For a single-day all-day event, use `start` and `end` datetimes on the same calendar date; they do not need to be identical timestamps.
98
157
 
99
158
  Parameters:
100
- - `summary`: string
101
- - `start`: string — Start datetime (ISO 8601)
102
- - `end`: string — End datetime (ISO 8601)
103
- - `wholeDay`: boolean (optional) — Create as a whole-day event
104
159
  - `calendarUrl`: string
105
160
  - `description`: string (optional)
161
+ - `end`: string — End datetime (ISO 8601)
106
162
  - `location`: string (optional)
107
163
  - `recurrenceRule`: object (optional)
164
+ - `byday`: array of string (optional)
165
+ - `bymonth`: array of number (optional)
166
+ - `bymonthday`: array of number (optional)
167
+ - `count`: number (optional)
108
168
  - `freq`: enum (`DAILY` | `WEEKLY` | `MONTHLY` | `YEARLY`) (optional)
109
169
  - `interval`: number (optional)
110
- - `count`: number (optional)
111
170
  - `until`: string (optional)
112
- - `byday`: array of string (optional)
113
- - `bymonthday`: array of number (optional)
114
- - `bymonth`: array of number (optional)
171
+ - `start`: string — Start datetime (ISO 8601)
172
+ - `summary`: string
173
+ - `wholeDay`: boolean (optional) — Create as a whole-day event
115
174
 
116
175
  Returns:
117
176
  - The unique ID of the created event
@@ -121,22 +180,22 @@ Returns:
121
180
  Updates an existing event in the calendar specified by its URL. Only provided fields are changed. For a one-day full-day event, set `wholeDay` to true and set `start` and `end` to the same calendar day.
122
181
 
123
182
  Parameters:
124
- - `uid`: string — Unique identifier of the event to update (obtained from list-events)
125
183
  - `calendarUrl`: string
126
- - `summary`: string (optional)
127
- - `start`: string (optional)
128
- - `end`: string (optional)
129
- - `wholeDay`: boolean (optional) — Update whether this is a whole-day event
130
184
  - `description`: string (optional)
185
+ - `end`: string (optional)
131
186
  - `location`: string (optional)
132
187
  - `recurrenceRule`: object (optional)
188
+ - `byday`: array of string (optional)
189
+ - `bymonth`: array of number (optional)
190
+ - `bymonthday`: array of number (optional)
191
+ - `count`: number (optional)
133
192
  - `freq`: enum (`DAILY` | `WEEKLY` | `MONTHLY` | `YEARLY`) (optional)
134
193
  - `interval`: number (optional)
135
- - `count`: number (optional)
136
194
  - `until`: string (optional)
137
- - `byday`: array of string (optional)
138
- - `bymonthday`: array of number (optional)
139
- - `bymonth`: array of number (optional)
195
+ - `start`: string (optional)
196
+ - `summary`: string (optional)
197
+ - `uid`: string — Unique identifier of the event to update (obtained from list-events)
198
+ - `wholeDay`: boolean (optional) — Update whether this is a whole-day event
140
199
 
141
200
  Returns:
142
201
  - The unique ID of the updated event
@@ -146,8 +205,8 @@ Returns:
146
205
  Deletes an event in the calendar specified by its URL
147
206
 
148
207
  Parameters:
149
- - `uid`: string — Unique identifier of the event to delete (obtained from list-events)
150
208
  - `calendarUrl`: string
209
+ - `uid`: string — Unique identifier of the event to delete (obtained from list-events)
151
210
 
152
211
  Returns:
153
212
  - Confirmation message when the event is successfully deleted
@@ -158,11 +217,11 @@ List tasks (VTODOs) in the calendar specified by its URL. By default returns onl
158
217
 
159
218
  Parameters:
160
219
  - `calendarUrl`: string
161
- - `status`: enum (`OPEN` | `ALL` | `NEEDS-ACTION` | `COMPLETED` | `IN-PROCESS` | `CANCELLED`) (optional) — Filter by status. `OPEN` (default) = NEEDS-ACTION + IN-PROCESS; `ALL` = everything; or an exact status (NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED).
162
- - `due_before`: string (optional) — Only tasks with a due date at or before this (ISO 8601). Undated tasks are excluded when a due window is set.
163
220
  - `due_after`: string (optional) — Only tasks with a due date at or after this (ISO 8601). Undated tasks are excluded when a due window is set.
221
+ - `due_before`: string (optional) — Only tasks with a due date at or before this (ISO 8601). Undated tasks are excluded when a due window is set.
164
222
  - `limit`: number (optional) — Max tasks to return (default 50, max 500)
165
223
  - `offset`: number (optional) — Tasks to skip (default 0)
224
+ - `status`: enum (`OPEN` | `ALL` | `NEEDS-ACTION` | `COMPLETED` | `IN-PROCESS` | `CANCELLED`) (optional) — Filter by status. `OPEN` (default) = NEEDS-ACTION + IN-PROCESS; `ALL` = everything; or an exact status (NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED).
166
225
 
167
226
  Returns:
168
227
  - An object `{ todos, total, limit, offset }` where `total` is the count before pagination. Each todo has `uid`, `summary`, `status`, and optionally `due`, `start`, `completed`, `description`, `location`.
@@ -172,13 +231,13 @@ Returns:
172
231
  Creates a task (VTODO) in the calendar specified by its URL. Only `summary` is required; a task may have no dates. Use `due` for a deadline and `start` for when work should begin.
173
232
 
174
233
  Parameters:
175
- - `summary`: string
176
234
  - `calendarUrl`: string
177
- - `due`: string (optional) — Due datetime (ISO 8601)
178
- - `start`: string (optional) — Start datetime (ISO 8601)
179
235
  - `description`: string (optional)
236
+ - `due`: string (optional) — Due datetime (ISO 8601)
180
237
  - `location`: string (optional)
238
+ - `start`: string (optional) — Start datetime (ISO 8601)
181
239
  - `status`: enum (`NEEDS-ACTION` | `COMPLETED` | `IN-PROCESS` | `CANCELLED`) (optional) — Defaults to NEEDS-ACTION when omitted
240
+ - `summary`: string
182
241
 
183
242
  Returns:
184
243
  - The unique ID of the created todo
@@ -188,14 +247,14 @@ Returns:
188
247
  Updates an existing task (VTODO) in the calendar specified by its URL. Only provided fields are changed. To mark a task done, prefer the `complete-todo` tool.
189
248
 
190
249
  Parameters:
191
- - `uid`: string — Unique identifier of the todo to update (from list-todos)
192
250
  - `calendarUrl`: string
193
- - `summary`: string (optional)
194
- - `due`: string (optional)
195
- - `start`: string (optional)
196
251
  - `description`: string (optional)
252
+ - `due`: string (optional)
197
253
  - `location`: string (optional)
254
+ - `start`: string (optional)
198
255
  - `status`: enum (`NEEDS-ACTION` | `COMPLETED` | `IN-PROCESS` | `CANCELLED`) (optional)
256
+ - `summary`: string (optional)
257
+ - `uid`: string — Unique identifier of the todo to update (from list-todos)
199
258
 
200
259
  Returns:
201
260
  - The unique ID of the updated todo
@@ -205,8 +264,8 @@ Returns:
205
264
  Marks a task (VTODO) as done. Sets its status to COMPLETED and records the completion time.
206
265
 
207
266
  Parameters:
208
- - `uid`: string — Unique identifier of the todo to complete (from list-todos)
209
267
  - `calendarUrl`: string
268
+ - `uid`: string — Unique identifier of the todo to complete (from list-todos)
210
269
 
211
270
  Returns:
212
271
  - The unique ID of the completed todo
@@ -216,8 +275,8 @@ Returns:
216
275
  Deletes a task (VTODO) in the calendar specified by its URL
217
276
 
218
277
  Parameters:
219
- - `uid`: string — Unique identifier of the todo to delete (from list-todos)
220
278
  - `calendarUrl`: string
279
+ - `uid`: string — Unique identifier of the todo to delete (from list-todos)
221
280
 
222
281
  Returns:
223
282
  - Confirmation message when the todo is successfully deleted
@@ -0,0 +1,35 @@
1
+ const DEFAULT_HOST = "127.0.0.1";
2
+ const DEFAULT_PORT = 3000;
3
+ const MAX_PORT = 65_535;
4
+ const DIGITS = /^\d+$/u;
5
+ // An IPv4 literal in 127.0.0.0/8, not a hostname that merely starts with "127.".
6
+ const LOOPBACK_IPV4 = /^127(?:\.\d{1,3}){3}$/u;
7
+ /** True for addresses only reachable from this machine. */
8
+ export function isLoopbackHost(host) {
9
+ return host === "localhost" || host === "::1" || LOOPBACK_IPV4.test(host);
10
+ }
11
+ function parsePort(name, value) {
12
+ const port = Number(value);
13
+ if (!DIGITS.test(value) || port > MAX_PORT) {
14
+ throw new Error(`${name} must be an integer between 0 and 65535`);
15
+ }
16
+ return port;
17
+ }
18
+ function readPort(env) {
19
+ if (env.MCP_PORT) {
20
+ return parsePort("MCP_PORT", env.MCP_PORT);
21
+ }
22
+ if (env.PORT) {
23
+ return parsePort("PORT", env.PORT);
24
+ }
25
+ return DEFAULT_PORT;
26
+ }
27
+ /** Reads the HTTP transport settings; throws on invalid or unsafe values. */
28
+ export function parseHttpConfig(env) {
29
+ const host = env.MCP_HOST || DEFAULT_HOST;
30
+ const authToken = env.MCP_AUTH_TOKEN || undefined;
31
+ if (!(authToken || isLoopbackHost(host))) {
32
+ throw new Error("MCP_AUTH_TOKEN is required when MCP_HOST is not a loopback address");
33
+ }
34
+ return { authToken, host, port: readPort(env) };
35
+ }
@@ -0,0 +1,128 @@
1
+ import { createHash, timingSafeEqual } from "node:crypto";
2
+ import { createServer as createHttpServer, } from "node:http";
3
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
4
+ import { isLoopbackHost } from "./http-config.js";
5
+ const MCP_PATH = "/mcp";
6
+ const HEALTH_PATH = "/health";
7
+ const BEARER = /^Bearer\s+(?<token>.+)$/iu;
8
+ const JSONRPC_INTERNAL_ERROR = -32_603;
9
+ function send(res, status, body, headers = {}) {
10
+ res.writeHead(status, { "Content-Type": "text/plain", ...headers });
11
+ res.end(body);
12
+ }
13
+ /** Hostname of a Host header, without port; handles `[::1]:3000`. */
14
+ function hostnameOf(hostHeader) {
15
+ if (hostHeader.startsWith("[")) {
16
+ return hostHeader.slice(1, hostHeader.indexOf("]"));
17
+ }
18
+ return hostHeader.split(":")[0] ?? "";
19
+ }
20
+ /** The request path, or null when the target is not a parseable URL. */
21
+ function pathnameOf(url) {
22
+ try {
23
+ return new URL(url ?? "/", "http://localhost").pathname;
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ function digest(value) {
30
+ return createHash("sha256").update(value).digest();
31
+ }
32
+ // Hashing first gives equal-length buffers, so timingSafeEqual never throws
33
+ // and the comparison leaks nothing about the token's length.
34
+ function hasValidToken(req, expected) {
35
+ const token = req.headers.authorization?.match(BEARER)?.groups?.token;
36
+ return (token !== undefined && timingSafeEqual(digest(token), digest(expected)));
37
+ }
38
+ /**
39
+ * Rejects requests to /mcp that fail the DNS-rebinding, Origin, auth or method
40
+ * checks. Returns true when it has already answered the request.
41
+ */
42
+ function rejectRequest(req, res, config) {
43
+ // A rebound browser page reaches a loopback server with a foreign Host.
44
+ if (isLoopbackHost(config.host) &&
45
+ !isLoopbackHost(hostnameOf(req.headers.host ?? ""))) {
46
+ send(res, 403, "Forbidden: Host not allowed");
47
+ return true;
48
+ }
49
+ // No CORS support, so no browser origin is valid.
50
+ if (req.headers.origin !== undefined) {
51
+ send(res, 403, "Forbidden: Origin not allowed");
52
+ return true;
53
+ }
54
+ if (config.authToken && !hasValidToken(req, config.authToken)) {
55
+ send(res, 401, "Unauthorized", { "WWW-Authenticate": "Bearer" });
56
+ return true;
57
+ }
58
+ // Stateless mode has no server-to-client stream (GET) or session (DELETE).
59
+ if (req.method !== "POST") {
60
+ send(res, 405, "Method Not Allowed", { Allow: "POST" });
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ async function handleMcp(req, res, createServer) {
66
+ try {
67
+ // A stateless transport and an McpServer each serve one request only.
68
+ const mcpServer = createServer();
69
+ const transport = new StreamableHTTPServerTransport({
70
+ enableJsonResponse: true,
71
+ });
72
+ res.on("close", () => {
73
+ transport.close();
74
+ mcpServer.close();
75
+ });
76
+ await mcpServer.connect(transport);
77
+ await transport.handleRequest(req, res);
78
+ }
79
+ catch (error) {
80
+ console.error("caldav-mcp: request failed:", error);
81
+ if (!res.headersSent) {
82
+ res.writeHead(500, { "Content-Type": "application/json" });
83
+ res.end(JSON.stringify({
84
+ error: {
85
+ code: JSONRPC_INTERNAL_ERROR,
86
+ message: "Internal server error",
87
+ },
88
+ id: null,
89
+ jsonrpc: "2.0",
90
+ }));
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * Serves MCP over stateless Streamable HTTP at /mcp, plus GET /health.
96
+ * Resolves once listening; the caller owns logging and shutdown.
97
+ */
98
+ export function startHttpServer(config, createServer) {
99
+ const server = createHttpServer((req, res) => {
100
+ const pathname = pathnameOf(req.url);
101
+ if (pathname === null) {
102
+ // Node's parser accepts targets like `http://[` that URL rejects;
103
+ // throwing here would crash the process before any auth check.
104
+ send(res, 400, "Bad Request");
105
+ return;
106
+ }
107
+ // Node omits the body for HEAD, which some health probes send.
108
+ if (pathname === HEALTH_PATH &&
109
+ (req.method === "GET" || req.method === "HEAD")) {
110
+ send(res, 200, "ok");
111
+ return;
112
+ }
113
+ if (pathname !== MCP_PATH) {
114
+ send(res, 404, "Not Found");
115
+ return;
116
+ }
117
+ if (!rejectRequest(req, res, config)) {
118
+ handleMcp(req, res, createServer);
119
+ }
120
+ });
121
+ return new Promise((resolve, reject) => {
122
+ server.once("error", reject);
123
+ server.listen(config.port, config.host, () => {
124
+ server.off("error", reject);
125
+ resolve(server);
126
+ });
127
+ });
128
+ }
package/dist/index.js CHANGED
@@ -1,29 +1,41 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
3
  import { CalDAVClient } from "ts-caldav";
5
- import { registerCompleteTodo } from "./tools/complete-todo.js";
6
- import { registerCreateEvent } from "./tools/create-event.js";
7
- import { registerCreateTodo } from "./tools/create-todo.js";
8
- import { registerDeleteEvent } from "./tools/delete-event.js";
9
- import { registerDeleteTodo } from "./tools/delete-todo.js";
10
- import { registerListCalendars } from "./tools/list-calendars.js";
11
- import { registerListEvents } from "./tools/list-events.js";
12
- import { registerListTodos } from "./tools/list-todos.js";
13
- import { registerUpdateEvent } from "./tools/update-event.js";
14
- import { registerUpdateTodo } from "./tools/update-todo.js";
15
- const server = new McpServer({
16
- name: "caldav-mcp",
17
- version: "0.1.0",
18
- });
4
+ import { parseHttpConfig } from "./http-config.js";
5
+ import { createServer } from "./server.js";
6
+ function listeningUrl(server) {
7
+ const { address, family, port } = server.address();
8
+ const host = family === "IPv6" ? `[${address}]` : address;
9
+ return `http://${host}:${port}/mcp`;
10
+ }
11
+ function shutDownOnSignals(server) {
12
+ const shutdown = () => {
13
+ server.close(() => process.exit(0));
14
+ // closeIdleConnections only exists from Node 18.2; engines allows 18.0.
15
+ server.closeIdleConnections?.();
16
+ };
17
+ process.once("SIGINT", shutdown);
18
+ process.once("SIGTERM", shutdown);
19
+ }
19
20
  async function main() {
21
+ let httpConfig;
22
+ if (process.argv.includes("--http")) {
23
+ try {
24
+ httpConfig = parseHttpConfig(process.env);
25
+ }
26
+ catch (error) {
27
+ console.error(error.message);
28
+ process.exit(1);
29
+ return;
30
+ }
31
+ }
20
32
  const client = await CalDAVClient.create({
21
- baseUrl: process.env.CALDAV_BASE_URL || "",
22
33
  auth: {
34
+ password: process.env.CALDAV_PASSWORD || "",
23
35
  type: "basic",
24
36
  username: process.env.CALDAV_USERNAME || "",
25
- password: process.env.CALDAV_PASSWORD || "",
26
37
  },
38
+ baseUrl: process.env.CALDAV_BASE_URL || "",
27
39
  });
28
40
  // Test connection on startup
29
41
  try {
@@ -33,18 +45,48 @@ async function main() {
33
45
  console.error("❌ Failed to connect to CalDAV server:", error);
34
46
  process.exit(1);
35
47
  }
36
- registerCreateEvent(client, server);
37
- registerListEvents(client, server);
38
- registerDeleteEvent(client, server);
39
- registerUpdateEvent(client, server);
40
- registerCreateTodo(client, server);
41
- registerListTodos(client, server);
42
- registerUpdateTodo(client, server);
43
- registerCompleteTodo(client, server);
44
- registerDeleteTodo(client, server);
45
- await registerListCalendars(client, server);
48
+ if (httpConfig) {
49
+ // Imported lazily so stdio mode never loads the HTTP stack.
50
+ const { startHttpServer } = await import("./http-server.js");
51
+ const server = await startHttpServer(httpConfig, () => createServer(client));
52
+ // stdout is not reserved in HTTP mode, but keep logs on stderr like stdio.
53
+ console.error(`caldav-mcp listening on ${listeningUrl(server)}`);
54
+ shutDownOnSignals(server);
55
+ return;
56
+ }
46
57
  // Start receiving messages on stdin and sending messages on stdout
47
- const transport = new StdioServerTransport();
48
- await server.connect(transport);
58
+ await createServer(client).connect(new StdioServerTransport());
59
+ }
60
+ const MAX_CAUSE_DEPTH = 5;
61
+ /** undici's AggregateError for a refused multi-address connect has no message. */
62
+ function messageOf(error) {
63
+ if (error.message) {
64
+ return error.message;
65
+ }
66
+ const { code } = error;
67
+ return typeof code === "string" ? code : error.name;
49
68
  }
50
- main();
69
+ /**
70
+ * One line for a startup error, with its cause chain: ts-caldav and fetch
71
+ * keep the actual network reason (ENOTFOUND, TLS errors) only in `cause`.
72
+ */
73
+ function describeError(error) {
74
+ if (!(error instanceof Error)) {
75
+ return String(error);
76
+ }
77
+ const causes = [];
78
+ let { cause } = error;
79
+ while (cause instanceof Error && causes.length < MAX_CAUSE_DEPTH) {
80
+ causes.push(messageOf(cause));
81
+ ({ cause } = cause);
82
+ }
83
+ return causes.length > 0
84
+ ? `${error.message} (${causes.join(": ")})`
85
+ : error.message;
86
+ }
87
+ main().catch((error) => {
88
+ // e.g. EADDRINUSE or an unreachable CalDAV server: one readable line
89
+ // instead of an unhandled rejection.
90
+ console.error(`caldav-mcp: failed to start: ${describeError(error)}`);
91
+ process.exit(1);
92
+ });
package/dist/server.js ADDED
@@ -0,0 +1,32 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { registerCompleteTodo } from "./tools/complete-todo.js";
3
+ import { registerCreateEvent } from "./tools/create-event.js";
4
+ import { registerCreateTodo } from "./tools/create-todo.js";
5
+ import { registerDeleteEvent } from "./tools/delete-event.js";
6
+ import { registerDeleteTodo } from "./tools/delete-todo.js";
7
+ import { registerListCalendars } from "./tools/list-calendars.js";
8
+ import { registerListEvents } from "./tools/list-events.js";
9
+ import { registerListTodos } from "./tools/list-todos.js";
10
+ import { registerUpdateEvent } from "./tools/update-event.js";
11
+ import { registerUpdateTodo } from "./tools/update-todo.js";
12
+ /**
13
+ * Builds a fresh MCP server with every tool registered. HTTP mode calls this
14
+ * once per request: an McpServer can only be connected to one transport.
15
+ */
16
+ export function createServer(client) {
17
+ const server = new McpServer({
18
+ name: "caldav-mcp",
19
+ version: "0.1.0",
20
+ });
21
+ registerCreateEvent(client, server);
22
+ registerListEvents(client, server);
23
+ registerDeleteEvent(client, server);
24
+ registerUpdateEvent(client, server);
25
+ registerCreateTodo(client, server);
26
+ registerListTodos(client, server);
27
+ registerUpdateTodo(client, server);
28
+ registerCompleteTodo(client, server);
29
+ registerDeleteTodo(client, server);
30
+ registerListCalendars(client, server);
31
+ return server;
32
+ }
@@ -15,8 +15,9 @@ export function hrefFor(calendarUrl, uid) {
15
15
  * shown to the LLM.
16
16
  */
17
17
  export function toAbsoluteUrl(href, baseUrl) {
18
- if (!href || !baseUrl)
18
+ if (!(href && baseUrl)) {
19
19
  return href;
20
+ }
20
21
  try {
21
22
  const url = new URL(href, baseUrl);
22
23
  url.username = "";
@@ -35,12 +36,14 @@ export function toAbsoluteUrl(href, baseUrl) {
35
36
  * on another origin pass through unchanged.
36
37
  */
37
38
  export function toCalendarPath(calendarUrl, baseUrl) {
38
- if (!baseUrl)
39
+ if (!baseUrl) {
39
40
  return calendarUrl;
41
+ }
40
42
  try {
41
43
  const url = new URL(calendarUrl);
42
- if (url.origin !== new URL(baseUrl).origin)
44
+ if (url.origin !== new URL(baseUrl).origin) {
43
45
  return calendarUrl;
46
+ }
44
47
  return `${url.pathname}${url.search}`;
45
48
  }
46
49
  catch {
@@ -1,14 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { hrefFor, toCalendarPath } from "./caldav-href.js";
3
3
  export const completeTodoDefinition = {
4
- name: "complete-todo",
5
4
  description: "Marks a task (VTODO) as done. Sets its status to COMPLETED and records the completion time.",
6
5
  inputSchema: {
6
+ calendarUrl: z.string(),
7
7
  uid: z
8
8
  .string()
9
9
  .describe("Unique identifier of the todo to complete (from list-todos)"),
10
- calendarUrl: z.string(),
11
10
  },
11
+ name: "complete-todo",
12
12
  returns: "The unique ID of the completed todo",
13
13
  };
14
14
  export function registerCompleteTodo(client, server) {
@@ -26,11 +26,11 @@ export function registerCompleteTodo(client, server) {
26
26
  // RFC 5545: a COMPLETED VTODO should carry a COMPLETED timestamp.
27
27
  const updated = await client.updateTodo(calendarUrl, {
28
28
  ...existing,
29
- status: "COMPLETED",
30
29
  completed: new Date(),
30
+ status: "COMPLETED",
31
31
  });
32
32
  return {
33
- content: [{ type: "text", text: updated.uid }],
33
+ content: [{ text: updated.uid, type: "text" }],
34
34
  };
35
35
  });
36
36
  }
@@ -3,24 +3,24 @@ import { toCalendarPath } from "./caldav-href.js";
3
3
  import { recurrenceRuleSchema, toRecurrenceRule, } from "./recurrence-rule.js";
4
4
  import { toWholeDayDate } from "./whole-day-date.js";
5
5
  export const createEventDefinition = {
6
- name: "create-event",
7
6
  description: "Creates an event in the calendar specified by its URL. For all-day events, set `wholeDay` to true. For a single-day all-day event, use `start` and `end` datetimes on the same calendar date; they do not need to be identical timestamps.",
8
7
  inputSchema: {
9
- summary: z.string(),
10
- start: z
11
- .string()
12
- .datetime({ offset: true })
13
- .describe("Start datetime (ISO 8601)"),
8
+ calendarUrl: z.string(),
9
+ description: z.string().optional(),
14
10
  end: z
15
11
  .string()
16
12
  .datetime({ offset: true })
17
13
  .describe("End datetime (ISO 8601)"),
18
- wholeDay: z.boolean().optional().describe("Create as a whole-day event"),
19
- calendarUrl: z.string(),
20
- description: z.string().optional(),
21
14
  location: z.string().optional(),
22
15
  recurrenceRule: recurrenceRuleSchema.optional(),
16
+ start: z
17
+ .string()
18
+ .datetime({ offset: true })
19
+ .describe("Start datetime (ISO 8601)"),
20
+ summary: z.string(),
21
+ wholeDay: z.boolean().optional().describe("Create as a whole-day event"),
23
22
  },
23
+ name: "create-event",
24
24
  returns: "The unique ID of the created event",
25
25
  };
26
26
  export function registerCreateEvent(client, server) {
@@ -31,9 +31,9 @@ export function registerCreateEvent(client, server) {
31
31
  const { summary, start, end, wholeDay, description, location, recurrenceRule, } = args;
32
32
  const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
33
33
  const event = await client.createEvent(calendarUrl, {
34
- summary: summary,
35
- start: wholeDay ? toWholeDayDate(start) : new Date(start),
36
34
  end: wholeDay ? toWholeDayDate(end) : new Date(end),
35
+ start: wholeDay ? toWholeDayDate(start) : new Date(start),
36
+ summary,
37
37
  ...(wholeDay !== undefined && { wholeDay }),
38
38
  ...(description !== undefined && { description }),
39
39
  ...(location !== undefined && { location }),
@@ -42,7 +42,7 @@ export function registerCreateEvent(client, server) {
42
42
  }),
43
43
  });
44
44
  return {
45
- content: [{ type: "text", text: event.uid }],
45
+ content: [{ text: event.uid, type: "text" }],
46
46
  };
47
47
  });
48
48
  }
@@ -2,27 +2,27 @@ import { z } from "zod";
2
2
  import { toCalendarPath } from "./caldav-href.js";
3
3
  import { todoStatusSchema } from "./todo-status.js";
4
4
  export const createTodoDefinition = {
5
- name: "create-todo",
6
5
  description: "Creates a task (VTODO) in the calendar specified by its URL. Only `summary` is required; a task may have no dates. Use `due` for a deadline and `start` for when work should begin.",
7
6
  inputSchema: {
8
- summary: z.string(),
9
7
  calendarUrl: z.string(),
8
+ description: z.string().optional(),
10
9
  due: z
11
10
  .string()
12
11
  .datetime({ offset: true })
13
12
  .optional()
14
13
  .describe("Due datetime (ISO 8601)"),
14
+ location: z.string().optional(),
15
15
  start: z
16
16
  .string()
17
17
  .datetime({ offset: true })
18
18
  .optional()
19
19
  .describe("Start datetime (ISO 8601)"),
20
- description: z.string().optional(),
21
- location: z.string().optional(),
22
20
  status: todoStatusSchema
23
21
  .optional()
24
22
  .describe("Defaults to NEEDS-ACTION when omitted"),
23
+ summary: z.string(),
25
24
  },
25
+ name: "create-todo",
26
26
  returns: "The unique ID of the created todo",
27
27
  };
28
28
  export function registerCreateTodo(client, server) {
@@ -41,7 +41,7 @@ export function registerCreateTodo(client, server) {
41
41
  ...(status !== undefined && { status }),
42
42
  });
43
43
  return {
44
- content: [{ type: "text", text: todo.uid }],
44
+ content: [{ text: todo.uid, type: "text" }],
45
45
  };
46
46
  });
47
47
  }
@@ -1,14 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { hrefFor, toCalendarPath } from "./caldav-href.js";
3
3
  export const deleteEventDefinition = {
4
- name: "delete-event",
5
4
  description: "Deletes an event in the calendar specified by its URL",
6
5
  inputSchema: {
6
+ calendarUrl: z.string(),
7
7
  uid: z
8
8
  .string()
9
9
  .describe("Unique identifier of the event to delete (obtained from list-events)"),
10
- calendarUrl: z.string(),
11
10
  },
11
+ name: "delete-event",
12
12
  returns: "Confirmation message when the event is successfully deleted",
13
13
  };
14
14
  export function registerDeleteEvent(client, server) {
@@ -21,7 +21,7 @@ export function registerDeleteEvent(client, server) {
21
21
  const etag = await client.getETag(hrefFor(calendarUrl, uid));
22
22
  await client.deleteEvent(calendarUrl, uid, etag);
23
23
  return {
24
- content: [{ type: "text", text: "Event deleted" }],
24
+ content: [{ text: "Event deleted", type: "text" }],
25
25
  };
26
26
  });
27
27
  }
@@ -2,14 +2,14 @@ import { CalDAVError } from "ts-caldav";
2
2
  import { z } from "zod";
3
3
  import { hrefFor, toCalendarPath } from "./caldav-href.js";
4
4
  export const deleteTodoDefinition = {
5
- name: "delete-todo",
6
5
  description: "Deletes a task (VTODO) in the calendar specified by its URL",
7
6
  inputSchema: {
7
+ calendarUrl: z.string(),
8
8
  uid: z
9
9
  .string()
10
10
  .describe("Unique identifier of the todo to delete (from list-todos)"),
11
- calendarUrl: z.string(),
12
11
  },
12
+ name: "delete-todo",
13
13
  returns: "Confirmation message when the todo is successfully deleted",
14
14
  };
15
15
  export function registerDeleteTodo(client, server) {
@@ -29,13 +29,13 @@ export function registerDeleteTodo(client, server) {
29
29
  }
30
30
  catch (error) {
31
31
  if (error instanceof CalDAVError && error.status === 404) {
32
- throw new Error(`Todo not found: ${uid}`);
32
+ throw new Error(`Todo not found: ${uid}`, { cause: error });
33
33
  }
34
34
  throw error;
35
35
  }
36
36
  await client.deleteTodo(calendarUrl, uid, etag);
37
37
  return {
38
- content: [{ type: "text", text: "Todo deleted" }],
38
+ content: [{ text: "Todo deleted", type: "text" }],
39
39
  };
40
40
  });
41
41
  }
@@ -1,21 +1,23 @@
1
1
  import { toAbsoluteUrl } from "./caldav-href.js";
2
2
  export const listCalendarsDefinition = {
3
- name: "list-calendars",
4
3
  description: "List all calendars returning both name and absolute URL. Pass a calendar's `url` unchanged as `calendarUrl` to the other tools.",
5
4
  inputSchema: {},
5
+ name: "list-calendars",
6
6
  returns: "List of all available calendars",
7
7
  };
8
- export async function registerListCalendars(client, server) {
9
- // ts-caldav returns server-relative hrefs; resolve them so agents don't
10
- // have to guess how to prefix the base URL.
11
- const calendars = (await client.getCalendars()).map((calendar) => ({
12
- ...calendar,
13
- url: toAbsoluteUrl(calendar.url, client.baseUrl),
14
- }));
8
+ export function registerListCalendars(client, server) {
15
9
  server.registerTool(listCalendarsDefinition.name, {
16
10
  description: listCalendarsDefinition.description,
17
11
  inputSchema: listCalendarsDefinition.inputSchema,
18
12
  }, async () => {
19
- return { content: [{ type: "text", text: JSON.stringify(calendars) }] };
13
+ // ts-caldav returns server-relative hrefs; resolve them so agents don't
14
+ // have to guess how to prefix the base URL.
15
+ const calendars = (await client.getCalendars()).map((calendar) => ({
16
+ ...calendar,
17
+ url: toAbsoluteUrl(calendar.url, client.baseUrl),
18
+ }));
19
+ return {
20
+ content: [{ text: JSON.stringify(calendars), type: "text" }],
21
+ };
20
22
  });
21
23
  }
@@ -1,23 +1,23 @@
1
1
  import { z } from "zod";
2
2
  import { toCalendarPath } from "./caldav-href.js";
3
3
  export const listEventsDefinition = {
4
- name: "list-events",
5
4
  description: "List all events between start and end date in the calendar specified by its URL",
6
5
  inputSchema: {
7
- start: z
6
+ calendarUrl: z.string(),
7
+ end: z
8
8
  .string()
9
9
  .refine((val) => !Number.isNaN(Date.parse(val)), {
10
10
  message: "Invalid date string",
11
11
  })
12
- .describe("Start date (ISO 8601)"),
13
- end: z
12
+ .describe("End date (ISO 8601)"),
13
+ start: z
14
14
  .string()
15
15
  .refine((val) => !Number.isNaN(Date.parse(val)), {
16
16
  message: "Invalid date string",
17
17
  })
18
- .describe("End date (ISO 8601)"),
19
- calendarUrl: z.string(),
18
+ .describe("Start date (ISO 8601)"),
20
19
  },
20
+ name: "list-events",
21
21
  returns: "A list of events that fall within the given timeframe, each containing `uid`, `summary`, `start`, `end`, and optionally `description` and `location`",
22
22
  };
23
23
  export function registerListEvents(client, server) {
@@ -28,20 +28,20 @@ export function registerListEvents(client, server) {
28
28
  const { start, end } = args;
29
29
  const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
30
30
  const options = {
31
- start: new Date(start),
32
31
  end: new Date(end),
32
+ start: new Date(start),
33
33
  };
34
34
  const allEvents = await client.getEvents(calendarUrl, options);
35
35
  const data = allEvents.map((e) => ({
36
- uid: e.uid,
37
- summary: e.summary,
38
- start: e.start,
39
36
  end: e.end,
37
+ start: e.start,
38
+ summary: e.summary,
39
+ uid: e.uid,
40
40
  ...(e.description && { description: e.description }),
41
41
  ...(e.location && { location: e.location }),
42
42
  }));
43
43
  return {
44
- content: [{ type: "text", text: JSON.stringify(data) }],
44
+ content: [{ text: JSON.stringify(data), type: "text" }],
45
45
  };
46
46
  });
47
47
  }
@@ -23,32 +23,30 @@ function statusOf(t) {
23
23
  export function compareTodos(a, b) {
24
24
  const soA = a.sortOrder ?? Number.POSITIVE_INFINITY;
25
25
  const soB = b.sortOrder ?? Number.POSITIVE_INFINITY;
26
- if (soA !== soB)
26
+ if (soA !== soB) {
27
27
  return soA - soB;
28
+ }
28
29
  const dueA = a.due ? a.due.getTime() : Number.POSITIVE_INFINITY;
29
30
  const dueB = b.due ? b.due.getTime() : Number.POSITIVE_INFINITY;
30
- if (dueA !== dueB)
31
+ if (dueA !== dueB) {
31
32
  return dueA - dueB;
33
+ }
32
34
  return a.summary.localeCompare(b.summary);
33
35
  }
34
36
  export const listTodosDefinition = {
35
- name: "list-todos",
36
37
  description: "List tasks (VTODOs) in the calendar specified by its URL. By default returns only open tasks (NEEDS-ACTION and IN-PROCESS), sorted by manual order then due date. Use `status` to include completed (`COMPLETED`) or all (`ALL`) tasks, and `limit`/`offset` to page through long lists.",
37
38
  inputSchema: {
38
39
  calendarUrl: z.string(),
39
- status: statusFilterSchema
40
- .optional()
41
- .describe("Filter by status. `OPEN` (default) = NEEDS-ACTION + IN-PROCESS; `ALL` = everything; or an exact status (NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED)."),
42
- due_before: z
40
+ due_after: z
43
41
  .string()
44
42
  .datetime({ offset: true })
45
43
  .optional()
46
- .describe("Only tasks with a due date at or before this (ISO 8601). Undated tasks are excluded when a due window is set."),
47
- due_after: z
44
+ .describe("Only tasks with a due date at or after this (ISO 8601). Undated tasks are excluded when a due window is set."),
45
+ due_before: z
48
46
  .string()
49
47
  .datetime({ offset: true })
50
48
  .optional()
51
- .describe("Only tasks with a due date at or after this (ISO 8601). Undated tasks are excluded when a due window is set."),
49
+ .describe("Only tasks with a due date at or before this (ISO 8601). Undated tasks are excluded when a due window is set."),
52
50
  limit: z
53
51
  .number()
54
52
  .int()
@@ -62,7 +60,11 @@ export const listTodosDefinition = {
62
60
  .nonnegative()
63
61
  .optional()
64
62
  .describe("Tasks to skip (default 0)"),
63
+ status: statusFilterSchema
64
+ .optional()
65
+ .describe("Filter by status. `OPEN` (default) = NEEDS-ACTION + IN-PROCESS; `ALL` = everything; or an exact status (NEEDS-ACTION, COMPLETED, IN-PROCESS, CANCELLED)."),
65
66
  },
67
+ name: "list-todos",
66
68
  returns: "An object `{ todos, total, limit, offset }` where `total` is the count before pagination. Each todo has `uid`, `summary`, `status`, and optionally `due`, `start`, `completed`, `description`, `location`.",
67
69
  };
68
70
  export function registerListTodos(client, server) {
@@ -75,30 +77,36 @@ export function registerListTodos(client, server) {
75
77
  const limit = args.limit ?? 50;
76
78
  const offset = args.offset ?? 0;
77
79
  const hasWindow = args.due_after !== undefined || args.due_before !== undefined;
78
- const after = args.due_after !== undefined
79
- ? new Date(args.due_after).getTime()
80
- : null;
81
- const before = args.due_before !== undefined
82
- ? new Date(args.due_before).getTime()
83
- : null;
80
+ const after = args.due_after === undefined
81
+ ? null
82
+ : new Date(args.due_after).getTime();
83
+ const before = args.due_before === undefined
84
+ ? null
85
+ : new Date(args.due_before).getTime();
84
86
  const matchesStatus = (t) => {
85
87
  const s = statusOf(t);
86
- if (status === "ALL")
88
+ if (status === "ALL") {
87
89
  return true;
88
- if (status === "OPEN")
90
+ }
91
+ if (status === "OPEN") {
89
92
  return OPEN_STATUSES.includes(s);
93
+ }
90
94
  return s === status;
91
95
  };
92
96
  const matchesWindow = (t) => {
93
- if (!hasWindow)
97
+ if (!hasWindow) {
94
98
  return true;
95
- if (!t.due)
99
+ }
100
+ if (!t.due) {
96
101
  return false;
102
+ }
97
103
  const d = t.due.getTime();
98
- if (after !== null && d < after)
104
+ if (after !== null && d < after) {
99
105
  return false;
100
- if (before !== null && d > before)
106
+ }
107
+ if (before !== null && d > before) {
101
108
  return false;
109
+ }
102
110
  return true;
103
111
  };
104
112
  const all = await client.getTodos(calendarUrl, { all: true });
@@ -106,9 +114,9 @@ export function registerListTodos(client, server) {
106
114
  .filter((t) => matchesStatus(t) && matchesWindow(t))
107
115
  .sort(compareTodos);
108
116
  const todos = filtered.slice(offset, offset + limit).map((t) => ({
109
- uid: t.uid,
110
- summary: t.summary,
111
117
  status: statusOf(t),
118
+ summary: t.summary,
119
+ uid: t.uid,
112
120
  ...(t.due && { due: t.due }),
113
121
  ...(t.start && { start: t.start }),
114
122
  ...(t.completed && { completed: t.completed }),
@@ -118,13 +126,13 @@ export function registerListTodos(client, server) {
118
126
  return {
119
127
  content: [
120
128
  {
121
- type: "text",
122
129
  text: JSON.stringify({
123
- todos,
124
- total: filtered.length,
125
130
  limit,
126
131
  offset,
132
+ todos,
133
+ total: filtered.length,
127
134
  }),
135
+ type: "text",
128
136
  },
129
137
  ],
130
138
  };
@@ -2,29 +2,35 @@ import { z } from "zod";
2
2
  import { toWholeDayDate } from "./whole-day-date.js";
3
3
  export function toRecurrenceRule(r, wholeDay) {
4
4
  const out = {};
5
- if (r.freq !== undefined)
5
+ if (r.freq !== undefined) {
6
6
  out.freq = r.freq;
7
- if (r.interval !== undefined)
7
+ }
8
+ if (r.interval !== undefined) {
8
9
  out.interval = r.interval;
9
- if (r.count !== undefined)
10
+ }
11
+ if (r.count !== undefined) {
10
12
  out.count = r.count;
13
+ }
11
14
  if (r.until !== undefined) {
12
15
  out.until = wholeDay ? toWholeDayDate(r.until) : new Date(r.until);
13
16
  }
14
- if (r.byday !== undefined)
17
+ if (r.byday !== undefined) {
15
18
  out.byday = r.byday;
16
- if (r.bymonthday !== undefined)
19
+ }
20
+ if (r.bymonthday !== undefined) {
17
21
  out.bymonthday = r.bymonthday;
18
- if (r.bymonth !== undefined)
22
+ }
23
+ if (r.bymonth !== undefined) {
19
24
  out.bymonth = r.bymonth;
25
+ }
20
26
  return out;
21
27
  }
22
28
  export const recurrenceRuleSchema = z.object({
29
+ byday: z.array(z.string()).optional(), // e.g. ["MO", "TU"]
30
+ bymonth: z.array(z.number()).optional(),
31
+ bymonthday: z.array(z.number()).optional(),
32
+ count: z.number().optional(),
23
33
  freq: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(),
24
34
  interval: z.number().optional(),
25
- count: z.number().optional(),
26
35
  until: z.string().datetime({ offset: true }).optional(), // ISO 8601 string
27
- byday: z.array(z.string()).optional(), // e.g. ["MO", "TU"]
28
- bymonthday: z.array(z.number()).optional(),
29
- bymonth: z.array(z.number()).optional(),
30
36
  });
@@ -3,24 +3,24 @@ import { hrefFor, toCalendarPath } from "./caldav-href.js";
3
3
  import { recurrenceRuleSchema, toRecurrenceRule, } from "./recurrence-rule.js";
4
4
  import { carryOverWholeDayDates, toWholeDayDate } from "./whole-day-date.js";
5
5
  export const updateEventDefinition = {
6
- name: "update-event",
7
6
  description: "Updates an existing event in the calendar specified by its URL. Only provided fields are changed. For a one-day full-day event, set `wholeDay` to true and set `start` and `end` to the same calendar day.",
8
7
  inputSchema: {
8
+ calendarUrl: z.string(),
9
+ description: z.string().optional(),
10
+ end: z.string().datetime({ offset: true }).optional(),
11
+ location: z.string().optional(),
12
+ recurrenceRule: recurrenceRuleSchema.optional(),
13
+ start: z.string().datetime({ offset: true }).optional(),
14
+ summary: z.string().optional(),
9
15
  uid: z
10
16
  .string()
11
17
  .describe("Unique identifier of the event to update (obtained from list-events)"),
12
- calendarUrl: z.string(),
13
- summary: z.string().optional(),
14
- start: z.string().datetime({ offset: true }).optional(),
15
- end: z.string().datetime({ offset: true }).optional(),
16
18
  wholeDay: z
17
19
  .boolean()
18
20
  .optional()
19
21
  .describe("Update whether this is a whole-day event"),
20
- description: z.string().optional(),
21
- location: z.string().optional(),
22
- recurrenceRule: recurrenceRuleSchema.optional(),
23
22
  },
23
+ name: "update-event",
24
24
  returns: "The unique ID of the updated event",
25
25
  };
26
26
  export function registerUpdateEvent(client, server) {
@@ -56,7 +56,7 @@ export function registerUpdateEvent(client, server) {
56
56
  }),
57
57
  });
58
58
  return {
59
- content: [{ type: "text", text: updated.uid }],
59
+ content: [{ text: updated.uid, type: "text" }],
60
60
  };
61
61
  });
62
62
  }
@@ -2,20 +2,20 @@ import { z } from "zod";
2
2
  import { hrefFor, toCalendarPath } from "./caldav-href.js";
3
3
  import { todoStatusSchema } from "./todo-status.js";
4
4
  export const updateTodoDefinition = {
5
- name: "update-todo",
6
5
  description: "Updates an existing task (VTODO) in the calendar specified by its URL. Only provided fields are changed. To mark a task done, prefer the `complete-todo` tool.",
7
6
  inputSchema: {
8
- uid: z
9
- .string()
10
- .describe("Unique identifier of the todo to update (from list-todos)"),
11
7
  calendarUrl: z.string(),
12
- summary: z.string().optional(),
13
- due: z.string().datetime({ offset: true }).optional(),
14
- start: z.string().datetime({ offset: true }).optional(),
15
8
  description: z.string().optional(),
9
+ due: z.string().datetime({ offset: true }).optional(),
16
10
  location: z.string().optional(),
11
+ start: z.string().datetime({ offset: true }).optional(),
17
12
  status: todoStatusSchema.optional(),
13
+ summary: z.string().optional(),
14
+ uid: z
15
+ .string()
16
+ .describe("Unique identifier of the todo to update (from list-todos)"),
18
17
  },
18
+ name: "update-todo",
19
19
  returns: "The unique ID of the updated todo",
20
20
  };
21
21
  export function registerUpdateTodo(client, server) {
@@ -38,11 +38,13 @@ export function registerUpdateTodo(client, server) {
38
38
  // so the cleared case omits the property entirely rather than setting it
39
39
  // undefined (which exactOptionalPropertyTypes forbids).
40
40
  const { completed: priorCompleted, ...base } = existing;
41
- const completed = status === undefined
42
- ? priorCompleted
43
- : status === "COMPLETED"
44
- ? (priorCompleted ?? new Date())
45
- : undefined;
41
+ let completed;
42
+ if (status === undefined) {
43
+ completed = priorCompleted;
44
+ }
45
+ else if (status === "COMPLETED") {
46
+ completed = priorCompleted ?? new Date();
47
+ }
46
48
  const updated = await client.updateTodo(calendarUrl, {
47
49
  ...base,
48
50
  ...(summary !== undefined && { summary }),
@@ -54,7 +56,7 @@ export function registerUpdateTodo(client, server) {
54
56
  ...(completed !== undefined && { completed }),
55
57
  });
56
58
  return {
57
- content: [{ type: "text", text: updated.uid }],
59
+ content: [{ text: updated.uid, type: "text" }],
58
60
  };
59
61
  });
60
62
  }
@@ -46,6 +46,7 @@ export function localDayToWholeDayDate(value) {
46
46
  export function inclusiveEndToWholeDayDate(end, start) {
47
47
  const last = localDayToWholeDayDate(new Date(end.getTime() - 1));
48
48
  const first = localDayToWholeDayDate(start);
49
+ // biome-ignore lint/complexity/useMathMinMax: Math.max returns a number; this must return the later Date.
49
50
  return last < first ? first : last;
50
51
  }
51
52
  /**
@@ -62,8 +63,10 @@ export function carryOverWholeDayDates(existing) {
62
63
  const carried = {
63
64
  start: localDayToWholeDayDate(existing.start),
64
65
  };
65
- if (existing.end) {
66
- carried.end = inclusiveEndToWholeDayDate(existing.end, existing.start);
66
+ // Events built outside ts-caldav's parser can lack DTEND.
67
+ const end = existing.end;
68
+ if (end) {
69
+ carried.end = inclusiveEndToWholeDayDate(end, existing.start);
67
70
  }
68
71
  if (existing.recurrenceRule?.until) {
69
72
  carried.recurrenceRule = {
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "caldav-mcp",
3
- "mcpName": "io.github.dominik1001/caldav-mcp",
3
+ "version": "0.11.1",
4
4
  "description": "A CalDAV client using Model Context Protocol (MCP) to expose calendar operations as tools for AI assistants.",
5
- "version": "0.10.3",
6
- "main": "dist/index.js",
5
+ "homepage": "https://github.com/dominik1001/caldav-mcp#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/dominik1001/caldav-mcp/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/dominik1001/caldav-mcp.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Dominik Grusemann",
7
15
  "type": "module",
16
+ "main": "dist/index.js",
8
17
  "bin": {
9
18
  "caldav-mcp": "dist/index.js"
10
19
  },
@@ -13,36 +22,24 @@
13
22
  ],
14
23
  "scripts": {
15
24
  "build": "tsc && shx chmod +x dist/*.js",
16
- "dev": "tsx --watch --env-file=.env src/index.ts",
17
- "prepare": "lefthook install",
18
- "test": "vitest run",
19
- "test:watch": "vitest",
20
- "test:coverage": "vitest run --coverage",
21
25
  "check": "biome check .",
22
- "check:fix": "biome check --write .",
23
26
  "check:ci": "biome ci .",
27
+ "check:fix": "biome check --write .",
28
+ "dev": "tsx --watch --env-file=.env src/index.ts",
24
29
  "docs": "tsx scripts/gen-tool-docs.ts",
25
30
  "docs:check": "tsx scripts/gen-tool-docs.ts --check",
26
- "validate": "npm run check && npm test && npm run knip && npm run docs:check && npm run build",
31
+ "fix": "ultracite fix",
32
+ "knip": "knip",
33
+ "prepare": "lefthook install",
34
+ "semantic-release": "semantic-release",
27
35
  "smoke": "npm run build && tsx --env-file=.env scripts/smoke.ts",
28
36
  "smoke:agent": "npm run build && bash scripts/smoke-agent.sh",
29
- "watch": "tsc --watch",
30
- "semantic-release": "semantic-release",
31
- "knip": "knip"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/dominik1001/caldav-mcp.git"
36
- },
37
- "bugs": {
38
- "url": "https://github.com/dominik1001/caldav-mcp/issues"
39
- },
40
- "homepage": "https://github.com/dominik1001/caldav-mcp#readme",
41
- "author": "Dominik Grusemann",
42
- "license": "MIT",
43
- "engines": {
44
- "node": ">=18.0.0",
45
- "npm": ">=9.0.0"
37
+ "smoke:http": "npm run build && SMOKE_TRANSPORT=http tsx --env-file=.env scripts/smoke.ts",
38
+ "test": "vitest run",
39
+ "test:coverage": "vitest run --coverage",
40
+ "test:watch": "vitest",
41
+ "validate": "npm run check && npm test && npm run knip && npm run docs:check && npm run build",
42
+ "watch": "tsc --watch"
46
43
  },
47
44
  "dependencies": {
48
45
  "@modelcontextprotocol/sdk": "^1.26.0",
@@ -50,7 +47,7 @@
50
47
  "zod": "^4.4.3"
51
48
  },
52
49
  "devDependencies": {
53
- "@biomejs/biome": "^2.4.14",
50
+ "@biomejs/biome": "^2.5.15",
54
51
  "@commitlint/cli": "^21.0.0",
55
52
  "@commitlint/config-conventional": "^21.0.0",
56
53
  "@semantic-release/changelog": "^7.0.0",
@@ -65,6 +62,12 @@
65
62
  "shx": "^0.4.0",
66
63
  "tsx": "^4.21.0",
67
64
  "typescript": "^7.0.2",
65
+ "ultracite": "8.2.0",
68
66
  "vitest": "^5.0.0"
69
- }
67
+ },
68
+ "engines": {
69
+ "node": ">=18.0.0",
70
+ "npm": ">=9.0.0"
71
+ },
72
+ "mcpName": "io.github.dominik1001/caldav-mcp"
70
73
  }