mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* fix: Page large document and template text in MCP fetch * fix: Keep surrogate pairs whole when paging MCP fetch text * fix: Only include textLength in MCP fetch when text is paged * fix: Update MCP instructions and skills for paged fetch and template lists
158 lines
4.7 KiB
TypeScript
158 lines
4.7 KiB
TypeScript
import { Scope } from "@shared/types";
|
|
import {
|
|
buildUser,
|
|
buildCollection,
|
|
buildTemplate,
|
|
buildOAuthAuthentication,
|
|
} from "@server/test/factories";
|
|
import { getTestServer } from "@server/test/support";
|
|
import { buildOAuthUser, callMcpTool } from "@server/test/McpHelper";
|
|
|
|
const server = getTestServer();
|
|
|
|
describe("list_templates", () => {
|
|
it("returns workspace and collection templates the user can access", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const workspaceTemplate = await buildTemplate({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
collectionId: null,
|
|
text: "Body of the workspace template",
|
|
});
|
|
const collectionTemplate = await buildTemplate({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_templates");
|
|
const data = (res?.result?.content ?? []).map((c: { text?: string }) =>
|
|
JSON.parse(c.text ?? "{}")
|
|
);
|
|
|
|
const ids = data.map((t: { id: string }) => t.id);
|
|
expect(ids).toContain(workspaceTemplate.id);
|
|
expect(ids).toContain(collectionTemplate.id);
|
|
|
|
const match = data.find(
|
|
(t: { id: string }) => t.id === workspaceTemplate.id
|
|
) as { url: string; collectionId: string | null; text?: string };
|
|
expect(match.url).toMatch(/^https?:\/\//);
|
|
expect(match.collectionId).toBeNull();
|
|
expect(match.text).toBeUndefined();
|
|
});
|
|
|
|
it("filters by collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection1 = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const collection2 = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const template1 = await buildTemplate({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
collectionId: collection1.id,
|
|
});
|
|
await buildTemplate({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
collectionId: collection2.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_templates", {
|
|
collectionId: collection1.id,
|
|
});
|
|
const data = (res?.result?.content ?? []).map((c: { text?: string }) =>
|
|
JSON.parse(c.text ?? "{}")
|
|
);
|
|
|
|
const ids = data.map((t: { id: string }) => t.id);
|
|
expect(ids).toContain(template1.id);
|
|
expect(
|
|
data.every(
|
|
(t: { collectionId: string }) => t.collectionId === collection1.id
|
|
)
|
|
).toBe(true);
|
|
});
|
|
|
|
it("filters by a collection referenced by urlId", async () => {
|
|
const { user, accessToken } = await buildOAuthUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const template = await buildTemplate({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_templates", {
|
|
collectionId: collection.urlId,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBeUndefined();
|
|
const data = (res?.result?.content ?? []).map((c: { text?: string }) =>
|
|
JSON.parse(c.text ?? "{}")
|
|
);
|
|
const ids = data.map((t: { id: string }) => t.id);
|
|
expect(ids).toEqual([template.id]);
|
|
});
|
|
|
|
it("fails for an admin who is not a member of a private collection", async () => {
|
|
const { user, accessToken } = await buildOAuthUser({ role: "admin" });
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
permission: null,
|
|
});
|
|
await buildTemplate({
|
|
teamId: user.teamId,
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
const res = await callMcpTool(server, accessToken, "list_templates", {
|
|
collectionId: collection.id,
|
|
});
|
|
|
|
expect(res?.result?.isError).toBe(true);
|
|
});
|
|
|
|
it("does not return templates from collections the user cannot access", async () => {
|
|
const owner = await buildUser();
|
|
const otherUser = await buildUser({ teamId: owner.teamId });
|
|
|
|
const privateCollection = await buildCollection({
|
|
teamId: owner.teamId,
|
|
userId: owner.id,
|
|
permission: null,
|
|
});
|
|
const privateTemplate = await buildTemplate({
|
|
teamId: owner.teamId,
|
|
userId: owner.id,
|
|
collectionId: privateCollection.id,
|
|
});
|
|
|
|
const auth = await buildOAuthAuthentication({
|
|
user: otherUser,
|
|
scope: [Scope.Read],
|
|
});
|
|
|
|
const res = await callMcpTool(server, auth.accessToken!, "list_templates");
|
|
const data = (res?.result?.content ?? []).map((c: { text?: string }) =>
|
|
JSON.parse(c.text ?? "{}")
|
|
);
|
|
const ids = data.map((t: { id: string }) => t.id);
|
|
|
|
expect(res?.result?.isError).not.toBe(true);
|
|
expect(ids).not.toContain(privateTemplate.id);
|
|
});
|
|
});
|