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
+45 -8
View File
@@ -397,8 +397,9 @@ export class AssetService {
}
}
async copyAssets(req: CopyAssetsRequest): Promise<void> {
await this.prismaClient.$transaction(async (tx) => {
/** Copies assets into a folder. Returns the IDs of the copies, in the order of `assetIds`. */
async copyAssets(req: CopyAssetsRequest): Promise<string[]> {
return this.prismaClient.$transaction(async (tx) => {
const newParent = await tx.asset.findUnique({
where: { id: req.newParentId },
include: { project: { include: { team: true } } },
@@ -448,6 +449,7 @@ export class AssetService {
let firstSortIndex = firstFile?.sortIndex || null
let totalSize = 0
const copiedIds: string[] = new Array(req.assetIds.length)
for (let i = req.assetIds.length - 1; i >= 0; i--) {
const assetId = req.assetIds[i]
const asset = assetsToCopy.find((a) => a.id === assetId)!
@@ -461,6 +463,7 @@ export class AssetService {
req.creatorId,
req.withComments,
)
copiedIds[i] = copiedAsset.id
totalSize += Number(copiedAsset.sizeByte)
firstSortIndex = newSortIndex
}
@@ -472,6 +475,7 @@ export class AssetService {
},
})
await this.updateAncestorsSize(tx, newParent.id, totalSize)
return copiedIds
})
}
@@ -1144,12 +1148,17 @@ export class AssetService {
* Lightweight lookup of an asset's type and team/project, without building a full AssetInfo
* (no presigned URLs). Use it to capture context before a mutation such as a delete.
*/
async getAssetMeta(
assetId: string,
): Promise<{ id: string; name: string; type: AssetType; teamId: string; projectId?: string }> {
async getAssetMeta(assetId: string): Promise<{
id: string
name: string
type: AssetType
parentId: string | null
teamId: string
projectId?: string
}> {
const asset = await this.prismaClient.asset.findUnique({
where: { id: assetId },
select: { id: true, name: true, type: true },
select: { id: true, name: true, type: true, parentId: true },
})
if (!asset) {
throw new HTTPException(404, { message: 'Asset not found' })
@@ -1158,6 +1167,20 @@ export class AssetService {
return { ...asset, teamId, projectId }
}
/**
* The asset whose file is stored under `key`, with its creator. Used to make finishing an
* upload idempotent: the same uploaded object is never attached to two assets.
*/
async findAssetByStorageKey(
key: string,
): Promise<{ id: string; creatorId: string | null } | null> {
return this.prismaClient.asset.findFirst({
where: { storageKey: { key } },
select: { id: true, creatorId: true },
orderBy: { id: 'asc' },
})
}
async resolveTargetAssetId(assetId: string): Promise<string> {
const asset = await this.prismaClient.asset.findUnique({
where: { id: assetId },
@@ -1734,7 +1757,16 @@ export class AssetService {
}
}
async createComment(req: CreateCommentRequest): Promise<CommentInfo> {
/**
* Creates a comment or reply. Mentions of agents (`<@agentId>`) start a chat with them
* unless `triggerAgents` is false, which keeps an agent's own comments from starting
* further agent runs.
*/
async createComment(
req: CreateCommentRequest,
options: { triggerAgents?: boolean } = {},
): Promise<CommentInfo> {
const triggerAgents = options.triggerAgents ?? true
let commentId = ''
const resolvedAssetId = await this.resolveLatestVersionId(req.assetId)
@@ -1783,6 +1815,8 @@ export class AssetService {
}
}
if (!triggerAgents) return
// Parse bot mentions
const botMentionMatches = [...req.message.matchAll(/<@([^>]+)>/g)]
const mentionedAgentIds = new Set(botMentionMatches.map((match) => match[1]))
@@ -2083,7 +2117,10 @@ export class AssetService {
orderBy: { id: 'asc' },
})
},
async () => this.prismaClient.assetComment.count({ where: { assetId, replyToId: null } }),
async () =>
this.prismaClient.assetComment.count({
where: { assetId: resolvedAssetId, replyToId: null },
}),
params,
)