MCPcopy Index your code
hub / github.com/simstudioai/sim / execute

Function execute

apps/sim/lib/copilot/tools/server/table/user-table.ts:333–2051  ·  view source on GitHub ↗
(params: UserTableArgs, context?: ServerToolContext)

Source from the content-addressed store, hash-verified

331export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult> = {
332 name: UserTable.id,
333 async execute(params: UserTableArgs, context?: ServerToolContext): Promise<UserTableResult> {
334 const withMessageId = (message: string) =>
335 context?.messageId ? `${message} [messageId:${context.messageId}]` : message
336
337 if (!context?.userId) {
338 logger.error('Unauthorized attempt to access user table - no authenticated user context')
339 throw new Error('Authentication required')
340 }
341
342 const { operation, args = {} } = params
343 const workspaceId =
344 context.workspaceId || ((args as Record<string, unknown>).workspaceId as string | undefined)
345 const assertNotAborted = () =>
346 assertServerToolNotAborted(context, 'Request aborted before table mutation could be applied.')
347
348 try {
349 switch (operation) {
350 case 'create': {
351 if (!args.name) {
352 return { success: false, message: 'Name is required for creating a table' }
353 }
354 if (!args.schema) {
355 return { success: false, message: 'Schema is required for creating a table' }
356 }
357 if (!workspaceId) {
358 return { success: false, message: 'Workspace ID is required' }
359 }
360
361 const requestId = generateId().slice(0, 8)
362 assertNotAborted()
363 const planLimits = await getWorkspaceTableLimits(workspaceId)
364 const table = await createTable(
365 {
366 name: args.name,
367 description: args.description,
368 schema: args.schema,
369 workspaceId,
370 userId: context.userId,
371 maxTables: planLimits.maxTables,
372 },
373 requestId
374 )
375
376 return {
377 success: true,
378 message: `Created table "${table.name}" (${table.id})`,
379 data: { table },
380 }
381 }
382
383 case 'get': {
384 if (!args.tableId) {
385 return { success: false, message: 'Table ID is required' }
386 }
387 if (!workspaceId) {
388 return { success: false, message: 'Workspace ID is required' }
389 }
390

Callers

nothing calls this directly

Calls 15

generateIdFunction · 0.90
getWorkspaceTableLimitsFunction · 0.90
createTableFunction · 0.90
getTableByIdFunction · 0.90
deleteTableFunction · 0.90
buildIdByNameFunction · 0.90
buildNameByIdFunction · 0.90
insertRowFunction · 0.90
rowDataNameToIdFunction · 0.90
rowDataIdToNameFunction · 0.90
batchInsertRowsFunction · 0.90
getRowByIdFunction · 0.90

Tested by

no test coverage detected