Skip to content

Build your personal knowledge base with Trilium Notes

fix(electron): wrong MCP URL

Elian Doranb4abe442d8dd
diff --git a/apps/client/src/widgets/type_widgets/options/llm.tsx b/apps/client/src/widgets/type_widgets/options/llm.tsx
index 893d2aaf03..b07ea45ac9 100644
--- a/apps/client/src/widgets/type_widgets/options/llm.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm.tsx
@@ -81,6 +81,12 @@ function ProviderSettings() {
}
function getMcpEndpointUrl() {
+ // On desktop the renderer lives on `trilium-app://app/`, so window.location
+ // does not point at a reachable HTTP origin. The server injects an absolute
+ // httpBaseUrl in that case; in the browser we derive it from the page.
+ if (window.glob.httpBaseUrl) {
+ return `${window.glob.httpBaseUrl}/mcp`;
+ }
const port = window.location.port || (window.location.protocol === "https:" ? "443" : "80");
return `${window.location.protocol}//localhost:${port}/mcp`;
}
diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.ts
index f206125f32..26fba8825a 100644
--- a/apps/server/src/routes/index.ts
+++ b/apps/server/src/routes/index.ts
@@ -39,7 +39,12 @@ export function bootstrap(req: Request, res: Response) {
instanceName: config.General ? config.General.instanceName : null,
// The desktop renderer loads from trilium-app://, so location-based
// ws:// URL derivation no longer works there. Send an absolute URL.
- wsBaseUrl: isElectron ? `ws://127.0.0.1:${port}/` : undefined
+ wsBaseUrl: isElectron ? `ws://127.0.0.1:${port}/` : undefined,
+ // Same reason for HTTP-origin-dependent UI (e.g. the MCP URL shown
+ // in Options) — give the renderer a real loopback origin to display.
+ httpBaseUrl: isElectron
+ ? `${config["Network"]["https"] ? "https" : "http"}://127.0.0.1:${port}`
+ : undefined
};
if (!isDbInitialized) {
res.send({
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index 50042f0b74..7d1be2f4af 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -367,6 +367,16 @@ export type BootstrapDefinition = {
* where the WS URL can still be derived from `window.location`.
*/
wsBaseUrl?: string;
+ /**
+ * Absolute base URL of the local HTTP server (e.g. `http://127.0.0.1:37840`),
+ * sent by the desktop app because the renderer page lives on the
+ * `trilium-app://` custom protocol where `window.location` does not point
+ * at a reachable HTTP origin. Used to display copy-pasteable endpoints
+ * (such as the MCP URL) that external clients connect to over loopback.
+ * Undefined for the regular web build, where `window.location` already
+ * encodes the reachable HTTP origin.
+ */
+ httpBaseUrl?: string;
hasNativeTitleBar: boolean;
hasBackgroundEffects: boolean;
maxEntityChangeIdAtLoad?: number;