From ba31fe79205fa01c6bad1d87baee43e233a3a748 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Sun, 15 Mar 2026 09:07:02 +0300 Subject: [PATCH] Add tests for MCP server makeFigma option Test that external FigmaAPI skips file lifecycle tools and allows tool execution without loading a document first. --- tests/engine/mcp-server.test.ts | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/engine/mcp-server.test.ts b/tests/engine/mcp-server.test.ts index 1910a0c2d..85ca68204 100644 --- a/tests/engine/mcp-server.test.ts +++ b/tests/engine/mcp-server.test.ts @@ -437,4 +437,53 @@ describe('MCP server', () => { await rm(rootDir, { recursive: true, force: true }) } }) + + test('createServer with makeFigma skips file lifecycle tools', async () => { + const graph = new SceneGraph() + const { FigmaAPI } = await import('@open-pencil/core') + const custom = await createLinkedClient({ + makeFigma: () => new FigmaAPI(graph) + }) + try { + const { tools } = await custom.client.listTools() + const names = tools.map((t) => t.name) + expect(names).not.toContain('open_file') + expect(names).not.toContain('save_file') + expect(names).not.toContain('new_document') + expect(names).toContain('create_shape') + expect(names).toContain('render') + expect(names).toContain('get_page_tree') + } finally { + await custom.close() + } + }) + + test('createServer with makeFigma can call tools without loading a document', async () => { + const graph = new SceneGraph() + const { FigmaAPI } = await import('@open-pencil/core') + const custom = await createLinkedClient({ + makeFigma: () => { + const api = new FigmaAPI(graph) + api.currentPage = api.wrapNode(graph.getPages()[0].id) + return api + } + }) + try { + const result = await custom.client.callTool({ + name: 'create_shape', + arguments: { type: 'RECTANGLE', x: 0, y: 0, width: 100, height: 50 } + }) + expect(result.isError).not.toBe(true) + const data = parseResult(result) as { id: string; type: string } + expect(data.type).toBe('RECTANGLE') + expect(data.id).toBeTruthy() + + const tree = await custom.client.callTool({ name: 'get_page_tree', arguments: {} }) + expect(tree.isError).not.toBe(true) + const treeData = parseResult(tree) as { children: { id: string }[] } + expect(treeData.children.some((c) => c.id === data.id)).toBe(true) + } finally { + await custom.close() + } + }) })