mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
* fix: Return a compact success payload from MCP mutation tools Mutation tools serialized the entire resource — and for documents the full markdown body — back to the client on every write, which the caller already has. They now acknowledge the write with the identifying fields needed to reference the resource. The one exception is update_document with editMode "patch", which still echoes the resulting content so the caller can verify what was replaced. For move_document and restore_document the breadcrumb is now resolved after the transaction commits, so it reflects the new location rather than the cached pre-move document structure. * test: Update MCP scope enforcement tests for the new response shape * test: Assert the success acknowledgement across all mutation tool variants
131 lines
4.2 KiB
TypeScript
131 lines
4.2 KiB
TypeScript
import { Collection } from "@server/models";
|
|
import { buildCollection, buildUser } from "@server/test/factories";
|
|
import { getTestServer } from "@server/test/support";
|
|
import {
|
|
buildOAuthUser,
|
|
callMcpTool,
|
|
parseMcpListContent,
|
|
} from "@server/test/McpHelper";
|
|
|
|
const server = getTestServer();
|
|
|
|
describe("collection tools", () => {
|
|
it("list_collections returns user collections", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections");
|
|
const data = parseMcpListContent<{ id: string; url: string }>(
|
|
res?.result?.content
|
|
);
|
|
|
|
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
const ids = data.map((c) => c.id);
|
|
expect(ids).toContain(collection.id);
|
|
|
|
const match = data.find((c) => c.id === collection.id);
|
|
expect(match).toBeDefined();
|
|
expect(match!.url).toMatch(/^https?:\/\//);
|
|
});
|
|
|
|
it("list_collections does not return collections from another team", async () => {
|
|
const { accessToken } = await buildOAuthUser();
|
|
const otherUser = await buildUser();
|
|
const otherCollection = await buildCollection({
|
|
teamId: otherUser.teamId,
|
|
userId: otherUser.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_collections");
|
|
const data = parseMcpListContent<{ id: string }>(res?.result?.content);
|
|
|
|
const ids = data.map((c: { id: string }) => c.id);
|
|
expect(ids).not.toContain(otherCollection.id);
|
|
});
|
|
|
|
it("create_collection creates with name, description, icon, color", async () => {
|
|
const { accessToken } = await buildOAuthUser();
|
|
|
|
const res = await callMcpTool(server, accessToken, "create_collection", {
|
|
name: "Test Collection",
|
|
description: "A **test** description",
|
|
icon: "rocket",
|
|
color: "#FF0000",
|
|
});
|
|
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
|
|
|
expect(data.success).toBe(true);
|
|
expect(data.name).toEqual("Test Collection");
|
|
expect(data.id).toBeDefined();
|
|
expect(data.url).toMatch(/^https?:\/\//);
|
|
|
|
const collection = await Collection.findByPk(data.id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
expect(collection.description).toEqual("A **test** description");
|
|
expect(collection.icon).toEqual("rocket");
|
|
expect(collection.color).toEqual("#FF0000");
|
|
expect(collection.permission).toEqual(null);
|
|
});
|
|
|
|
it("update_collection updates fields on existing collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
name: "Updated Name",
|
|
description: "Updated description",
|
|
});
|
|
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
|
|
|
expect(data.success).toBe(true);
|
|
expect(data.name).toEqual("Updated Name");
|
|
expect(data.url).toMatch(/^https?:\/\//);
|
|
|
|
await collection.reload();
|
|
expect(collection.description).toEqual("Updated description");
|
|
});
|
|
|
|
it("update_collection errors when no fields are provided to update", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
expect(res?.result?.content?.[0]?.text).toContain(
|
|
"The update resulted in no changes to the collection"
|
|
);
|
|
});
|
|
|
|
it("update_collection errors when provided fields are identical to the current collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "update_collection", {
|
|
id: collection.id,
|
|
name: collection.name,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
expect(res?.result?.content?.[0]?.text).toContain(
|
|
"The update resulted in no changes to the collection"
|
|
);
|
|
});
|
|
});
|