@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI Productivity Platform
133 lines • 5.66 kB
JavaScript
/**
* SharePointListFoldersTool
* List folders in SharePoint document library
*/
import { BaseToolController } from '../base/BaseToolController.js';
import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
import { SharePointErrorHandler } from '../../utils/SharePointErrorHandler.js';
export class SharePointListFoldersTool extends BaseToolController {
constructor(ucmClient, logger, publishingAuthorId) {
super(ucmClient, logger, publishingAuthorId);
}
get name() {
return 'ucm_sharepoint_list_folders';
}
get description() {
return 'Browse SharePoint hierarchically: "/" lists document libraries, "/LibraryName" lists library root, "/LibraryName/Folder" lists subfolder. Supports pagination. Use ucm_list_connections first to get connection ID.';
}
get inputSchema() {
return {
type: 'object',
properties: {
connectionId: {
type: 'string',
description: 'SharePoint connection ID to use for listing folders (get this from list_connections)',
minLength: 36,
maxLength: 36
},
folderPath: {
type: 'string',
description: 'Path: "/" = list libraries (e.g., Documents, Sales), "/Documents" = list library root, "/Documents/Projects" = list subfolder. Default: "/"',
maxLength: 1000
},
limit: {
type: 'number',
description: 'Maximum number of items to return (default: 50, max: 200)',
minimum: 1,
maximum: 200
},
offset: {
type: 'number',
description: 'Number of items to skip for pagination (default: 0)',
minimum: 0
}
},
required: ['connectionId'],
additionalProperties: false
};
}
validateParams(params) {
super.validateParams(params);
// Validate connectionId is UUID format
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (!uuidPattern.test(params.connectionId)) {
throw new McpError(McpErrorCode.InvalidParams, 'Connection ID must be a valid UUID');
}
// Set default folder path if not provided
if (!params.folderPath) {
params.folderPath = '/';
}
// Validate folder path format
if (params.folderPath && typeof params.folderPath !== 'string') {
throw new McpError(McpErrorCode.InvalidParams, 'Folder path must be a string');
}
// Ensure folder path starts with /
if (params.folderPath && !params.folderPath.startsWith('/')) {
params.folderPath = '/' + params.folderPath;
}
// Validate and set default limit
if (params.limit !== undefined) {
if (typeof params.limit !== 'number' || params.limit < 1 || params.limit > 200) {
throw new McpError(McpErrorCode.InvalidParams, 'Limit must be between 1 and 200');
}
}
else {
params.limit = 50;
}
// Validate and set default offset
if (params.offset !== undefined) {
if (typeof params.offset !== 'number' || params.offset < 0) {
throw new McpError(McpErrorCode.InvalidParams, 'Offset must be 0 or greater');
}
}
else {
params.offset = 0;
}
}
async handleExecute(params) {
this.logger.info('SharePointListFoldersTool', `Listing folders at path: ${params.folderPath}`);
try {
// Call the API to list SharePoint folders
// organizationId is auto-detected from auth token in V1 API
const listParams = {
folderPath: params.folderPath,
limit: params.limit,
offset: params.offset
};
// Make API call via UCM client (V1 API)
const result = await this.ucmClient.sharePointListFolders(params.connectionId, listParams);
this.logger.info('SharePointListFoldersTool', `Listed ${result.folders?.length || 0} folders and ${result.files?.length || 0} files`);
// Format response from V1 API
const response = {
success: true,
path: result.path || params.folderPath,
totalFolders: result.totalFolders || 0,
totalFiles: result.totalFiles || 0,
total: result.total || 0,
hasMore: result.hasMore || false,
limit: params.limit,
offset: params.offset,
folders: result.folders?.map((folder) => ({
name: folder.name,
webUrl: folder.webUrl,
size: folder.size,
createdDateTime: folder.createdDateTime,
lastModifiedDateTime: folder.lastModifiedDateTime
})) || [],
files: result.files || []
};
return {
content: [
{
type: 'text',
text: JSON.stringify(response, null, 2)
}
]
};
}
catch (error) {
return SharePointErrorHandler.handle(error, this.logger, 'SharePointListFoldersTool');
}
}
}
//# sourceMappingURL=SharePointListFoldersTool.js.map