// Account tools - provides account information for multi-account support
import { z } from 'zod';
import type { DriveService } from '../services/drive.js';
import { getAccountId } from '../auth/index.js';
// Tool definitions for MCP
export const accountTools = [
{
name: 'getAccountInfo',
description: 'Get information about the current Google account (account ID, email, storage quota)',
inputSchema: {
type: 'object' as const,
properties: {},
required: [],
},
},
];
// Schema for validation (empty - no parameters needed)
export const GetAccountInfoSchema = z.object({});
// Handler factory
export function createAccountHandlers(driveService: DriveService) {
return {
getAccountInfo: async (_args: z.infer<typeof GetAccountInfoSchema>) => {
const accountId = getAccountId() || 'default';
// Get user info and storage quota from Drive API
const about = await driveService.getAbout();
return {
accountId,
email: about.user?.emailAddress || 'unknown',
displayName: about.user?.displayName || 'unknown',
storageQuota: about.storageQuota
? {
limit: formatBytes(Number(about.storageQuota.limit)),
usage: formatBytes(Number(about.storageQuota.usage)),
usageInDrive: formatBytes(Number(about.storageQuota.usageInDrive)),
usageInDriveTrash: formatBytes(Number(about.storageQuota.usageInDriveTrash)),
}
: null,
};
},
};
}
// Helper to format bytes to human readable
function formatBytes(bytes: number): string {
if (!bytes || isNaN(bytes)) return '0 B';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let unitIndex = 0;
let value = bytes;
while (value >= 1024 && unitIndex < units.length - 1) {
value /= 1024;
unitIndex++;
}
return `${value.toFixed(2)} ${units[unitIndex]}`;
}