@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.
86 lines (85 loc) • 2.62 kB
JavaScript
import { z } from "zod";
export function getUserTools(server, api) {
// Tool: Get Current User
server.tool("get_current_user", "Gets the current user's information", async () => {
try {
console.info("Getting current user");
const user = await api.users.getCurrentUser();
return {
content: [
{
type: "text",
text: JSON.stringify(user, null, 2)
}
]
};
}
catch (error) {
console.error("Failed to get current user", { error });
return {
content: [
{
type: "text",
text: `Failed to get current user: ${error.message}`
}
],
isError: true
};
}
});
// Tool: Get User
server.tool("get_user", "Gets a user's information by ID", {
userId: z.string().describe("ID of the user to get")
}, async ({ userId }) => {
try {
console.info(`Getting user with ID: ${userId}`);
const user = await api.users.getUserById(userId);
return {
content: [
{
type: "text",
text: JSON.stringify(user, null, 2)
}
]
};
}
catch (error) {
console.error("Failed to get user", { error });
return {
content: [
{
type: "text",
text: `Failed to get user: ${error.message}`
}
],
isError: true
};
}
});
server.tool("list_users", "Lists all users", async () => {
try {
console.info("Listing all users");
const users = await api.users.listUsers();
return {
content: [
{
type: "text",
text: JSON.stringify(users, null, 2)
}
]
};
}
catch (error) {
console.error("Failed to list users", { error });
return {
content: [
{
type: "text",
text: `Failed to list users: ${error.message}`
}
],
isError: true
};
}
});
}