mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 22:49: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:
@@ -4,6 +4,7 @@ import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { workflowService, TaskQueueAgent } from '@shumai/workflow-core'
|
||||
import { initAgentWorkflows } from '@shumai/agent'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { projectService } from '@shumai/core/src/project/project'
|
||||
import { AgentHarness } from '@earendil-works/pi-agent-core'
|
||||
|
||||
@@ -24,6 +25,18 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
let rootFolderId = ''
|
||||
let scenario: 'organize' | 'review' = 'organize'
|
||||
// Used by the review scenario
|
||||
let projectId = ''
|
||||
let reviewFieldKey = ''
|
||||
let promptFieldKey = ''
|
||||
|
||||
const reply = (text: string) =>
|
||||
({
|
||||
content: [{ type: 'text', text }],
|
||||
usage: { input: 10, output: 20 },
|
||||
stopReason: 'stop',
|
||||
}) as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
|
||||
|
||||
beforeAll(async () => {
|
||||
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-agent-ops'
|
||||
@@ -36,16 +49,56 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
) {
|
||||
const tool = (name: string) =>
|
||||
this.getTools().find((t) => t.name === name) as unknown as ExecutableTool | undefined
|
||||
const call = async (name: string, params: Record<string, unknown>) => {
|
||||
const t = tool(name)
|
||||
if (!t) throw new Error(`missing tool ${name}`)
|
||||
return JSON.parse(toolText(await t.execute(`call-${name}`, params))) as unknown
|
||||
}
|
||||
|
||||
if (scenario === 'review') {
|
||||
const found = (await call('search_assets', { parent: rootFolderId, query: 'brief' })) as {
|
||||
data: Array<{ id: string; name: string }>
|
||||
}
|
||||
const assetId = found.data[0].id
|
||||
const comment = (await call('create_comment', {
|
||||
assetId,
|
||||
message: 'The logo is too small',
|
||||
})) as { id: string }
|
||||
const listed = (await call('list_comments', { assetId })) as {
|
||||
data: Array<{ id: string; message: string }>
|
||||
}
|
||||
await call('resolve_comment', { commentId: comment.id })
|
||||
const { fields } = (await call('list_metadata_fields', { projectId })) as {
|
||||
fields: Array<{ key: string; creationContext: boolean }>
|
||||
}
|
||||
await call('update_asset_metadata', {
|
||||
assetId,
|
||||
values: { [reviewFieldKey]: 'Needs changes' },
|
||||
})
|
||||
const file = (await call('create_file', {
|
||||
parent: rootFolderId,
|
||||
name: 'review-notes.md',
|
||||
content: '# Review\n\nLogo too small.',
|
||||
metadata: { [promptFieldKey]: 'Summarize the review' },
|
||||
})) as { id: string }
|
||||
const creationFields = fields.filter((f) => f.creationContext).map((f) => f.key)
|
||||
return reply(
|
||||
[
|
||||
`found:${found.data.map((a) => a.name).join(',')}`,
|
||||
`comment:${comment.id}`,
|
||||
`listed:${listed.data.map((c) => c.message).join(',')}`,
|
||||
`creation_fields:${creationFields.join(',')}`,
|
||||
`file:${file.id}`,
|
||||
`complete_tool:${tool('complete_upload') ? 'present' : 'absent'}`,
|
||||
].join('|'),
|
||||
)
|
||||
}
|
||||
|
||||
const createFolder = tool('create_folder')
|
||||
const listAssets = tool('list_assets')
|
||||
const deleteAsset = tool('delete_asset')
|
||||
if (!createFolder || !listAssets) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'MISSING_OPERATION_TOOLS' }],
|
||||
usage: { input: 1, output: 1 },
|
||||
stopReason: 'stop',
|
||||
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
|
||||
return reply('MISSING_OPERATION_TOOLS')
|
||||
}
|
||||
|
||||
const created = JSON.parse(
|
||||
@@ -63,11 +116,7 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
// delete_asset is denied by default and must not be registered
|
||||
`delete_tool:${deleteAsset ? 'present' : 'absent'}`,
|
||||
].join('|')
|
||||
return {
|
||||
content: [{ type: 'text', text: summary }],
|
||||
usage: { input: 10, output: 20 },
|
||||
stopReason: 'stop',
|
||||
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
|
||||
return reply(summary)
|
||||
})
|
||||
|
||||
await workflowService.startWorkers(TaskQueueAgent)
|
||||
@@ -84,22 +133,24 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('creates and lists assets through Operations, attributed to the user and agent', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'E2E Agent Ops Team' } })
|
||||
/** A team, project, chat agent, and a user comment asking the agent to act; returns the task. */
|
||||
async function setupChat(label: string, message: string) {
|
||||
const team = await prisma.team.create({ data: { name: `E2E Agent Ops Team ${label}` } })
|
||||
const regularUser = await prisma.user.create({
|
||||
data: { name: 'Ops User', email: 'ops-user@example.com', type: 'human' },
|
||||
data: { name: 'Ops User', email: `ops-user-${label}@example.com`, type: 'human' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: regularUser.id, role: 'owner' },
|
||||
})
|
||||
const project = await projectService.createProject(regularUser, {
|
||||
teamId: team.id,
|
||||
name: 'E2E Agent Ops Project',
|
||||
name: `E2E Agent Ops Project ${label}`,
|
||||
})
|
||||
rootFolderId = project.rootFolder!
|
||||
projectId = project.id
|
||||
|
||||
const agentUser = await prisma.user.create({
|
||||
data: { name: 'E2E Ops Agent', email: 'e2e-ops-agent@shumai.ai', type: 'agent' },
|
||||
data: { name: 'E2E Ops Agent', email: `e2e-ops-agent-${label}@shumai.ai`, type: 'agent' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: agentUser.id, role: 'editor' },
|
||||
@@ -136,13 +187,9 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
config: { provider: 'google', model: 'gemini' },
|
||||
},
|
||||
})
|
||||
const sessionId = `agent-ops-session-${label}`
|
||||
await prisma.agentSession.create({
|
||||
data: {
|
||||
id: 'agent-ops-session',
|
||||
agentId: agentUser.id,
|
||||
userId: regularUser.id,
|
||||
cwd: process.cwd(),
|
||||
},
|
||||
data: { id: sessionId, agentId: agentUser.id, userId: regularUser.id, cwd: process.cwd() },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
@@ -155,12 +202,7 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
},
|
||||
})
|
||||
const userComment = await prisma.assetComment.create({
|
||||
data: {
|
||||
assetId: asset.id,
|
||||
message: 'Create a folder called Agent Folder and list the root',
|
||||
creatorId: regularUser.id,
|
||||
sessionId: 'agent-ops-session',
|
||||
},
|
||||
data: { assetId: asset.id, message, creatorId: regularUser.id, sessionId },
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
@@ -174,13 +216,29 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
projectId: project.id,
|
||||
agent: {
|
||||
agentId: agentUser.id,
|
||||
sessionId: 'agent-ops-session',
|
||||
sessionId,
|
||||
userCommentId: userComment.id,
|
||||
userId: regularUser.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return { team, project, regularUser, agentUser, asset, userComment, task }
|
||||
}
|
||||
|
||||
async function agentReply(assetId: string, userCommentId: string) {
|
||||
const [reply] = await prisma.assetComment.findMany({
|
||||
where: { assetId, replyToId: userCommentId },
|
||||
})
|
||||
return reply?.message ?? ''
|
||||
}
|
||||
|
||||
it('creates and lists assets through Operations, attributed to the user and agent', async () => {
|
||||
scenario = 'organize'
|
||||
const { team, project, regularUser, agentUser, asset, userComment, task } = await setupChat(
|
||||
'organize',
|
||||
'Create a folder called Agent Folder and list the root',
|
||||
)
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
@@ -203,11 +261,83 @@ describe('Workflow E2E - agent Operation tools', () => {
|
||||
via: 'agent',
|
||||
})
|
||||
|
||||
const [reply] = await prisma.assetComment.findMany({
|
||||
where: { assetId: asset.id, replyToId: userComment.id },
|
||||
const message = await agentReply(asset.id, userComment.id)
|
||||
expect(message).toContain(`created:${folder.id}`)
|
||||
expect(message).toMatch(/listed:.*Agent Folder/)
|
||||
expect(message).toContain('delete_tool:absent')
|
||||
}, 50000)
|
||||
|
||||
it('reviews a file: search, comment, resolve, set metadata, and write notes with Creation Context', async () => {
|
||||
scenario = 'review'
|
||||
const setup = await setupChat('review', 'Review the brief and write up notes')
|
||||
const { team, project, regularUser, agentUser, asset, userComment, task } = setup
|
||||
const review = await metadataService.createProjectField(project.id, {
|
||||
config: { name: 'Review', type: 'text' },
|
||||
description: '',
|
||||
})
|
||||
expect(reply?.message).toContain(`created:${folder.id}`)
|
||||
expect(reply?.message).toMatch(/listed:.*Agent Folder/)
|
||||
expect(reply?.message).toContain('delete_tool:absent')
|
||||
const prompt = await metadataService.createProjectField(project.id, {
|
||||
config: { name: 'Prompt', type: 'text', autofillSource: 'CREATION_CONTEXT' },
|
||||
description: 'What the agent was asked to do',
|
||||
})
|
||||
reviewFieldKey = review.key
|
||||
promptFieldKey = prompt.key
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const message = await agentReply(asset.id, userComment.id)
|
||||
expect(message).toContain('found:brief.png')
|
||||
expect(message).toMatch(/listed:[^|]*The logo is too small/)
|
||||
expect(message).toContain(`creation_fields:${prompt.key}`)
|
||||
// The agent finishes its own uploads; complete_upload is an MCP-only tool
|
||||
expect(message).toContain('complete_tool:absent')
|
||||
|
||||
// The comment is posted as the user, resolved, and audited as coming from the agent
|
||||
const comment = await prisma.assetComment.findFirstOrThrow({
|
||||
where: { assetId: asset.id, message: 'The logo is too small' },
|
||||
})
|
||||
expect(comment.creatorId).toBe(regularUser.id)
|
||||
expect(comment.isCompleted).toBe(true)
|
||||
for (const action of ['comment_create', 'comment_complete']) {
|
||||
const audit = await prisma.auditLog.findFirstOrThrow({
|
||||
where: { action, itemId: comment.id },
|
||||
})
|
||||
expect(audit).toMatchObject({
|
||||
teamId: team.id,
|
||||
userId: regularUser.id,
|
||||
agentId: agentUser.id,
|
||||
via: 'agent',
|
||||
})
|
||||
}
|
||||
|
||||
const reviewValue = await prisma.assetMetadataValue.findFirstOrThrow({
|
||||
where: { assetId: asset.id, fieldKey: review.key },
|
||||
})
|
||||
expect(reviewValue.stringValue).toBe('Needs changes')
|
||||
|
||||
// The notes file is stored, attributed to the user and agent, with Creation Context
|
||||
const fileId = /file:([A-Z0-9]+)/.exec(message)?.[1]
|
||||
const notes = await prisma.asset.findUniqueOrThrow({
|
||||
where: { id: fileId },
|
||||
include: { storageKey: true, metadataValues: true },
|
||||
})
|
||||
expect(notes).toMatchObject({
|
||||
name: 'review-notes.md',
|
||||
parentId: rootFolderId,
|
||||
creatorId: regularUser.id,
|
||||
agentId: agentUser.id,
|
||||
})
|
||||
const stored = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-agent-ops',
|
||||
notes.storageKey!.key,
|
||||
)
|
||||
expect(stored.buffer.toString('utf-8')).toBe('# Review\n\nLogo too small.')
|
||||
expect(notes.metadataValues).toContainEqual(
|
||||
expect.objectContaining({ fieldKey: prompt.key, stringValue: 'Summarize the review' }),
|
||||
)
|
||||
const fileAudit = await prisma.auditLog.findFirstOrThrow({
|
||||
where: { action: 'file_create', itemId: notes.id },
|
||||
})
|
||||
expect(fileAudit).toMatchObject({ agentId: agentUser.id, via: 'agent' })
|
||||
}, 50000)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user