apple-tools-mcp 3.3.2 → 3.3.3
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 +2 -0
- package/index.js +2 -2
- package/lib/httpAuth.js +42 -3
- package/lib/httpTransport.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -208,6 +208,8 @@ apple-tools-mcp http-token
|
|
|
208
208
|
|
|
209
209
|
`127.0.0.1` accepts connections only on this Mac. Set `httpHost` to a LAN or Tailscale address when a client on another machine should connect. `APPLE_TOOLS_HTTP_HOST` and `APPLE_TOOLS_HTTP_PORT` override the file. Do not send the token over an open network.
|
|
210
210
|
|
|
211
|
+
Under a secrets manager's runtime injection (for example `infisical run -- apple-tools-http`), set `APPLE_TOOLS_HTTP_TOKEN` and the server uses it instead of Keychain, which it then neither reads nor writes. To rotate without cutting off clients, start the server with the new token in `APPLE_TOOLS_HTTP_TOKEN` and the old one in `APPLE_TOOLS_HTTP_TOKEN_PREVIOUS`; once every client has the new token, restart without `APPLE_TOOLS_HTTP_TOKEN_PREVIOUS` and the old token stops working.
|
|
212
|
+
|
|
211
213
|
An example LaunchAgent is `examples/com.apple-tools-http.plist`. How to point Claude and other clients at it, including `apple-tools-http-proxy`, is in `examples/mcp-client.md`.
|
|
212
214
|
|
|
213
215
|
## Index commands
|
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { cycleEndFlags, indexUnavailableMessage, indexQueryGate } from "./lib/in
|
|
|
15
15
|
import { isIndexerMode, isPermissionsMode, isHttpMode, isHttpTokenMode } from "./lib/processMode.js";
|
|
16
16
|
import { runPermissionsCommand } from "./lib/permissions.js";
|
|
17
17
|
import { loadResolvedIndexInterval, logResolvedInterval, resolveHttpServerConfig } from "./lib/config.js";
|
|
18
|
-
import { loadOrCreateHttpAuthToken, verifyAuthHeader } from "./lib/httpAuth.js";
|
|
18
|
+
import { acceptedHttpAuthTokens, loadOrCreateHttpAuthToken, verifyAuthHeader } from "./lib/httpAuth.js";
|
|
19
19
|
import { createHttpRequestHandler } from "./lib/httpTransport.js";
|
|
20
20
|
import { createIndexerLock, DEFAULT_LOCK_HEARTBEAT_MS } from "./lib/indexerLock.js";
|
|
21
21
|
import {
|
|
@@ -1702,7 +1702,7 @@ async function startHttpServer(host, port) {
|
|
|
1702
1702
|
const { token } = loadOrCreateHttpAuthToken();
|
|
1703
1703
|
|
|
1704
1704
|
const httpServer = http.createServer(createHttpRequestHandler({
|
|
1705
|
-
token,
|
|
1705
|
+
token: acceptedHttpAuthTokens(token),
|
|
1706
1706
|
verifyAuthHeader,
|
|
1707
1707
|
createServer,
|
|
1708
1708
|
StreamableHTTPServerTransport,
|
package/lib/httpAuth.js
CHANGED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
* Keychain — never in a config file, the repo, argv, or logs.
|
|
12
12
|
* Print it only with the explicit http-token command. There is no external account, no
|
|
13
13
|
* OAuth flow, and no cost: it's a self-issued password, like an SSH key.
|
|
14
|
+
*
|
|
15
|
+
* Under a secrets manager's runtime injection (`infisical run`), APPLE_TOOLS_HTTP_TOKEN carries the token
|
|
16
|
+
* instead, and Keychain is neither read nor written. While a rotation is under way,
|
|
17
|
+
* APPLE_TOOLS_HTTP_TOKEN_PREVIOUS is also accepted, so clients still on the old token keep working until
|
|
18
|
+
* they have switched; unset it to retire the old token.
|
|
14
19
|
*/
|
|
15
20
|
|
|
16
21
|
import crypto from "crypto";
|
|
@@ -19,6 +24,13 @@ import { execFileSync as defaultExecFileSync } from "child_process";
|
|
|
19
24
|
|
|
20
25
|
export const KEYCHAIN_SERVICE = "apple-tools-mcp-http";
|
|
21
26
|
export const KEYCHAIN_ACCOUNT = "http-auth-token";
|
|
27
|
+
export const ENV_TOKEN = "APPLE_TOOLS_HTTP_TOKEN";
|
|
28
|
+
export const ENV_PREVIOUS_TOKEN = "APPLE_TOOLS_HTTP_TOKEN_PREVIOUS";
|
|
29
|
+
|
|
30
|
+
function envToken(env, name) {
|
|
31
|
+
const value = env && typeof env[name] === "string" ? env[name].trim() : "";
|
|
32
|
+
return value.length > 0 ? value : null;
|
|
33
|
+
}
|
|
22
34
|
|
|
23
35
|
function readFromKeychain(exec) {
|
|
24
36
|
try {
|
|
@@ -50,7 +62,8 @@ function generateToken(randomBytes) {
|
|
|
50
62
|
* log?: (msg: string) => void,
|
|
51
63
|
* forceNew?: boolean,
|
|
52
64
|
* execFileSync?: typeof defaultExecFileSync,
|
|
53
|
-
* randomBytes?: typeof crypto.randomBytes
|
|
65
|
+
* randomBytes?: typeof crypto.randomBytes,
|
|
66
|
+
* env?: Record<string, string | undefined>
|
|
54
67
|
* }} [options]
|
|
55
68
|
* @returns {{ token: string, generated: boolean }}
|
|
56
69
|
*/
|
|
@@ -58,8 +71,14 @@ export function loadOrCreateHttpAuthToken(options = {}) {
|
|
|
58
71
|
const log = options.log || ((msg) => console.error(msg));
|
|
59
72
|
const exec = options.execFileSync || defaultExecFileSync;
|
|
60
73
|
const randomBytes = options.randomBytes || crypto.randomBytes;
|
|
74
|
+
const env = options.env || process.env;
|
|
61
75
|
|
|
62
76
|
if (!options.forceNew) {
|
|
77
|
+
const injected = envToken(env, ENV_TOKEN);
|
|
78
|
+
if (injected) {
|
|
79
|
+
return { token: injected, generated: false };
|
|
80
|
+
}
|
|
81
|
+
|
|
63
82
|
const existing = readFromKeychain(exec);
|
|
64
83
|
if (existing) {
|
|
65
84
|
return { token: existing, generated: false };
|
|
@@ -73,15 +92,35 @@ export function loadOrCreateHttpAuthToken(options = {}) {
|
|
|
73
92
|
return { token, generated: true };
|
|
74
93
|
}
|
|
75
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Every token the server accepts: the current one, plus the previous one during a rotation overlap. The
|
|
97
|
+
* previous token is honoured only when the current token itself came from the environment.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} token the current token (from loadOrCreateHttpAuthToken)
|
|
100
|
+
* @param {Record<string, string | undefined>} [env]
|
|
101
|
+
* @returns {string[]}
|
|
102
|
+
*/
|
|
103
|
+
export function acceptedHttpAuthTokens(token, env = process.env) {
|
|
104
|
+
const previous = envToken(env, ENV_PREVIOUS_TOKEN);
|
|
105
|
+
return previous && envToken(env, ENV_TOKEN) === token && previous !== token ? [token, previous] : [token];
|
|
106
|
+
}
|
|
107
|
+
|
|
76
108
|
/**
|
|
77
109
|
* Constant-time check of an incoming `Authorization: Bearer <token>` header
|
|
78
|
-
* against the expected token. Never throws.
|
|
110
|
+
* against the expected token, or any of a list of accepted tokens. Never throws.
|
|
79
111
|
*
|
|
80
112
|
* @param {string | undefined | null} headerValue
|
|
81
|
-
* @param {string} expectedToken
|
|
113
|
+
* @param {string | string[]} expectedToken
|
|
82
114
|
* @returns {boolean}
|
|
83
115
|
*/
|
|
84
116
|
export function verifyAuthHeader(headerValue, expectedToken) {
|
|
117
|
+
if (Array.isArray(expectedToken)) {
|
|
118
|
+
// Check every entry (no early exit), so timing doesn't reveal which one matched.
|
|
119
|
+
return expectedToken.reduce((ok, expected) => verifyAuthHeader(headerValue, expected) || ok, false);
|
|
120
|
+
}
|
|
121
|
+
if (typeof expectedToken !== "string" || expectedToken.length === 0) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
85
124
|
if (typeof headerValue !== "string") {
|
|
86
125
|
return false;
|
|
87
126
|
}
|
package/lib/httpTransport.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {{
|
|
10
|
-
* token: string,
|
|
11
|
-
* verifyAuthHeader: (header: string | string[] | undefined, token: string) => boolean,
|
|
10
|
+
* token: string | string[],
|
|
11
|
+
* verifyAuthHeader: (header: string | string[] | undefined, token: string | string[]) => boolean,
|
|
12
12
|
* createServer: () => { connect: (transport: unknown) => Promise<void>, close: () => Promise<void> },
|
|
13
13
|
* StreamableHTTPServerTransport: new (options: { sessionIdGenerator: undefined }) => { handleRequest: (req: unknown, res: unknown) => Promise<void>, close: () => Promise<void> },
|
|
14
14
|
* packageVersion: string,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apple-tools-mcp",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "MCP server for semantic search and write actions across Apple Mail, Messages, Calendar, and Contacts. Speaks stdio (local) or bearer-token-authenticated Streamable HTTP (LAN / Tailscale).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|