diff --git a/CHANGELOG.md b/CHANGELOG.md index 807321d..fc319eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ All notable changes to this project will be documented in this file. +## 1.13.0 - 2026-09-30 + +Changes since 1.12.0: + +### Added + +- Added credential CRUD tools to the MCP server: `list_credentials`, `get_credential`, `create_credential`, `update_credential`, and `delete_credential`. Combined with the existing `add_scenario_credential` tool, credentials can now be created and attached to scenarios entirely via MCP. + +## 1.12.0 - 2026-09-16 + +Changes since 1.11.0: + +### Added + +- When a scenario or snippet step fails, a full-page screenshot and the current page HTML are captured and uploaded as run artifacts, so failures can be diagnosed from the run's file list. + ## 1.11.0 - 2026-09-15 Changes since 1.10.1: diff --git a/package-lock.json b/package-lock.json index a815288..e1df1dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.12.0", + "version": "1.13.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.12.0", + "version": "1.13.0", "workspaces": [ "server", "client" diff --git a/package.json b/package.json index 904fe04..a6a417a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.12.0", + "version": "1.13.0", "private": true, "workspaces": [ "server", diff --git a/server/src/mcp/mcp.service.ts b/server/src/mcp/mcp.service.ts index 726d1fc..5469b02 100644 --- a/server/src/mcp/mcp.service.ts +++ b/server/src/mcp/mcp.service.ts @@ -275,6 +275,166 @@ export class McpService { }, ); + // ── Credentials ─────────────────────────────────────────────────────────── + + server.registerTool( + "list_credentials", + { + description: "List all credentials (paginated)", + inputSchema: { + page: z + .number() + .int() + .min(1) + .optional() + .describe("Page number (default 1)"), + limit: z + .number() + .int() + .min(1) + .optional() + .describe("Items per page (default 20)"), + orderBy: z + .enum(["id", "name", "lastUsedAt", "createdAt", "updatedAt"]) + .optional() + .describe("Field to order by (default id)"), + orderDir: z + .enum(["ASC", "DESC"]) + .optional() + .describe("Sort direction (default ASC)"), + }, + }, + async ({ page, limit, orderBy, orderDir }) => { + const result = await this.credentialService.findAll({ + page, + limit, + orderBy, + orderDir, + }); + return { + content: [{ type: "text" as const, text: JSON.stringify(result) }], + }; + }, + ); + + server.registerTool( + "get_credential", + { + description: "Get a credential by ID", + inputSchema: { + id: z.uuid().describe("Credential ID"), + }, + }, + async ({ id }) => { + try { + const credential = await this.credentialService.findOne(id); + return { + content: [ + { type: "text" as const, text: JSON.stringify(credential) }, + ], + }; + } catch (err) { + return { + isError: true, + content: [{ type: "text" as const, text: (err as Error).message }], + }; + } + }, + ); + + server.registerTool( + "create_credential", + { + description: + "Create a new credential. Assign it to a scenario with add_scenario_credential to use it via context.getCredential(alias).", + inputSchema: { + name: z.string().min(1).describe("Human-readable credential name"), + data: z + .string() + .optional() + .describe( + 'JSON-encoded credential payload, e.g. {"token":"abc123"}', + ), + }, + }, + async ({ name, data }) => { + try { + const credential = await this.credentialService.create({ + name, + data, + }); + return { + content: [ + { type: "text" as const, text: JSON.stringify(credential) }, + ], + }; + } catch (err) { + return { + isError: true, + content: [{ type: "text" as const, text: (err as Error).message }], + }; + } + }, + ); + + server.registerTool( + "update_credential", + { + description: "Update an existing credential (name and/or data)", + inputSchema: { + id: z.uuid().describe("Credential ID to update"), + name: z.string().min(1).optional().describe("New name"), + data: z + .string() + .optional() + .describe("New JSON-encoded credential payload"), + }, + }, + async ({ id, name, data }) => { + try { + const credential = await this.credentialService.update(id, { + ...(name !== undefined && { name }), + ...(data !== undefined && { data }), + }); + return { + content: [ + { type: "text" as const, text: JSON.stringify(credential) }, + ], + }; + } catch (err) { + return { + isError: true, + content: [{ type: "text" as const, text: (err as Error).message }], + }; + } + }, + ); + + server.registerTool( + "delete_credential", + { + description: "Delete a credential by ID", + inputSchema: { + id: z.uuid().describe("Credential ID to delete"), + }, + }, + async ({ id }) => { + try { + await this.credentialService.remove(id); + return { + content: [ + { type: "text" as const, text: `Credential ${id} deleted` }, + ], + }; + } catch (err) { + return { + isError: true, + content: [{ type: "text" as const, text: (err as Error).message }], + }; + } + }, + ); + // ── Browser ─────────────────────────────────────────────────────────────── server.registerTool( diff --git a/server/test/mcp.controller.spec.ts b/server/test/mcp.controller.spec.ts index 1ae7b24..4c016cb 100644 --- a/server/test/mcp.controller.spec.ts +++ b/server/test/mcp.controller.spec.ts @@ -843,4 +843,143 @@ describe("McpController", () => { expect(result.isError).toBe(true); }); }); + + // ── Credential CRUD tools ───────────────────────────────────────────────── + + async function createCredential(name: string, data?: string) { + const { rpc } = await mcpCall("create_credential", { name, data }); + return JSON.parse( + (rpc.result as { content: { text: string }[] }).content[0].text, + ) as { id: string; name: string; data: string | null }; + } + + describe("list_credentials", () => { + it("returns a paginated result with a data array", async () => { + await createCredential("mcp-list-cred"); + const { status, rpc } = await mcpCall("list_credentials", { + limit: 100, + }); + expect(status).toBe(200); + const result = rpc.result as { content: { text: string }[] }; + const body = JSON.parse(result.content[0].text) as { + data: { name: string }[]; + total: number; + }; + expect(Array.isArray(body.data)).toBe(true); + expect(typeof body.total).toBe("number"); + expect(body.data.some((c) => c.name === "mcp-list-cred")).toBe(true); + }); + }); + + describe("create_credential", () => { + it("creates a credential and returns it with name and data", async () => { + const created = await createCredential( + "mcp-test-cred", + '{"token":"abc123"}', + ); + expect(typeof created.id).toBe("string"); + expect(created.name).toBe("mcp-test-cred"); + expect(created.data).toBe('{"token":"abc123"}'); + }); + + it("stores null data when data is omitted", async () => { + const created = await createCredential("mcp-test-cred-nodata"); + expect(created.data).toBeNull(); + }); + }); + + describe("get_credential", () => { + it("returns the created credential by id", async () => { + const created = await createCredential("mcp-get-cred", '{"a":1}'); + const { status, rpc } = await mcpCall("get_credential", { + id: created.id, + }); + expect(status).toBe(200); + const result = rpc.result as { content: { text: string }[] }; + const fetched = JSON.parse(result.content[0].text) as { + id: string; + name: string; + data: string; + }; + expect(fetched.id).toBe(created.id); + expect(fetched.name).toBe("mcp-get-cred"); + expect(fetched.data).toBe('{"a":1}'); + }); + + it("returns an MCP error for a non-existent credential id", async () => { + const { status, rpc } = await mcpCall("get_credential", { + id: "00000000-0000-0000-0000-000000000000", + }); + expect(status).toBe(200); + const result = rpc.result as { isError: boolean }; + expect(result.isError).toBe(true); + }); + }); + + describe("update_credential", () => { + it("updates name and data of an existing credential", async () => { + const created = await createCredential("mcp-upd-cred-orig", '{"v":1}'); + const { status, rpc } = await mcpCall("update_credential", { + id: created.id, + name: "mcp-upd-cred-new", + data: '{"v":2}', + }); + expect(status).toBe(200); + const result = rpc.result as { content: { text: string }[] }; + const updated = JSON.parse(result.content[0].text) as { + name: string; + data: string; + }; + expect(updated.name).toBe("mcp-upd-cred-new"); + expect(updated.data).toBe('{"v":2}'); + }); + + it("leaves data untouched when only name is updated", async () => { + const created = await createCredential("mcp-upd-cred-partial", '{"k":1}'); + const { rpc } = await mcpCall("update_credential", { + id: created.id, + name: "mcp-upd-cred-partial-new", + }); + const updated = JSON.parse( + (rpc.result as { content: { text: string }[] }).content[0].text, + ) as { name: string; data: string }; + expect(updated.name).toBe("mcp-upd-cred-partial-new"); + expect(updated.data).toBe('{"k":1}'); + }); + + it("returns an MCP error for a non-existent credential id", async () => { + const { status, rpc } = await mcpCall("update_credential", { + id: "00000000-0000-0000-0000-000000000000", + name: "Ghost", + }); + expect(status).toBe(200); + const result = rpc.result as { isError: boolean }; + expect(result.isError).toBe(true); + }); + }); + + describe("delete_credential", () => { + it("deletes an existing credential and confirms deletion", async () => { + const created = await createCredential("mcp-del-cred"); + const { status, rpc } = await mcpCall("delete_credential", { + id: created.id, + }); + expect(status).toBe(200); + const result = rpc.result as { content: { text: string }[] }; + expect(result.content[0].text).toContain(created.id); + + const getResult = (await mcpCall("get_credential", { id: created.id })) + .rpc.result as { isError: boolean }; + expect(getResult.isError).toBe(true); + }); + + it("returns an MCP error for a non-existent credential id", async () => { + const { status, rpc } = await mcpCall("delete_credential", { + id: "00000000-0000-0000-0000-000000000000", + }); + expect(status).toBe(200); + const result = rpc.result as { isError: boolean }; + expect(result.isError).toBe(true); + }); + }); });