google-workspace-mcp 2.0.0
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/LICENSE +7 -0
- package/README.md +765 -0
- package/dist/accounts.d.ts +85 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +520 -0
- package/dist/accounts.js.map +1 -0
- package/dist/auth.d.ts +4 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +206 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +426 -0
- package/dist/cli.js.map +1 -0
- package/dist/errorHelpers.d.ts +40 -0
- package/dist/errorHelpers.d.ts.map +1 -0
- package/dist/errorHelpers.js +52 -0
- package/dist/errorHelpers.js.map +1 -0
- package/dist/googleDocsApiHelpers.d.ts +118 -0
- package/dist/googleDocsApiHelpers.d.ts.map +1 -0
- package/dist/googleDocsApiHelpers.js +850 -0
- package/dist/googleDocsApiHelpers.js.map +1 -0
- package/dist/googleSheetsApiHelpers.d.ts +75 -0
- package/dist/googleSheetsApiHelpers.d.ts.map +1 -0
- package/dist/googleSheetsApiHelpers.js +376 -0
- package/dist/googleSheetsApiHelpers.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +119 -0
- package/dist/server.js.map +1 -0
- package/dist/serverWrapper.d.ts +21 -0
- package/dist/serverWrapper.d.ts.map +1 -0
- package/dist/serverWrapper.js +74 -0
- package/dist/serverWrapper.js.map +1 -0
- package/dist/tools/accounts.tools.d.ts +3 -0
- package/dist/tools/accounts.tools.d.ts.map +1 -0
- package/dist/tools/accounts.tools.js +154 -0
- package/dist/tools/accounts.tools.js.map +1 -0
- package/dist/tools/calendar.tools.d.ts +3 -0
- package/dist/tools/calendar.tools.d.ts.map +1 -0
- package/dist/tools/calendar.tools.js +487 -0
- package/dist/tools/calendar.tools.js.map +1 -0
- package/dist/tools/docs.tools.d.ts +3 -0
- package/dist/tools/docs.tools.d.ts.map +1 -0
- package/dist/tools/docs.tools.js +1766 -0
- package/dist/tools/docs.tools.js.map +1 -0
- package/dist/tools/drive.tools.d.ts +3 -0
- package/dist/tools/drive.tools.d.ts.map +1 -0
- package/dist/tools/drive.tools.js +1001 -0
- package/dist/tools/drive.tools.js.map +1 -0
- package/dist/tools/forms.tools.d.ts +3 -0
- package/dist/tools/forms.tools.d.ts.map +1 -0
- package/dist/tools/forms.tools.js +370 -0
- package/dist/tools/forms.tools.js.map +1 -0
- package/dist/tools/gmail.tools.d.ts +3 -0
- package/dist/tools/gmail.tools.d.ts.map +1 -0
- package/dist/tools/gmail.tools.js +520 -0
- package/dist/tools/gmail.tools.js.map +1 -0
- package/dist/tools/sheets.tools.d.ts +3 -0
- package/dist/tools/sheets.tools.d.ts.map +1 -0
- package/dist/tools/sheets.tools.js +521 -0
- package/dist/tools/sheets.tools.js.map +1 -0
- package/dist/tools/slides.tools.d.ts +3 -0
- package/dist/tools/slides.tools.d.ts.map +1 -0
- package/dist/tools/slides.tools.js +323 -0
- package/dist/tools/slides.tools.js.map +1 -0
- package/dist/types.d.ts +507 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +185 -0
- package/dist/types.js.map +1 -0
- package/dist/urlHelpers.d.ts +60 -0
- package/dist/urlHelpers.d.ts.map +1 -0
- package/dist/urlHelpers.js +101 -0
- package/dist/urlHelpers.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAWlC,sBAAsB;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,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W,GAAG;YAClB,aAAa,EAAE,OAAgB;SAChC,CAAC;QAEF,MAAM,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAChC,OAAO,CAAC,KAAK,CACX,4BAA4B,WAAW,CAAC,aAAa,iCAAiC,CACvF,CAAC;QAEF,OAAO,CAAC,KAAK,CACX,iFAAiF,CAClF,CAAC;IACJ,CAAC;IAAC,OAAO,UAAmB,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACtF,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type FastMCP } from 'fastmcp';
|
|
2
|
+
import type { FastMCPSessionAuth } from './types.js';
|
|
3
|
+
export interface ServerConfig {
|
|
4
|
+
/** When true, tools with readOnlyHint: false will be blocked at runtime */
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a FastMCP server to:
|
|
9
|
+
* 1. Add global error handling with help links to all tools
|
|
10
|
+
* 2. Enforce read-only mode based on tool annotations (if enabled)
|
|
11
|
+
*
|
|
12
|
+
* @param server - The FastMCP server instance
|
|
13
|
+
* @param config - Server configuration
|
|
14
|
+
* @returns The same server instance with addTool wrapped
|
|
15
|
+
*/
|
|
16
|
+
export declare function createServerWithConfig<T extends FastMCPSessionAuth>(server: FastMCP<T>, config: ServerConfig): FastMCP<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Parse server config from environment variables
|
|
19
|
+
*/
|
|
20
|
+
export declare function getServerConfigFromEnv(): ServerConfig;
|
|
21
|
+
//# sourceMappingURL=serverWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverWrapper.d.ts","sourceRoot":"","sources":["../src/serverWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,CAAC;CACnB;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,kBAAkB,EACjE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAClB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,CAAC,CAAC,CAsCZ;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAIrD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const HELP_MESSAGE = `
|
|
2
|
+
|
|
3
|
+
For help, see: https://github.com/zueai/google-workspace-mcp#troubleshooting
|
|
4
|
+
To report an issue: https://github.com/zueai/google-workspace-mcp/issues`;
|
|
5
|
+
/**
|
|
6
|
+
* Enhances error messages with help links
|
|
7
|
+
*/
|
|
8
|
+
function enhanceErrorMessage(error) {
|
|
9
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10
|
+
return `${message}${HELP_MESSAGE}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Wraps a tool's execute function with error handling that adds help links
|
|
14
|
+
*/
|
|
15
|
+
function wrapExecuteWithErrorHandler(tool) {
|
|
16
|
+
const originalExecute = tool.execute;
|
|
17
|
+
const wrappedExecute = async (args, context) => {
|
|
18
|
+
try {
|
|
19
|
+
return await originalExecute(args, context);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new Error(enhanceErrorMessage(error));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
...tool,
|
|
27
|
+
execute: wrappedExecute,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wraps a FastMCP server to:
|
|
32
|
+
* 1. Add global error handling with help links to all tools
|
|
33
|
+
* 2. Enforce read-only mode based on tool annotations (if enabled)
|
|
34
|
+
*
|
|
35
|
+
* @param server - The FastMCP server instance
|
|
36
|
+
* @param config - Server configuration
|
|
37
|
+
* @returns The same server instance with addTool wrapped
|
|
38
|
+
*/
|
|
39
|
+
export function createServerWithConfig(server, config) {
|
|
40
|
+
// Store original addTool method
|
|
41
|
+
const originalAddTool = server.addTool.bind(server);
|
|
42
|
+
// Override addTool to wrap all tools with error handling (and read-only enforcement if configured)
|
|
43
|
+
server.addTool = function (tool) {
|
|
44
|
+
const isReadOnly = tool.annotations?.readOnlyHint === true;
|
|
45
|
+
// In read-only mode, block non-read-only tools
|
|
46
|
+
if (config.readOnly && !isReadOnly) {
|
|
47
|
+
const toolName = tool.name;
|
|
48
|
+
const blockedExecute = (_args, _context) => {
|
|
49
|
+
return Promise.reject(new Error(`Tool "${toolName}" is disabled: server is running in read-only mode. ` +
|
|
50
|
+
`This tool would modify data. Restart the server without --read-only to enable write operations.${HELP_MESSAGE}`));
|
|
51
|
+
};
|
|
52
|
+
const blockedTool = {
|
|
53
|
+
...tool,
|
|
54
|
+
execute: blockedExecute,
|
|
55
|
+
description: `[READ-ONLY MODE - DISABLED] ${tool.description || ''}`,
|
|
56
|
+
};
|
|
57
|
+
originalAddTool(blockedTool);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Wrap tool with error handler
|
|
61
|
+
const wrappedTool = wrapExecuteWithErrorHandler(tool);
|
|
62
|
+
originalAddTool(wrappedTool);
|
|
63
|
+
};
|
|
64
|
+
return server;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parse server config from environment variables
|
|
68
|
+
*/
|
|
69
|
+
export function getServerConfigFromEnv() {
|
|
70
|
+
return {
|
|
71
|
+
readOnly: process.env.GOOGLE_MCP_READ_ONLY === 'true',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=serverWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverWrapper.js","sourceRoot":"","sources":["../src/serverWrapper.ts"],"names":[],"mappings":"AAUA,MAAM,YAAY,GAAG;;;yEAGoD,CAAC;AAE1E;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACzC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,GAAG,OAAO,GAAG,YAAY,EAAE,CAAC;AACrC,CAAC;AAmBD;;GAEG;AACH,SAAS,2BAA2B,CAClC,IAAoC;IAEpC,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC;IAErC,MAAM,cAAc,GAAG,KAAK,EAAE,IAAa,EAAE,OAAmB,EAAoB,EAAE;QACpF,IAAI,CAAC;YACH,OAAO,MAAO,eAA4E,CACxF,IAAI,EACJ,OAAO,CACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,cAAgD;KAC1D,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAkB,EAClB,MAAoB;IAEpB,gCAAgC;IAChC,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpD,mGAAmG;IACnG,MAAM,CAAC,OAAO,GAAG,UACf,IAAoC;QAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;QAE3D,+CAA+C;QAC/C,IAAI,MAAM,CAAC,QAAQ,IAAI,CAAC,UAAU,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;YAC3B,MAAM,cAAc,GAAG,CAAC,KAAc,EAAE,QAAoB,EAAmB,EAAE;gBAC/E,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,SAAS,QAAQ,sDAAsD;oBACrE,kGAAkG,YAAY,EAAE,CACnH,CACF,CAAC;YACJ,CAAC,CAAC;YAEF,MAAM,WAAW,GAAmC;gBAClD,GAAG,IAAI;gBACP,OAAO,EAAE,cAAqC;gBAC9C,WAAW,EAAE,+BAA+B,IAAI,CAAC,WAAW,IAAI,EAAE,EAAE;aACrE,CAAC;YAEF,eAAe,CAAC,WAAW,CAAC,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,+BAA+B;QAC/B,MAAM,WAAW,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;QACtD,eAAe,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,MAAM;KACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.tools.d.ts","sourceRoot":"","sources":["../../src/tools/accounts.tools.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAajD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,yBAAyB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,QA+K/C"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// accounts.tools.ts - Account management tool module
|
|
2
|
+
import { UserError } from 'fastmcp';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { listAccounts as listAccountsFromRegistry, completeAddAccount, removeAccount as removeAccountFromRegistry, getConfigDir, getCredentialsPath, } from '../accounts.js';
|
|
5
|
+
import { getErrorMessage } from '../errorHelpers.js';
|
|
6
|
+
// Store pending OAuth sessions
|
|
7
|
+
const pendingOAuthSessions = new Map();
|
|
8
|
+
export function registerAccountsTools(server, ensureAccountsInitialized) {
|
|
9
|
+
// --- List Accounts ---
|
|
10
|
+
server.addTool({
|
|
11
|
+
name: 'listAccounts',
|
|
12
|
+
description: 'Lists all configured Google accounts that can be used with this MCP server.',
|
|
13
|
+
parameters: z.object({}),
|
|
14
|
+
annotations: {
|
|
15
|
+
title: 'List Accounts',
|
|
16
|
+
readOnlyHint: true,
|
|
17
|
+
openWorldHint: false,
|
|
18
|
+
},
|
|
19
|
+
execute: async (args, { log }) => {
|
|
20
|
+
log.info('Listing configured accounts');
|
|
21
|
+
await ensureAccountsInitialized();
|
|
22
|
+
try {
|
|
23
|
+
const accounts = await listAccountsFromRegistry();
|
|
24
|
+
if (accounts.length === 0) {
|
|
25
|
+
return `No accounts configured.\n\nTo add an account, use the addAccount tool with a unique name.\n\nCredentials file location: ${getCredentialsPath()}\nConfig directory: ${getConfigDir()}`;
|
|
26
|
+
}
|
|
27
|
+
let result = `**Configured Accounts (${accounts.length}):**\n\n`;
|
|
28
|
+
accounts.forEach((account, index) => {
|
|
29
|
+
result += `${index + 1}. **${account.name}**\n`;
|
|
30
|
+
if (account.email) {
|
|
31
|
+
result += ` Email: ${account.email}\n`;
|
|
32
|
+
}
|
|
33
|
+
result += ` Added: ${account.addedAt}\n\n`;
|
|
34
|
+
});
|
|
35
|
+
result += `\nUse the account name (e.g., "${accounts[0].name}") as the 'account' parameter in other tools.`;
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const message = getErrorMessage(error);
|
|
40
|
+
log.error(`Error listing accounts: ${message}`);
|
|
41
|
+
throw new UserError(`Failed to list accounts: ${message}`);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
// --- Add Account ---
|
|
46
|
+
server.addTool({
|
|
47
|
+
name: 'addAccount',
|
|
48
|
+
description: 'Starts the OAuth flow to add a new Google account. Returns an authorization URL that must be opened in a browser. After authorizing, the account will be added automatically. The account name must be unique and contain only letters, numbers, underscores, and hyphens. Optionally, you can specify a custom credentials file to use a different OAuth app for this account.',
|
|
49
|
+
annotations: {
|
|
50
|
+
title: 'Add Account',
|
|
51
|
+
readOnlyHint: false,
|
|
52
|
+
destructiveHint: false,
|
|
53
|
+
idempotentHint: false,
|
|
54
|
+
openWorldHint: true,
|
|
55
|
+
},
|
|
56
|
+
parameters: z.object({
|
|
57
|
+
name: z
|
|
58
|
+
.string()
|
|
59
|
+
.min(1)
|
|
60
|
+
.regex(/^[a-zA-Z0-9_-]+$/, 'Account name must contain only letters, numbers, underscores, and hyphens')
|
|
61
|
+
.describe('A unique name for this account (e.g., "work", "personal", "client-abc")'),
|
|
62
|
+
credentialsPath: z
|
|
63
|
+
.string()
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('Optional: Path to a custom credentials.json file for this account. Use this to authenticate with a different OAuth app. If not specified, looks for ~/.google-mcp/credentials/{name}.json, then falls back to the global credentials.'),
|
|
66
|
+
}),
|
|
67
|
+
execute: async (args, { log }) => {
|
|
68
|
+
log.info(`Starting OAuth flow for account: ${args.name}${args.credentialsPath ? ` with custom credentials: ${args.credentialsPath}` : ''}`);
|
|
69
|
+
await ensureAccountsInitialized();
|
|
70
|
+
try {
|
|
71
|
+
// Check if account already exists
|
|
72
|
+
const accounts = await listAccountsFromRegistry();
|
|
73
|
+
if (accounts.some((a) => a.name === args.name)) {
|
|
74
|
+
throw new UserError(`Account "${args.name}" already exists. Use removeAccount first if you want to re-add it.`);
|
|
75
|
+
}
|
|
76
|
+
const port = 3000 + Math.floor(Math.random() * 1000);
|
|
77
|
+
// Start the OAuth flow in the background, passing the optional credentials path
|
|
78
|
+
const oauthPromise = completeAddAccount(args.name, port, args.credentialsPath, (authUrl) => {
|
|
79
|
+
// Store the session info
|
|
80
|
+
pendingOAuthSessions.set(args.name, {
|
|
81
|
+
port,
|
|
82
|
+
authUrl,
|
|
83
|
+
resolve: () => { },
|
|
84
|
+
reject: () => { },
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
// Give it a moment to start the server and generate the URL
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
89
|
+
const session = pendingOAuthSessions.get(args.name);
|
|
90
|
+
if (!session) {
|
|
91
|
+
throw new UserError('Failed to start OAuth flow');
|
|
92
|
+
}
|
|
93
|
+
// Set up the promise handlers
|
|
94
|
+
oauthPromise
|
|
95
|
+
.then(() => {
|
|
96
|
+
pendingOAuthSessions.delete(args.name);
|
|
97
|
+
log.info(`OAuth completed for account: ${args.name}`);
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => {
|
|
100
|
+
pendingOAuthSessions.delete(args.name);
|
|
101
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
+
log.error(`OAuth failed for account: ${args.name}: ${message}`);
|
|
103
|
+
});
|
|
104
|
+
let response = `ACTION REQUIRED: Open this URL to authorize account "${args.name}":
|
|
105
|
+
|
|
106
|
+
${session.authUrl}
|
|
107
|
+
|
|
108
|
+
^^^^ COPY AND OPEN THE URL ABOVE IN YOUR BROWSER ^^^^
|
|
109
|
+
|
|
110
|
+
After authorizing, the account will be added automatically. Server listening on port ${port}.`;
|
|
111
|
+
if (args.credentialsPath) {
|
|
112
|
+
response += `\n\nUsing custom credentials: ${args.credentialsPath}`;
|
|
113
|
+
}
|
|
114
|
+
return response;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
const message = getErrorMessage(error);
|
|
118
|
+
log.error(`Error starting OAuth: ${message}`);
|
|
119
|
+
if (error instanceof UserError)
|
|
120
|
+
throw error;
|
|
121
|
+
throw new UserError(`Failed to start OAuth flow: ${message}`);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
// --- Remove Account ---
|
|
126
|
+
server.addTool({
|
|
127
|
+
name: 'removeAccount',
|
|
128
|
+
description: 'Removes a Google account from the MCP server. This deletes the stored credentials for the account.',
|
|
129
|
+
annotations: {
|
|
130
|
+
title: 'Remove Account',
|
|
131
|
+
readOnlyHint: false,
|
|
132
|
+
destructiveHint: true,
|
|
133
|
+
idempotentHint: false,
|
|
134
|
+
openWorldHint: false,
|
|
135
|
+
},
|
|
136
|
+
parameters: z.object({
|
|
137
|
+
name: z.string().min(1).describe('The name of the account to remove'),
|
|
138
|
+
}),
|
|
139
|
+
execute: async (args, { log }) => {
|
|
140
|
+
log.info(`Removing account: ${args.name}`);
|
|
141
|
+
await ensureAccountsInitialized();
|
|
142
|
+
try {
|
|
143
|
+
await removeAccountFromRegistry(args.name);
|
|
144
|
+
return `Successfully removed account "${args.name}".`;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const message = getErrorMessage(error);
|
|
148
|
+
log.error(`Error removing account: ${message}`);
|
|
149
|
+
throw new UserError(`Failed to remove account: ${message}`);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=accounts.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.tools.js","sourceRoot":"","sources":["../../src/tools/accounts.tools.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,YAAY,IAAI,wBAAwB,EACxC,kBAAkB,EAClB,aAAa,IAAI,yBAAyB,EAC1C,YAAY,EACZ,kBAAkB,GAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,+BAA+B;AAC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