summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaoyuren <13851610112@163.com>2026-04-25 19:02:50 -0300
committerhaoyuren <13851610112@163.com>2026-04-25 19:02:50 -0300
commit5a7e8f86b1c05330df89731b2d6539fb5b3b7997 (patch)
tree24c9a900b2494796478af2936010fb33d16e4174
parent91544f44995bfde3735cb6d956ebe065b0943702 (diff)
Fix packaged MCP server pathv0.3.8
-rw-r--r--package-lock.json4
-rw-r--r--package.json2
-rw-r--r--src/main/index.ts46
3 files changed, 36 insertions, 16 deletions
diff --git a/package-lock.json b/package-lock.json
index fd2d874..7758397 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "lattex",
- "version": "0.3.7",
+ "version": "0.3.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "lattex",
- "version": "0.3.7",
+ "version": "0.3.8",
"hasInstallScript": true,
"license": "AGPL-3.0",
"dependencies": {
diff --git a/package.json b/package.json
index 6b4110f..6f0f39d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "lattex",
- "version": "0.3.7",
+ "version": "0.3.8",
"description": "LaTeX editor with real-time Overleaf sync",
"license": "AGPL-3.0",
"author": "Yuren Hao",
diff --git a/src/main/index.ts b/src/main/index.ts
index 7c26a6c..0ad1ed1 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -3,7 +3,7 @@
import { app, BrowserWindow, ipcMain, dialog, shell, net } from 'electron'
import { join, basename, relative, extname } from 'path'
-import { readFile, writeFile, mkdir as mkdirAsync, unlink, readdir, stat } from 'fs/promises'
+import { copyFile, readFile, writeFile, mkdir as mkdirAsync, unlink, readdir, stat } from 'fs/promises'
import { spawn } from 'child_process'
import * as pty from 'node-pty'
import { OverleafSocket, type RootFolder, type SubFolder, type JoinDocResult } from './overleafSocket'
@@ -47,6 +47,23 @@ async function writeMcpState(): Promise<void> {
} catch { /* ignore */ }
}
+async function prepareMcpServerPath(tmpDir: string): Promise<string> {
+ const sourcePath = app.isPackaged
+ ? join(app.getAppPath() + '.unpacked', 'out', 'mcp', 'lattex.mjs')
+ : join(__dirname, '..', '..', 'src', 'mcp', 'lattex.mjs')
+
+ if (!app.isPackaged) return sourcePath
+
+ // Unsigned macOS apps can be launched from an App Translocation path. That
+ // path is not stable enough to persist in .mcp.json, so copy the bundled MCP
+ // server into the live project directory and point Claude at the copy.
+ const mcpDir = join(tmpDir, '.lattex')
+ await mkdirAsync(mcpDir, { recursive: true })
+ const serverPath = join(mcpDir, 'lattex-mcp.mjs')
+ await copyFile(sourcePath, serverPath)
+ return serverPath
+}
+
let commentContextRefreshTimer: ReturnType<typeof setTimeout> | null = null
function scheduleCommentContextRefresh(): void {
if (commentContextRefreshTimer) clearTimeout(commentContextRefreshTimer)
@@ -828,20 +845,23 @@ ipcMain.handle('ot:connect', async (_e, projectId: string) => {
mcpProjectId = projectId
mcpCommentContexts = {}
mcpPathDocMap = pathDocMap
- writeMcpState()
+ await writeMcpState()
// Write .mcp.json so Claude Code auto-discovers the MCP server
- // Dev: use source file. Packaged: use bundled file in app.asar.unpacked/out/mcp/
- const mcpServerPath = app.isPackaged
- ? join(app.getAppPath() + '.unpacked', 'out', 'mcp', 'lattex.mjs')
- : join(__dirname, '..', '..', 'src', 'mcp', 'lattex.mjs')
- writeFile(join(tmpDir, '.mcp.json'), JSON.stringify({
- mcpServers: {
- lattex: {
- command: 'node',
- args: [mcpServerPath]
+ // Dev: use source file. Packaged: copy bundled server into the project
+ // temp dir so .mcp.json never contains a stale App Translocation path.
+ try {
+ const mcpServerPath = await prepareMcpServerPath(tmpDir)
+ await writeFile(join(tmpDir, '.mcp.json'), JSON.stringify({
+ mcpServers: {
+ lattex: {
+ command: 'node',
+ args: [mcpServerPath]
+ }
}
- }
- }, null, 2)).catch(() => {})
+ }, null, 2))
+ } catch (e) {
+ console.log('[mcp] failed to write MCP config:', e)
+ }
// Clean up old root-level CLAUDE.md (was incorrectly placed there before)
require('fs').unlink(join(tmpDir, 'CLAUDE.md'), () => {})
// Create claude-workspace/ for Claude Code scratch space (not synced to Overleaf)