@utaba/ucm-mcp-server
Version:
Universal Context Manager MCP Server - AI Productivity Platform
125 lines • 5.27 kB
JavaScript
/**
* SharePointSearchTool
* Search SharePoint documents with text query
*/
import { BaseToolController } from '../base/BaseToolController.js';
import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
import { SharePointErrorHandler } from '../../utils/SharePointErrorHandler.js';
export class SharePointSearchTool extends BaseToolController {
constructor(ucmClient, logger, publishingAuthorId) {
super(ucmClient, logger, publishingAuthorId);
}
get name() {
return 'ucm_sharepoint_search_documents';
}
get description() {
return 'Search SharePoint documents with text query using Microsoft Search API. Returns document metadata with snippets. Supports pagination and file type filtering via KQL.';
}
get inputSchema() {
return {
type: 'object',
properties: {
connectionId: {
type: 'string',
description: 'SharePoint connection ID to use for searching (get this from list_connections)',
minLength: 36,
maxLength: 36
},
query: {
type: 'string',
description: 'Search query text (optional, defaults to * for all documents)',
maxLength: 500
},
limit: {
type: 'number',
description: 'Maximum number of results to return (default: 20, max: 100)',
minimum: 1,
maximum: 100
},
offset: {
type: 'number',
description: 'Number of results to skip for pagination (default: 0)',
minimum: 0
},
fileType: {
type: 'string',
description: 'Filter by file extension (e.g., "docx", "pdf", "xlsx") - uses Microsoft Search KQL filtering',
maxLength: 10
}
},
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');
}
// Validate query
if (!params.query || typeof params.query !== 'string' || params.query.trim() === '') {
params.query = '*';
}
// Validate and set default limit
if (params.limit !== undefined) {
if (typeof params.limit !== 'number' || params.limit < 1 || params.limit > 100) {
throw new McpError(McpErrorCode.InvalidParams, 'Limit must be between 1 and 100');
}
}
else {
params.limit = 20;
}
// 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;
}
// Validate file type if provided (now supported via Microsoft Search API KQL)
if (params.fileType && !/^[a-zA-Z0-9]{1,10}$/.test(params.fileType)) {
throw new McpError(McpErrorCode.InvalidParams, 'File type must be alphanumeric and no more than 10 characters');
}
}
async handleExecute(params) {
this.logger.info('SharePointSearchTool', `Searching SharePoint with query: "${params.query}"`);
try {
// Call the API to search SharePoint documents
const searchParams = {
query: params.query,
limit: params.limit,
offset: params.offset,
fileType: params.fileType
};
// Make API call via UCM client
const result = await this.ucmClient.sharePointSearch(params.connectionId, searchParams);
this.logger.info('SharePointSearchTool', `Search completed, found ${result.totalCount} results`);
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
query: params.query,
totalCount: result.totalCount,
returnedCount: result.files?.length || 0,
hasMore: result.hasMore,
limit: params.limit,
offset: params.offset,
fileType: params.fileType,
files: result.files || []
}, null, 2)
}
]
};
}
catch (error) {
return SharePointErrorHandler.handle(error, this.logger, 'SharePointSearchTool');
}
}
}
//# sourceMappingURL=SharePointSearchTool.js.map