reflect-mcp 1.0.0 → 1.0.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/dist/cli.d.ts CHANGED
@@ -3,5 +3,6 @@
3
3
  * Reflect MCP Server - CLI Entry Point
4
4
  *
5
5
  * Run with: npx reflect-mcp <db-path>
6
+ * Install: npx reflect-mcp install <db-path>
6
7
  */
7
8
  export {};
package/dist/cli.js CHANGED
@@ -3,54 +3,212 @@
3
3
  * Reflect MCP Server - CLI Entry Point
4
4
  *
5
5
  * Run with: npx reflect-mcp <db-path>
6
+ * Install: npx reflect-mcp install <db-path>
6
7
  */
7
8
  import { startReflectMCPServer } from "./server.js";
8
- import { DEFAULT_DB_PATH } from "./utils.js";
9
+ import { DEFAULT_DB_PATH, expandPath } from "./utils.js";
10
+ import * as fs from "fs";
11
+ import * as path from "path";
12
+ import * as os from "os";
13
+ import { execSync } from "child_process";
9
14
  const REFLECT_CLIENT_ID = "55798f25d5a24efb95e4174fff3d219e";
10
- // Parse command line arguments
11
- function parseArgs() {
12
- const args = process.argv.slice(2);
13
- let dbPath = DEFAULT_DB_PATH;
14
- let port = 3000;
15
- for (let i = 0; i < args.length; i++) {
16
- if (args[i] === "--port" && args[i + 1]) {
17
- port = parseInt(args[++i]);
18
- }
19
- else if (args[i] === "--help" || args[i] === "-h") {
20
- console.log(`
21
- Usage: reflect-mcp [db-path] [options]
15
+ const LAUNCH_AGENT_LABEL = "com.reflect-mcp";
16
+ const LAUNCH_AGENT_DIR = path.join(os.homedir(), "Library/LaunchAgents");
17
+ const LAUNCH_AGENT_PATH = path.join(LAUNCH_AGENT_DIR, `${LAUNCH_AGENT_LABEL}.plist`);
18
+ // Get the command and arguments
19
+ const args = process.argv.slice(2);
20
+ const command = args[0];
21
+ // Handle commands
22
+ if (command === "install") {
23
+ install(args.slice(1));
24
+ }
25
+ else if (command === "uninstall") {
26
+ uninstall();
27
+ }
28
+ else if (command === "status") {
29
+ status();
30
+ }
31
+ else if (command === "--help" || command === "-h") {
32
+ showHelp();
33
+ }
34
+ else {
35
+ // Default: run the server
36
+ runServer(args);
37
+ }
38
+ function showHelp() {
39
+ console.log(`
40
+ Reflect MCP Server - Connect your Reflect notes to Claude
41
+
42
+ Usage:
43
+ reflect-mcp [db-path] [--port <port>] Run the server
44
+ reflect-mcp install [db-path] Install as auto-start service
45
+ reflect-mcp uninstall Remove auto-start service
46
+ reflect-mcp status Check service status
22
47
 
23
48
  Arguments:
24
- db-path Path to Reflect SQLite database
25
- (default: ${DEFAULT_DB_PATH})
49
+ db-path Path to Reflect SQLite database
50
+ (default: ${DEFAULT_DB_PATH})
26
51
 
27
52
  Options:
28
- --port <port> Port to run server on (default: 3000)
29
- --help, -h Show this help message
53
+ --port <port> Port to run server on (default: 3000)
30
54
 
31
55
  Examples:
32
- npx reflect-mcp
33
- npx reflect-mcp ~/Library/Application\\ Support/Reflect/File\\ System/000/t/00/00000000
34
- npx reflect-mcp /path/to/reflect/db --port 4000
56
+ reflect-mcp install # Install with default db path
57
+ reflect-mcp install ~/my/reflect/db # Install with custom db path
58
+ reflect-mcp uninstall # Remove auto-start
59
+ reflect-mcp # Run server manually
35
60
  `);
36
- process.exit(0);
61
+ process.exit(0);
62
+ }
63
+ function install(installArgs) {
64
+ let dbPath = DEFAULT_DB_PATH;
65
+ let port = 3000;
66
+ // Parse install arguments
67
+ for (let i = 0; i < installArgs.length; i++) {
68
+ if (installArgs[i] === "--port" && installArgs[i + 1]) {
69
+ port = parseInt(installArgs[++i]);
37
70
  }
38
- else if (!args[i].startsWith("--")) {
39
- // Positional argument = db path
40
- dbPath = args[i];
71
+ else if (!installArgs[i].startsWith("--")) {
72
+ dbPath = installArgs[i];
41
73
  }
42
74
  }
43
- return { dbPath, port };
44
- }
45
- const { dbPath, port: PORT } = parseArgs();
46
- startReflectMCPServer({
47
- clientId: REFLECT_CLIENT_ID,
48
- port: PORT,
49
- dbPath,
50
- }).then(() => {
51
- console.log(`Reflect MCP Server running on http://localhost:${PORT}`);
52
- console.log(`Database: ${dbPath}`);
53
- }).catch((err) => {
54
- console.error("Failed to start server:", err);
55
- process.exit(1);
56
- });
75
+ const expandedDbPath = expandPath(dbPath);
76
+ const nodePath = process.execPath;
77
+ const cliPath = process.argv[1];
78
+ console.log("šŸ“¦ Installing Reflect MCP Server as auto-start service...\n");
79
+ // Create Launch Agent directory if needed
80
+ if (!fs.existsSync(LAUNCH_AGENT_DIR)) {
81
+ fs.mkdirSync(LAUNCH_AGENT_DIR, { recursive: true });
82
+ }
83
+ // Stop existing service if running
84
+ try {
85
+ execSync(`launchctl stop ${LAUNCH_AGENT_LABEL} 2>/dev/null`, { stdio: "ignore" });
86
+ execSync(`launchctl unload ${LAUNCH_AGENT_PATH} 2>/dev/null`, { stdio: "ignore" });
87
+ }
88
+ catch {
89
+ // Ignore errors - service might not exist yet
90
+ }
91
+ // Create plist content
92
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
93
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
94
+ <plist version="1.0">
95
+ <dict>
96
+ <key>Label</key>
97
+ <string>${LAUNCH_AGENT_LABEL}</string>
98
+ <key>ProgramArguments</key>
99
+ <array>
100
+ <string>${nodePath}</string>
101
+ <string>${cliPath}</string>
102
+ <string>${expandedDbPath}</string>
103
+ <string>--port</string>
104
+ <string>${port}</string>
105
+ </array>
106
+ <key>RunAtLoad</key>
107
+ <true/>
108
+ <key>KeepAlive</key>
109
+ <true/>
110
+ <key>StandardErrorPath</key>
111
+ <string>/tmp/reflect-mcp.log</string>
112
+ <key>StandardOutPath</key>
113
+ <string>/tmp/reflect-mcp.log</string>
114
+ </dict>
115
+ </plist>`;
116
+ // Write plist file
117
+ fs.writeFileSync(LAUNCH_AGENT_PATH, plist);
118
+ console.log(`āœ… Created: ${LAUNCH_AGENT_PATH}`);
119
+ // Load and start the service
120
+ try {
121
+ execSync(`launchctl load ${LAUNCH_AGENT_PATH}`);
122
+ execSync(`launchctl start ${LAUNCH_AGENT_LABEL}`);
123
+ console.log("āœ… Service installed and started!\n");
124
+ }
125
+ catch (error) {
126
+ console.error("āŒ Failed to start service:", error);
127
+ process.exit(1);
128
+ }
129
+ console.log(`šŸš€ Reflect MCP Server will now auto-start on login`);
130
+ console.log(` Server: http://localhost:${port}`);
131
+ console.log(` Database: ${expandedDbPath}`);
132
+ console.log(` Logs: tail -f /tmp/reflect-mcp.log\n`);
133
+ console.log(`šŸ“‹ Add to Claude Desktop config (~/.config/claude/claude_desktop_config.json):`);
134
+ console.log(`{
135
+ "mcpServers": {
136
+ "reflect": {
137
+ "command": "npx",
138
+ "args": ["-y", "mcp-remote", "http://localhost:${port}/mcp"]
139
+ }
140
+ }
141
+ }`);
142
+ }
143
+ function uninstall() {
144
+ console.log("šŸ—‘ļø Removing Reflect MCP Server auto-start service...\n");
145
+ try {
146
+ execSync(`launchctl stop ${LAUNCH_AGENT_LABEL} 2>/dev/null`, { stdio: "ignore" });
147
+ execSync(`launchctl unload ${LAUNCH_AGENT_PATH} 2>/dev/null`, { stdio: "ignore" });
148
+ }
149
+ catch {
150
+ // Ignore errors
151
+ }
152
+ if (fs.existsSync(LAUNCH_AGENT_PATH)) {
153
+ fs.unlinkSync(LAUNCH_AGENT_PATH);
154
+ console.log(`āœ… Removed: ${LAUNCH_AGENT_PATH}`);
155
+ }
156
+ console.log("āœ… Service uninstalled. Server will no longer auto-start.");
157
+ }
158
+ function status() {
159
+ console.log("šŸ“Š Reflect MCP Server Status\n");
160
+ // Check if plist exists
161
+ if (fs.existsSync(LAUNCH_AGENT_PATH)) {
162
+ console.log(`āœ… Launch Agent installed: ${LAUNCH_AGENT_PATH}`);
163
+ }
164
+ else {
165
+ console.log("āŒ Launch Agent not installed");
166
+ console.log(" Run: reflect-mcp install");
167
+ return;
168
+ }
169
+ // Check if service is running
170
+ try {
171
+ const result = execSync(`launchctl list | grep ${LAUNCH_AGENT_LABEL}`, { encoding: "utf-8" });
172
+ if (result.includes(LAUNCH_AGENT_LABEL)) {
173
+ const parts = result.trim().split(/\s+/);
174
+ const pid = parts[0];
175
+ const exitCode = parts[1];
176
+ if (pid !== "-") {
177
+ console.log(`āœ… Service running (PID: ${pid})`);
178
+ }
179
+ else if (exitCode === "0") {
180
+ console.log("āš ļø Service stopped (last exit: success)");
181
+ }
182
+ else {
183
+ console.log(`āŒ Service stopped (last exit code: ${exitCode})`);
184
+ }
185
+ }
186
+ }
187
+ catch {
188
+ console.log("āŒ Service not loaded");
189
+ }
190
+ console.log(`\nšŸ“ Logs: tail -f /tmp/reflect-mcp.log`);
191
+ }
192
+ function runServer(serverArgs) {
193
+ let dbPath = DEFAULT_DB_PATH;
194
+ let port = 3000;
195
+ for (let i = 0; i < serverArgs.length; i++) {
196
+ if (serverArgs[i] === "--port" && serverArgs[i + 1]) {
197
+ port = parseInt(serverArgs[++i]);
198
+ }
199
+ else if (!serverArgs[i].startsWith("--")) {
200
+ dbPath = serverArgs[i];
201
+ }
202
+ }
203
+ startReflectMCPServer({
204
+ clientId: REFLECT_CLIENT_ID,
205
+ port,
206
+ dbPath,
207
+ }).then(() => {
208
+ console.log(`Reflect MCP Server running on http://localhost:${port}`);
209
+ console.log(`Database: ${dbPath}`);
210
+ }).catch((err) => {
211
+ console.error("Failed to start server:", err);
212
+ process.exit(1);
213
+ });
214
+ }
@@ -82,6 +82,7 @@ export declare class PKCEOAuthProxy {
82
82
  redirect_uris?: string[];
83
83
  }>;
84
84
  loadUpstreamTokens(proxyToken: string): TokenData | null;
85
+ getFirstValidToken(): TokenData | null;
85
86
  private startCleanup;
86
87
  destroy(): void;
87
88
  }
@@ -281,6 +281,16 @@ export class PKCEOAuthProxy {
281
281
  }
282
282
  return data;
283
283
  }
284
+ // Get first valid token (for stdio mode where we don't have specific token ID)
285
+ getFirstValidToken() {
286
+ const now = new Date();
287
+ for (const [id, token] of this.tokens) {
288
+ if (token.expiresAt > now) {
289
+ return token;
290
+ }
291
+ }
292
+ return null;
293
+ }
284
294
  // Cleanup expired transactions and tokens
285
295
  startCleanup() {
286
296
  this.cleanupInterval = setInterval(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reflect-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "MCP server for Reflect Notes - connect your notes to Claude Desktop. Just run: npx reflect-mcp",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
@@ -35,6 +35,7 @@
35
35
  "node": ">=18"
36
36
  },
37
37
  "dependencies": {
38
+ "@modelcontextprotocol/sdk": "^1.25.1",
38
39
  "better-sqlite3": "^11.0.0",
39
40
  "fastmcp": "^3.25.4",
40
41
  "zod": "^4.1.13"