From bd74d2df758008568fdd36ccd75cc45b1ceface2 Mon Sep 17 00:00:00 2001 From: Jia Ji Chen Date: Sat, 29 Mar 2025 22:22:09 +1000 Subject: [PATCH] updated for windows to calculate path for credential file. also updated read me. --- README.md | 17 +++++++++++++++++ src/index.ts | 19 ++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 385f6ad..bcbf205 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,8 @@ To authenticate and save credentials: To integrate this server with the desktop app, add the following to your app's server configuration: +#### MacOS + ```json { "mcpServers": { @@ -106,3 +108,18 @@ To integrate this server with the desktop app, add the following to your app's s } } ``` + +#### Windows + +```json +{ + "mcpServers": { + "gtasks": { + "command": "C:\\Program Files\\nodejs\\node.exe", + "args": [ + "{ABSOLUTE PATH TO FILE HERE}\\dist\\index.js" + ] + } + } +} +``` diff --git a/src/index.ts b/src/index.ts index 0118656..d59bf75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,9 @@ import { import fs from "fs"; import { google, tasks_v1 } from "googleapis"; import path from "path"; +import { fileURLToPath } from "url"; import { TaskActions, TaskResources } from "./Tasks.js"; +import { Console } from "console"; const tasks = google.tasks("v1"); @@ -232,18 +234,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { } throw new Error("Tool not found"); }); +const folderPath = path.dirname(fileURLToPath(import.meta.url)); +//const folderPath = path.dirname(path.fileURLToPath(import.meta.url)); -const credentialsPath = path.join( - path.dirname(new URL(import.meta.url).pathname), - "../.gtasks-server-credentials.json", -); +function getFilePath(relativePath: string): string { + return path.join(folderPath, relativePath); + } + +const credentialsPath = getFilePath("../.gtasks-server-credentials.json"); async function authenticateAndSaveCredentials() { console.log("Launching auth flow…"); - const p = path.join( - path.dirname(new URL(import.meta.url).pathname), - "../gcp-oauth.keys.json", - ); + const p = getFilePath("../gcp-oauth.keys.json"); console.log(p); const auth = await authenticate({ @@ -261,7 +263,6 @@ async function loadCredentialsAndRunServer() { ); process.exit(1); } - const credentials = JSON.parse(fs.readFileSync(credentialsPath, "utf-8")); const auth = new google.auth.OAuth2(); auth.setCredentials(credentials);