UNPKG

dbx-mcp-server

Version:

A Model Context Protocol server for Dropbox integration with AI-powered PDF analysis, multi-directory indexing, and parallel processing

68 lines 2.77 kB
import { Dropbox } from 'dropbox'; import { getValidAccessToken } from '../auth.js'; import { config, log } from '../config.js'; import { getCachedTeamConfig, getCachedBusinessUserId, shouldUseTeamSpace } from './team-config.js'; // Get a Dropbox client with proper team space configuration export async function getDropboxClient(options) { const token = config.dropbox.accessToken || await getValidAccessToken(); // Get team configuration and business user ID const [teamConfig, businessUserId] = await Promise.all([ getCachedTeamConfig(), getCachedBusinessUserId() ]); // Determine if we should use team space const useTeamSpace = options?.forceTeamSpace || (options?.useTeamSpace ?? (teamConfig?.hasTeamSpace || false)); // Create client configuration const clientConfig = { accessToken: token, selectUser: process.env.DROPBOX_BUSINESS_USER_ID || businessUserId || undefined }; // TEAM SPACE ACCESS: Configure pathRoot for work directory (/work/...) access if (useTeamSpace) { let namespaceId = teamConfig?.teamSpaceId; let pathRootConfig; if (namespaceId) { pathRootConfig = { ".tag": "root", "root": namespaceId }; } else { // Fallback: use root namespace (should point to team space root when team space is enabled) pathRootConfig = { ".tag": "root" }; } clientConfig.pathRoot = pathRootConfig; log.info('Using team space pathRoot for work directory access', { teamSpaceNamespaceId: namespaceId, teamId: teamConfig?.teamId, teamName: teamConfig?.teamName, businessUserId, selectUser: clientConfig.selectUser, pathRoot: clientConfig.pathRoot }); } else if (businessUserId) { log.info('Using business user member folder scope for API calls', { businessUserId }); } else { log.info('Using personal account scope for API calls'); } const client = new Dropbox(clientConfig); return client; } // Get a Dropbox client with automatic team space detection based on path export async function getDropboxClientForPath(path) { const teamConfig = await getCachedTeamConfig(); const useTeamSpace = shouldUseTeamSpace(path, teamConfig); log.debug('Path-based client selection', { path, useTeamSpace, hasTeamSpace: teamConfig?.hasTeamSpace }); return getDropboxClient({ useTeamSpace }); } // Helper function to format paths for Dropbox API export function formatDropboxPath(path) { if (!path || path === '/') return ''; return '/' + path.replace(/^\/+|\/+$/g, ''); } //# sourceMappingURL=client-factory.js.map