@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI Productivity Platform
90 lines • 3.96 kB
JavaScript
/**
* SharePointListConnectionsTool
* List all SharePoint connections available to the user
*/
import { BaseToolController } from '../base/BaseToolController.js';
import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
export class SharePointListConnectionsTool extends BaseToolController {
constructor(ucmClient, logger, publishingAuthorId) {
super(ucmClient, logger, publishingAuthorId);
}
get name() {
return 'ucm_list_connections';
}
get description() {
return 'List all External connections including SharePoint available to the user. Returns connection details, use this to discover available connections before searching or browsing.';
}
get inputSchema() {
return {
type: 'object',
properties: {
limit: {
type: 'number',
description: 'Maximum number of connections to return (default: 20, max: 100)',
minimum: 1,
maximum: 100
},
offset: {
type: 'number',
description: 'Number of connections to skip for pagination (default: 0)',
minimum: 0
}
},
required: []
};
}
validateParams(params) {
super.validateParams(params);
// Validate limit if provided
if (params.limit !== undefined) {
if (typeof params.limit !== 'number' || params.limit < 1 || params.limit > 100) {
throw new McpError(McpErrorCode.InvalidParams, 'Limit must be a number between 1 and 100');
}
}
// Validate offset if provided
if (params.offset !== undefined) {
if (typeof params.offset !== 'number' || params.offset < 0) {
throw new McpError(McpErrorCode.InvalidParams, 'Offset must be a number greater than or equal to 0');
}
}
}
async handleExecute(params) {
this.logger.info('SharePointListConnectionsTool', `Listing SharePoint connections (limit: ${params.limit || 20}, offset: ${params.offset || 0})`);
try {
// Get organizationId from auth ticket (via UcmApiClient)
// Call API to list connections with pagination params
const result = await this.ucmClient.listExternalConnections({
limit: params.limit,
offset: params.offset
});
this.logger.info('listConnections', 'Connections retrieved successfully', '', {
contentLength: result.length,
source: 'UCM API /api/v1/connections'
});
return result;
}
catch (error) {
// Sanitize error for logging to avoid circular reference issues
const sanitizedError = {
message: error?.message,
status: error?.response?.status,
data: error?.response?.data
};
this.logger.error('SharePointListConnectionsTool', 'Failed to list connections', '', sanitizedError);
if (error instanceof McpError) {
throw error;
}
// Handle API errors
if (error.response) {
const status = error.response.status;
const errorData = error.response.data;
if (status === 401 || status === 403) {
throw new McpError(McpErrorCode.InvalidRequest, `Access denied: ${errorData?.message || 'Not authorized to list SharePoint connections'}`);
}
throw new McpError(McpErrorCode.InternalError, `API error: ${errorData?.message || error.message}`);
}
throw new McpError(McpErrorCode.InternalError, `Failed to list external connections: ${error.message}`);
}
}
}
//# sourceMappingURL=SharePointListConnectionsTool.js.map