UNPKG

@smartsheet/smar-mcp

Version:

A Model Context Protocol (MCP) server for interacting with the Smartsheet API. This server provides tools for searching, retrieving, and updating Smartsheet sheets through the MCP protocol.

166 lines (165 loc) 5.78 kB
/** * Sheet-specific API methods for Smartsheet */ export class SmartsheetSheetAPI { api; constructor(api) { this.api = api; } /** * Gets a sheet by ID * @param sheetId Sheet ID * @param include Optional comma-separated list of elements to include * @returns Sheet data */ async getSheet(sheetId, include, exclude, pageSize, page) { return this.api.request('GET', `/sheets/${sheetId}`, undefined, { include, exclude, pageSize, page }); } /** * Gets a sheet by directIdToken * @param directIdToken Sheet directIdToken * @param include Optional comma-separated list of elements to include * @returns Sheet data */ async getSheetByDirectIdToken(directIdToken, include, exclude, pageSize, page) { return this.api.request('GET', `/sheets/${directIdToken}`, undefined, { include, exclude, pageSize, page }); } /** * Gets the version of a sheet * @param sheetId Sheet ID * @returns Sheet version */ async getSheetVersion(sheetId) { return this.api.request('GET', `/sheets/${sheetId}/version`); } /** * Gets the history of a specific cell * @param sheetId Sheet ID * @param rowId Row ID * @param columnId Column ID * @param include Optional parameter to include additional information * @param pageSize Number of history entries to return per page * @param page Page number to return * @returns Cell history */ async getCellHistory(sheetId, rowId, columnId, include, pageSize, page) { return this.api.request('GET', `/sheets/${sheetId}/rows/${rowId}/columns/${columnId}/history`, undefined, { include, pageSize, page }); } /** * Get Row * @param sheetId Sheet ID * @param rowId Row ID * @param include Optional comma-separated list of elements to include * @returns Row data */ async getRow(sheetId, rowId, include, exclude) { return this.api.request('GET', `/sheets/${sheetId}/rows/${rowId}`, undefined, { include, exclude }); } /** * Updates rows in a sheet * @param sheetId Sheet ID * @param rows Array of row objects to update * @returns Update result */ async updateRows(sheetId, rows) { return this.api.request('PUT', `/sheets/${sheetId}/rows`, rows); } /** * Adds rows to a sheet * @param sheetId Sheet ID * @param rows Array of row objects to add * @returns Add result */ async addRows(sheetId, rows) { return this.api.request('POST', `/sheets/${sheetId}/rows`, rows); } /** * Deletes rows from a sheet * @param sheetId Sheet ID * @param rowIds Array of row IDs to delete * @param ignoreRowsNotFound Whether to ignore rows that don't exist * @returns Delete result */ async deleteRows(sheetId, rowIds, ignoreRowsNotFound = true) { return this.api.request('DELETE', `/sheets/${sheetId}/rows`, undefined, { ids: rowIds.join(','), ignoreRowsNotFound: ignoreRowsNotFound.toString() }); } /** * Gets the location information for a sheet * @param sheetId Sheet ID * @returns Location information including folder ID */ async getSheetLocation(sheetId) { const sheet = await this.getSheet(sheetId); return { folderId: sheet.parentId, folderType: sheet.parentType, workspaceId: sheet.workspaceId }; } /** * Creates a copy of a sheet * @param sheetId Sheet ID to copy * @param destinationName Name for the new sheet * @param destinationFolderId Optional folder ID for the new sheet * @param workspaceId Optional workspace ID for the new sheet * @returns New sheet data */ async copySheet(sheetId, destinationName, destinationFolderId, workspaceId) { const data = { newName: destinationName }; if (destinationFolderId) { data.destinationType = 'folder'; data.destinationId = destinationFolderId; console.debug(`Copying sheet to folder: ${destinationFolderId}`); } else if (workspaceId) { data.destinationType = 'workspace'; data.destinationId = workspaceId; console.debug(`Copying sheet to workspace: ${workspaceId}`); } else { // Default to 'home' if no folder or workspace specified data.destinationType = 'home'; console.debug("Copying sheet to home"); } const result = await this.api.request('POST', `/sheets/${sheetId}/copy`, data); console.info(`Copy sheet result: ${JSON.stringify(result.result?.id)}`); return result; } /** * Creates a new sheet * @param name Name for the new sheet * @param columns Array of column objects * @param folderId Optional folder ID where the sheet should be created * @returns New sheet data */ async createSheet(name, columns, folderId) { const data = { name, columns }; let endpoint = '/sheets'; // If folder ID is provided, create in that folder if (folderId) { endpoint = `/folders/${folderId}/sheets`; } return this.api.request('POST', endpoint, data); } /** * Creates an update request for a sheet * @param sheetId Sheet ID * @param options Update request options * @returns Created update request data */ async createUpdateRequest(sheetId, options) { return this.api.request('POST', `/sheets/${sheetId}/updaterequests`, options); } }