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.

89 lines (88 loc) 3.02 kB
import { z } from "zod"; export function getWorkspaceTools(server, api) { // Tool: Get Workspaces server.tool("get_workspaces", "Retrieves my Workspaces", {}, async ({}) => { try { console.info("Getting workspaces"); const workspace = await api.workspaces.getWorkspaces(); return { content: [ { type: "text", text: JSON.stringify(workspace, null, 2) } ] }; } catch (error) { console.error("Failed to get workspaces", { error }); return { content: [ { type: "text", text: `Failed to get workspaces: ${error.message}` } ], isError: true }; } }); // Tool: Get Workspace server.tool("get_workspace", "Retrieves the current state of a Workspace, including its contents which can be sheets, reports, or other folders", { workspaceId: z.string().describe("The ID of the workspace to retrieve") }, async ({ workspaceId }) => { try { console.info(`Getting workspace with ID: ${workspaceId}`); const workspace = await api.workspaces.getWorkspace(workspaceId); return { content: [ { type: "text", text: JSON.stringify(workspace, null, 2) } ] }; } catch (error) { console.error(`Failed to get workspace with ID: ${workspaceId}`, { error }); return { content: [ { type: "text", text: `Failed to get workspace: ${error.message}` } ], isError: true }; } }); // Tool: Create workspace server.tool("create_workspace", "Creates a new workspace", { workspaceName: z.string().describe("The name of the new workspace") }, async ({ workspaceName }) => { try { console.info(`Creating workspace: ${workspaceName}`); const workspace = await api.workspaces.createWorkspace(workspaceName); return { content: [ { type: "text", text: JSON.stringify(workspace, null, 2) } ] }; } catch (error) { console.error("Failed to create workspace", { error }); return { content: [ { type: "text", text: `Failed to create_workspace: ${error.message}` } ], isError: true }; } }); }