(params: UserTableArgs, context?: ServerToolContext)
| 331 | export 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 |
nothing calls this directly
no test coverage detected