mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +00:00
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:
@@ -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 },
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user