mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +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,35 @@
|
||||
import { copyAssets } from '@shumai/operations'
|
||||
import { AuditAction } from '@shumai/dtos'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
import { Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { asBadRequest } from '../errors'
|
||||
import { implementOperation } from '../implement'
|
||||
|
||||
export const copyAssetsOp = implementOperation(copyAssets, {
|
||||
authz: (input) => [
|
||||
{ permission: Permission.Edit, type: ResourceType.Asset, id: input.newParentId },
|
||||
...[...new Set(input.assetIds)].map((id) => ({
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id,
|
||||
})),
|
||||
],
|
||||
execute: async (input, ctx) => {
|
||||
const copiedAssetIds = await asBadRequest(() =>
|
||||
assetService.copyAssets({
|
||||
assetIds: input.assetIds,
|
||||
newParentId: input.newParentId,
|
||||
withComments: input.withComments ?? false,
|
||||
creatorId: ctx.userId,
|
||||
}),
|
||||
)
|
||||
return { copiedAssetIds, newParentId: input.newParentId }
|
||||
},
|
||||
// One entry per source asset, recorded in the destination's team and project.
|
||||
audit: (input) =>
|
||||
input.assetIds.map((assetId) => ({
|
||||
action: AuditAction.asset_copy,
|
||||
itemId: assetId,
|
||||
contextAssetId: input.newParentId,
|
||||
})),
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
import { getFolderInstructions } from '@shumai/operations'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
import { Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { asBadRequest } from '../errors'
|
||||
import { implementOperation } from '../implement'
|
||||
|
||||
export const getFolderInstructionsOp = implementOperation(getFolderInstructions, {
|
||||
authz: (input) => [{ permission: Permission.Read, type: ResourceType.Asset, id: input.folderId }],
|
||||
execute: async (input) => ({
|
||||
folderId: input.folderId,
|
||||
content: await asBadRequest(() => assetService.getAgentsMd(input.folderId)),
|
||||
}),
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import { DEFAULT_PAGE_SIZE, searchAssets } from '@shumai/operations'
|
||||
import { Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { searchService } from '@shumai/core/src/search/search'
|
||||
import { asBadRequest } from '../errors'
|
||||
import { implementOperation } from '../implement'
|
||||
import { toAssetSummary } from './to-asset-summary'
|
||||
|
||||
export const searchAssetsOp = implementOperation(searchAssets, {
|
||||
authz: (input) => [{ permission: Permission.Read, type: ResourceType.Asset, id: input.parent }],
|
||||
execute: async (input) => {
|
||||
const semantic = Boolean(input.query && input.semantic)
|
||||
const conditions = (input.conditions ?? []).map((c) => ({ ...c, value: c.value ?? null }))
|
||||
// Name search is a `name contains` condition (always combined with AND); only
|
||||
// semantic search uses the query text itself.
|
||||
if (input.query && !semantic) {
|
||||
conditions.push({ field: 'name', operator: 'contains', value: input.query })
|
||||
}
|
||||
const result = await asBadRequest(() =>
|
||||
searchService.search(input.parent, {
|
||||
query: semantic ? input.query : undefined,
|
||||
isSemantic: semantic,
|
||||
assetType: input.type,
|
||||
recursively: input.recursive ?? true,
|
||||
conditions,
|
||||
operator: input.matchAny ? 'OR' : 'AND',
|
||||
first: input.first ?? DEFAULT_PAGE_SIZE,
|
||||
after: input.after,
|
||||
}),
|
||||
)
|
||||
return {
|
||||
data: result.data.map(toAssetSummary),
|
||||
pageInfo: {
|
||||
hasNextPage: Boolean(result.pageInfo.cursor),
|
||||
endCursor: result.pageInfo.cursor ?? null,
|
||||
},
|
||||
total: result.pageInfo.total ?? result.data.length,
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user