feat: move MCP to /mcp and add teammate operations (#500)

* feat(operations): move MCP to /mcp and add search, comment, metadata, version, and upload operations

- Serve the MCP server at /mcp instead of /api/mcp
- Add search_assets, copy_assets, get_folder_instructions, list_comments,
  create_comment, resolve_comment, list_metadata_fields,
  update_asset_metadata, create_version_stack, list_versions, and
  remove_version on the agent, MCP, and CLI
- Add create_file and create_version (agent, MCP) with Creation Context
  metadata, and complete_upload (MCP) for presigned two-step uploads
- Replace the native agent create_file/create_version tools with
  Operation-backed ones
- Route the comment-complete, metadata, copy, version stack, and
  AGENTS.md read REST endpoints through their Operations

* docs(readme): add built-in MCP server and CLI to features list
This commit is contained in:
Yiling-J
2026-10-27 14:37:26 +08:00
committed by GitHub
parent 50fbd97953
commit b3cae4f2b0
81 changed files with 4111 additions and 1397 deletions
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const copyAssets = defineOperation({
name: 'copy_assets',
title: 'Copy Assets',
description:
'Copy one or more files or folders (with everything inside them) into a folder of the ' +
'same team, e.g. into another project. The originals are left unchanged. Returns the IDs ' +
'of the copies, in the same order as assetIds.',
input: z.object({
assetIds: z
.array(z.string().min(1))
.min(1)
.describe('The IDs of the files or folders to copy. At least one asset ID is required.'),
newParentId: z.string().min(1).describe('The destination folder ID to copy the assets into.'),
withComments: z
.boolean()
.optional()
.describe('Also copy the comments on the files (default false).'),
}),
output: z.object({
copiedAssetIds: z.array(z.string()).describe('IDs of the copies, in the order of assetIds.'),
newParentId: z.string(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false },
cli: {
command: ['copy'],
aliases: ['cp'],
positional: ['assetIds'],
flags: { newParentId: ['-p', '--parent'] },
format: (output) =>
`Copied ${output.copiedAssetIds.length} asset(s) to parent ${output.newParentId}: ${output.copiedAssetIds.join(', ')}`,
},
})
@@ -0,0 +1,26 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const getFolderInstructions = defineOperation({
name: 'get_folder_instructions',
title: 'Get Folder Instructions',
description:
"Read a folder's instructions for AI agents (its AGENTS.md): conventions such as naming " +
'rules, deliverable specs, or how the team reviews work in that folder. Check them before ' +
'adding or changing files in a folder. Returns null content when the folder has none.',
input: z.object({
folderId: z.string().min(1).describe("The folder ID (e.g. a project's rootFolderId)."),
}),
output: z.object({
folderId: z.string(),
content: z.string().nullable().describe('The instructions (Markdown), or null when unset.'),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['instructions'],
description: "Show a folder's instructions for AI agents (AGENTS.md).",
positional: ['folderId'],
format: (output) => output.content ?? '(This folder has no instructions.)',
},
})
@@ -0,0 +1,116 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema, MAX_PAGE_SIZE, pageInfoSchema } from '../schemas'
/** Operators the search supports (`is` in the web app's list has no search behavior). */
export const SEARCH_CONDITION_OPERATORS = [
'eq',
'neq',
'gt',
'gte',
'lt',
'lte',
'contains',
'notContains',
'isEmpty',
'isNotEmpty',
'in',
'notIn',
'hasAny',
'hasAll',
'hasNone',
'isWithin',
] as const
const conditionSchema = z.object({
field: z
.string()
.min(1)
.describe(
'Metadata field key from list_metadata_fields (e.g. "status"), or one of "name", ' +
'"sizeByte", "createdAt", "updatedAt".',
),
operator: z
.enum(SEARCH_CONDITION_OPERATORS)
.describe(
'Comparison: eq/neq for exact values (text, toggle, or a select option id), ' +
'gt/gte/lt/lte for numbers and dates, contains/notContains for text, in/notIn for ' +
'one of a list, hasAny/hasAll/hasNone for selectMulti fields, isWithin for a date ' +
'range, isEmpty/isNotEmpty (no value needed).',
),
value: z
.union([z.string(), z.number(), z.boolean(), z.array(z.string())])
.optional()
.describe(
'Value to compare with. For select fields use option IDs from list_metadata_fields; ' +
'for in/notIn/hasAny/hasAll/hasNone pass a list.',
),
})
export const searchAssets = defineOperation({
name: 'search_assets',
title: 'Search Assets',
description:
'Search for files (or folders) under a folder and all of its subfolders, by name, by ' +
'meaning ("semantic": e.g. "sunset over the sea", when the team has AI search enabled), ' +
'and/or by metadata conditions (e.g. status is "approved"). Results are paginated: when ' +
'pageInfo.hasNextPage is true, call again with after set to pageInfo.endCursor.',
input: z.object({
parent: z
.string()
.min(1)
.describe("The folder to search in, e.g. a project's rootFolderId to search everything."),
query: z.string().optional().describe('Text to search for in names (or by meaning).'),
semantic: z
.boolean()
.optional()
.describe(
'Search by meaning instead of by name (default false). Needs a query and AI search ' +
'enabled for the team.',
),
type: z
.enum(['file', 'folder'])
.optional()
.describe("Search 'file' (default; includes version stacks) or 'folder'."),
recursive: z
.boolean()
.optional()
.describe('Search subfolders too (default true). Set false for the folder itself only.'),
conditions: z
.array(conditionSchema)
.optional()
.describe('Metadata filters. Combined with AND unless matchAny is true.'),
matchAny: z
.boolean()
.optional()
.describe('Match assets meeting any condition instead of all of them (default false).'),
first: z
.number()
.int()
.min(1)
.max(MAX_PAGE_SIZE)
.optional()
.describe(`Maximum number of results to return (at most ${MAX_PAGE_SIZE}).`),
after: z
.string()
.optional()
.describe('Cursor from a previous response (pageInfo.endCursor) to fetch the next page.'),
}),
output: z.object({
data: z.array(assetSummarySchema),
pageInfo: pageInfoSchema,
total: z.number(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['search'],
description: 'Search for files under a folder by name or by meaning (--semantic).',
positional: ['query'],
flags: { parent: ['-p', '--parent'] },
// Metadata conditions are structured; agents pass them, the CLI searches by name. The CLI
// always searches subfolders (a boolean flag could only turn on the default).
omit: ['conditions', 'matchAny', 'recursive'],
defaults: { first: MAX_PAGE_SIZE },
},
})
@@ -0,0 +1,40 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const createComment = defineOperation({
name: 'create_comment',
title: 'Create Comment',
description:
'Post a review comment on a file, or reply to an existing comment thread. The comment is ' +
'posted as you, and the people involved are notified. For a video or audio file, set ' +
'"second" to pin the comment to a timecode. For a version stack, the comment goes on its ' +
'latest version.',
input: z.object({
assetId: z.string().min(1).describe('The file or version stack to comment on.'),
message: z.string().trim().min(1).max(10_000).describe('The comment text.'),
replyToId: z
.string()
.min(1)
.optional()
.describe('ID of the comment to reply to (from list_comments). Omit for a new thread.'),
second: z
.number()
.min(0)
.optional()
.describe('Timecode in seconds on a video or audio file. Omit for other files.'),
}),
output: z.object({
id: z.string().describe('The new comment ID.'),
assetId: z.string().describe('The file the comment is on (the latest version for a stack).'),
replyToId: z.string().nullable().describe('The thread it replies to, if any.'),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false },
cli: {
command: ['comment', 'add'],
description: 'Comment on a file, or reply to a comment with --reply-to.',
positional: ['assetId', 'message'],
flags: { replyToId: ['--reply-to'], second: ['-t', '--at'] },
format: (output) => `Posted comment ${output.id}`,
},
})
@@ -0,0 +1,79 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { MAX_PAGE_SIZE, pageInfoSchema } from '../schemas'
const commentAuthorSchema = z.object({
id: z.string(),
name: z.string(),
})
const commentFields = {
id: z.string(),
message: z.string(),
author: commentAuthorSchema,
/** Timecode in seconds on a video or audio file (the viewing angle for 3D models). */
second: z.number().nullable(),
/** Whether markup was drawn on the frame or page. */
hasMarkup: z.boolean(),
attachmentCount: z.number(),
createdAt: z.string(),
}
export const commentReplySchema = z.object(commentFields)
export const commentThreadSchema = z.object({
...commentFields,
resolved: z.boolean(),
replies: z.array(commentReplySchema),
})
export type CommentThread = z.infer<typeof commentThreadSchema>
export const listComments = defineOperation({
name: 'list_comments',
title: 'List Comments',
description:
'List the review comments on a file, oldest first, each with its replies. For a version ' +
'stack, lists the comments on its latest version. "second" is the timecode on a video or ' +
'audio file. Results are paginated: when pageInfo.hasNextPage is true, call again with ' +
'after set to pageInfo.endCursor.',
input: z.object({
assetId: z.string().min(1).describe('The file or version stack ID.'),
first: z
.number()
.int()
.min(1)
.max(MAX_PAGE_SIZE)
.optional()
.describe(`Maximum number of comment threads to return (at most ${MAX_PAGE_SIZE}).`),
after: z
.string()
.optional()
.describe('Cursor from a previous response (pageInfo.endCursor) to fetch the next page.'),
}),
output: z.object({
data: z.array(commentThreadSchema),
pageInfo: pageInfoSchema,
total: z.number(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['comment', 'ls'],
description: 'List the comments on a file, with their replies.',
positional: ['assetId'],
defaults: { first: MAX_PAGE_SIZE },
format: (output) => {
if (output.data.length === 0) return 'No comments.'
const lines: string[] = []
for (const thread of output.data) {
const at = thread.second !== null ? ` @${thread.second}s` : ''
const status = thread.resolved ? ' [resolved]' : ''
lines.push(`${thread.id}${at}${status} ${thread.author.name}: ${thread.message}`)
for (const reply of thread.replies) {
lines.push(` ↳ ${reply.id} ${reply.author.name}: ${reply.message}`)
}
}
return lines.join('\n')
},
},
})
@@ -0,0 +1,30 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const resolveComment = defineOperation({
name: 'resolve_comment',
title: 'Resolve Comment',
description:
'Mark a comment thread as resolved (done), e.g. after addressing the feedback in a new ' +
'version. Set reopen to true to mark it as unresolved again.',
input: z.object({
commentId: z.string().min(1).describe('The comment ID (from list_comments).'),
reopen: z
.boolean()
.optional()
.describe('Mark the comment as unresolved again instead (default false).'),
}),
output: z.object({
commentId: z.string(),
resolved: z.boolean(),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['comment', 'resolve'],
description: 'Mark a comment as resolved, or unresolved again with --reopen.',
positional: ['commentId'],
format: (output) =>
`Comment ${output.commentId} is ${output.resolved ? 'resolved' : 'unresolved'}`,
},
})
+14
View File
@@ -2,11 +2,25 @@ export * from './define'
export * from './schemas'
export * from './registry'
export { dropNullOptionals } from './null-optionals'
export { copyAssets } from './asset/copy-assets'
export { createFolder } from './asset/create-folder'
export { deleteAsset } from './asset/delete-asset'
export { getFolderInstructions } from './asset/get-folder-instructions'
export { listAssets } from './asset/list-assets'
export { moveAssets } from './asset/move-assets'
export { renameAsset } from './asset/rename-asset'
export * from './asset/search-assets'
export * from './asset/read-asset'
export * from './asset/download-asset'
export * from './comment/list-comments'
export { createComment } from './comment/create-comment'
export { resolveComment } from './comment/resolve-comment'
export * from './metadata/list-metadata-fields'
export * from './metadata/update-asset-metadata'
export { listProjects } from './project/list-projects'
export * from './upload/create-file'
export { createVersion } from './upload/create-version'
export { completeUpload } from './upload/complete-upload'
export { createVersionStack } from './version/create-version-stack'
export * from './version/list-versions'
export { removeVersion } from './version/remove-version'
@@ -0,0 +1,68 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const METADATA_FIELD_TYPES = [
'text',
'longText',
'select',
'selectMulti',
'rating',
'number',
'toggle',
'date',
'user',
'userMulti',
] as const
export const metadataFieldSchema = z.object({
key: z.string().describe('Key to use in update_asset_metadata, search_assets, and metadata.'),
name: z.string(),
type: z.string().describe(`One of: ${METADATA_FIELD_TYPES.join(', ')}.`),
description: z.string(),
readOnly: z.boolean().describe('Set by Shumai; cannot be changed.'),
creationContext: z
.boolean()
.describe(
'A Creation Context field: whoever creates a file records it (e.g. the prompt or model ' +
'used), through the metadata of create_file and create_version.',
),
options: z
.array(z.object({ id: z.string(), name: z.string() }))
.optional()
.describe('Choices of a select or selectMulti field: values use the option id.'),
})
export type MetadataFieldSummary = z.infer<typeof metadataFieldSchema>
export const listMetadataFields = defineOperation({
name: 'list_metadata_fields',
title: 'List Metadata Fields',
description:
"List a project's metadata fields (e.g. status, rating, tags, custom fields), with their " +
'type and choices. Use the keys with update_asset_metadata, as search_assets conditions, ' +
'and for the Creation Context metadata of create_file and create_version.',
input: z.object({
projectId: z.string().min(1).describe('The project ID (from list_projects).'),
}),
output: z.object({
fields: z.array(metadataFieldSchema),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['field', 'ls'],
description: "List a project's metadata fields.",
positional: ['projectId'],
format: (output) =>
output.fields
.map((f) => {
const flags = [f.type, f.readOnly ? 'read-only' : '', f.creationContext ? 'creation' : '']
.filter(Boolean)
.join(', ')
const options = f.options?.length
? ` [${f.options.map((o) => `${o.id}=${o.name}`).join(', ')}]`
: ''
return `${f.key} ${f.name} (${flags})${options}`
})
.join('\n'),
},
})
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineOperation } from '../define'
/** Describes metadata values; shared with the Creation Context metadata of uploads. */
export const METADATA_VALUES_DESCRIPTION =
'Values keyed by field key (from list_metadata_fields). Text fields take a string, ' +
'number and rating fields a number, toggle fields a boolean, date fields an ISO date ' +
'string, select fields an option id, and selectMulti fields a list of option ids. To add a ' +
'new choice to a select field, pass {"newOption": {"value": "Name"}} instead of an id. ' +
'Use null to clear a value.'
export const updateAssetMetadata = defineOperation({
name: 'update_asset_metadata',
title: 'Update Asset Metadata',
description:
'Set metadata values on a file, e.g. its status, rating, tags, or custom fields. Only the ' +
'given fields change. Call list_metadata_fields first to get the field keys and choices. ' +
'For a version stack, the values are set on its latest version.',
input: z.object({
assetId: z.string().min(1).describe('The file or version stack ID.'),
values: z.record(z.string(), z.unknown()).describe(METADATA_VALUES_DESCRIPTION),
}),
output: z.object({
assetId: z.string(),
updatedKeys: z.array(z.string()),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['meta', 'set'],
description:
'Set metadata values on a file, as JSON keyed by field key, e.g. --values \'{"status":"approved"}\'.',
positional: ['assetId'],
format: (output) => `Updated ${output.updatedKeys.join(', ')} on ${output.assetId}`,
},
})
+46 -5
View File
@@ -15,17 +15,31 @@ describe('operation registry', () => {
expect(new Set(names).size).toBe(names.length)
})
it('contains the asset and project operations', () => {
it('contains the asset, project, comment, metadata, version, and upload operations', () => {
expect(operationDefinitions.map((d) => d.name).sort()).toEqual([
'complete_upload',
'copy_assets',
'create_comment',
'create_file',
'create_folder',
'create_version',
'create_version_stack',
'delete_asset',
'download_asset',
'get_asset_render',
'get_folder_instructions',
'list_assets',
'list_comments',
'list_metadata_fields',
'list_projects',
'list_versions',
'move_assets',
'read_asset',
'remove_version',
'rename_asset',
'resolve_comment',
'search_assets',
'update_asset_metadata',
])
})
@@ -50,12 +64,29 @@ describe('operation registry', () => {
expect(readOnly.map((d) => d.name).sort()).toEqual([
'download_asset',
'get_asset_render',
'get_folder_instructions',
'list_assets',
'list_comments',
'list_metadata_fields',
'list_projects',
'list_versions',
'read_asset',
'search_assets',
])
})
it('exposes uploads on the agent and MCP only, and complete_upload on MCP only', () => {
// The CLI uploads with its own `upload` and `create-version` commands, and the agent's
// create tools complete their uploads themselves.
const surfaces = (name: string) => getOperationDefinition(name)?.surfaces
expect(surfaces('create_file')).toEqual(['agent', 'mcp'])
expect(surfaces('create_version')).toEqual(['agent', 'mcp'])
expect(surfaces('complete_upload')).toEqual(['mcp'])
const cli = getOperationDefinitionsForSurface('cli').map((d) => d.name)
expect(cli).not.toContain('create_file')
expect(cli).not.toContain('complete_upload')
})
it.each(operationDefinitions.map((d) => [d.name, d] as const))(
'%s exports an object JSON Schema with described fields',
(_name, definition) => {
@@ -85,20 +116,30 @@ describe('operation registry', () => {
)
it('keeps legacy CLI invocations mapped', () => {
const commands = operationDefinitions.map((d) => [
d.name,
[...(d.cli?.command ?? []), ...(d.cli?.aliases ?? [])],
])
const commands = operationDefinitions
.filter((d) => d.cli)
.map((d) => [d.name, [...(d.cli?.command ?? []), ...(d.cli?.aliases ?? [])]])
expect(commands).toEqual([
['list_projects', ['project', 'ls']],
['list_assets', ['ls']],
['search_assets', ['search']],
['create_folder', ['mkdir']],
['rename_asset', ['rename']],
['move_assets', ['move', 'mv']],
['copy_assets', ['copy', 'cp']],
['delete_asset', ['delete', 'rm']],
['read_asset', ['read']],
['get_asset_render', ['render']],
['download_asset', ['download']],
['get_folder_instructions', ['instructions']],
['list_comments', ['comment', 'ls']],
['create_comment', ['comment', 'add']],
['resolve_comment', ['comment', 'resolve']],
['list_metadata_fields', ['field', 'ls']],
['update_asset_metadata', ['meta', 'set']],
['create_version_stack', ['version', 'stack']],
['list_versions', ['version', 'ls']],
['remove_version', ['version', 'unstack']],
])
})
+28
View File
@@ -1,12 +1,26 @@
import { copyAssets } from './asset/copy-assets'
import { createFolder } from './asset/create-folder'
import { deleteAsset } from './asset/delete-asset'
import { downloadAsset } from './asset/download-asset'
import { getFolderInstructions } from './asset/get-folder-instructions'
import { listAssets } from './asset/list-assets'
import { moveAssets } from './asset/move-assets'
import { getAssetRender, readAsset } from './asset/read-asset'
import { renameAsset } from './asset/rename-asset'
import { searchAssets } from './asset/search-assets'
import { createComment } from './comment/create-comment'
import { listComments } from './comment/list-comments'
import { resolveComment } from './comment/resolve-comment'
import type { AnyOperationDefinition, Surface } from './define'
import { listMetadataFields } from './metadata/list-metadata-fields'
import { updateAssetMetadata } from './metadata/update-asset-metadata'
import { listProjects } from './project/list-projects'
import { completeUpload } from './upload/complete-upload'
import { createFile } from './upload/create-file'
import { createVersion } from './upload/create-version'
import { createVersionStack } from './version/create-version-stack'
import { listVersions } from './version/list-versions'
import { removeVersion } from './version/remove-version'
/**
* Every Operation definition. Adding one here requires a matching implementation in
@@ -15,13 +29,27 @@ import { listProjects } from './project/list-projects'
export const operationDefinitions = [
listProjects,
listAssets,
searchAssets,
createFolder,
renameAsset,
moveAssets,
copyAssets,
deleteAsset,
readAsset,
getAssetRender,
downloadAsset,
getFolderInstructions,
createFile,
createVersion,
completeUpload,
listComments,
createComment,
resolveComment,
listMetadataFields,
updateAssetMetadata,
createVersionStack,
listVersions,
removeVersion,
] as const
export type RegisteredOperationDefinition = (typeof operationDefinitions)[number]
@@ -0,0 +1,19 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema } from '../schemas'
export const completeUpload = defineOperation({
name: 'complete_upload',
title: 'Complete Upload',
description:
'Finish an upload started with create_file or create_version, after the file bytes were ' +
'PUT to its uploadUrl. Creates the file (or the new version) and starts processing it ' +
'(previews, transcoding). Returns the new file. Calling it again for the same upload ' +
'returns the same file.',
input: z.object({
uploadId: z.string().min(1).describe('The uploadId returned by create_file or create_version.'),
}),
output: assetSummarySchema,
surfaces: ['mcp'],
annotations: { readOnly: false, destructive: false, idempotent: true },
})
@@ -0,0 +1,55 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { METADATA_VALUES_DESCRIPTION } from '../metadata/update-asset-metadata'
/** How long an upload started by create_file or create_version stays valid. */
export const UPLOAD_TTL_SECONDS = 60 * 60
/** Creation Context metadata, recorded by whoever creates a file. */
export const creationMetadataSchema = z
.record(z.string(), z.unknown())
.optional()
.describe(
"Values for the project's Creation Context fields (list_metadata_fields, creationContext: " +
'true), such as the prompt or model used to make the file. Only those fields are ' +
`accepted. ${METADATA_VALUES_DESCRIPTION}`,
)
export const startedUploadSchema = z.object({
uploadId: z.string().describe('Pass to complete_upload once the file is uploaded.'),
uploadUrl: z.string().describe('Upload the raw file bytes here with an HTTP PUT request.'),
method: z.literal('PUT'),
expiresAt: z.string().describe('When uploadUrl and uploadId stop working (about an hour).'),
/** Storage key; only returned to Shumai's built-in agent, which uploads from its sandbox. */
key: z.string().optional(),
})
export type StartedUploadOutput = z.infer<typeof startedUploadSchema>
const UPLOAD_STEPS =
'Uploading takes three steps: call this tool, PUT the raw file bytes to uploadUrl (e.g. ' +
'`curl -T <file> "<uploadUrl>"`), then call complete_upload with uploadId to create the ' +
`asset. The upload URL expires after about an hour.`
export const createFile = defineOperation({
name: 'create_file',
title: 'Create File',
description: `Start uploading a new file into a folder. ${UPLOAD_STEPS}`,
input: z.object({
parent: z.string().min(1).describe('The folder to create the file in.'),
name: z
.string()
.trim()
.min(1)
.max(255)
.describe('File name including its extension, e.g. "storyboard.pdf".'),
contentType: z
.string()
.min(1)
.optional()
.describe('MIME type, e.g. "image/png". Detected from the name when omitted.'),
metadata: creationMetadataSchema,
}),
output: startedUploadSchema,
surfaces: ['agent', 'mcp'],
annotations: { readOnly: false, destructive: false },
})
@@ -0,0 +1,31 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { creationMetadataSchema, startedUploadSchema } from './create-file'
export const createVersion = defineOperation({
name: 'create_version',
title: 'Create Version',
description:
'Start uploading a new version of an existing file. The new version becomes the current ' +
'one; a plain file becomes a version stack. Uploading takes three steps: call this tool, ' +
'PUT the raw file bytes to uploadUrl (e.g. `curl -T <file> "<uploadUrl>"`), then call ' +
'complete_upload with uploadId. The upload URL expires after about an hour.',
input: z.object({
parent: z.string().min(1).describe('The file or version stack to add a version to.'),
name: z
.string()
.trim()
.min(1)
.max(255)
.describe('File name of the new version including its extension, e.g. "cut_v3.mp4".'),
contentType: z
.string()
.min(1)
.optional()
.describe('MIME type, e.g. "video/mp4". Detected from the name when omitted.'),
metadata: creationMetadataSchema,
}),
output: startedUploadSchema,
surfaces: ['agent', 'mcp'],
annotations: { readOnly: false, destructive: false },
})
@@ -0,0 +1,29 @@
import { z } from 'zod'
import { defineOperation } from '../define'
import { assetSummarySchema } from '../schemas'
export const createVersionStack = defineOperation({
name: 'create_version_stack',
title: 'Create Version Stack',
description:
'Stack existing files in the same folder as versions of one asset, e.g. "cut_v1.mp4" and ' +
'"cut_v2.mp4". The first file in fileIds becomes the current (latest) version. To add a ' +
'newly uploaded file as a version, use create_version instead.',
input: z.object({
fileIds: z
.array(z.string().min(1))
.min(2)
.describe(
'IDs of the files to stack (at least two, all in the same folder), latest version first.',
),
}),
output: assetSummarySchema,
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false },
cli: {
command: ['version', 'stack'],
description: 'Stack files in the same folder as versions; the first file is the latest.',
positional: ['fileIds'],
format: (output) => `Created version stack ${output.id}`,
},
})
@@ -0,0 +1,40 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const versionSummarySchema = z.object({
id: z.string().describe('The file ID of this version.'),
version: z.number().describe('Version number; the highest is the latest.'),
name: z.string(),
current: z.boolean().describe('Whether this is the current (latest) version.'),
createdAt: z.string(),
creator: z.object({ id: z.string(), name: z.string().nullable() }).nullable(),
agent: z
.object({ id: z.string(), name: z.string() })
.nullable()
.describe('The AI agent that created this version, if any.'),
})
export const listVersions = defineOperation({
name: 'list_versions',
title: 'List Versions',
description:
'List the versions in a version stack, latest first. Each version is a file: pass its ID ' +
'to read_asset or list_comments to look at an older version.',
input: z.object({
stackId: z.string().min(1).describe('The version stack ID.'),
}),
output: z.object({
versions: z.array(versionSummarySchema),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: true, destructive: false, idempotent: true },
cli: {
command: ['version', 'ls'],
description: 'List the versions in a version stack, latest first.',
positional: ['stackId'],
format: (output) =>
output.versions
.map((v) => `v${v.version}${v.current ? ' (current)' : ''} ${v.id} ${v.name}`)
.join('\n'),
},
})
@@ -0,0 +1,25 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const removeVersion = defineOperation({
name: 'remove_version',
title: 'Remove Version',
description:
'Take a version out of its version stack. The file is not deleted: it goes back into the ' +
'folder next to the stack as a separate file.',
input: z.object({
versionId: z.string().min(1).describe('The file ID of the version (from list_versions).'),
}),
output: z.object({
versionId: z.string(),
stackId: z.string().describe('The stack the version was removed from.'),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false },
cli: {
command: ['version', 'unstack'],
description: 'Take a version out of its version stack (the file is kept).',
positional: ['versionId'],
format: (output) => `Removed ${output.versionId} from version stack ${output.stackId}`,
},
})