diff --git a/e2e/mcp/api/component.e2e.test.ts b/e2e/mcp/api/component.e2e.test.ts index 01c6f94b4..f3295d6a3 100644 --- a/e2e/mcp/api/component.e2e.test.ts +++ b/e2e/mcp/api/component.e2e.test.ts @@ -108,7 +108,7 @@ describe('MCP Component API', () => { // 查询组件 const queryResult = await mcpClient.callTool('scene-query-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); expect(queryResult.code).toBe(200); expect(queryResult.data).toBeDefined(); @@ -135,7 +135,7 @@ describe('MCP Component API', () => { // 查询组件初始属性 const queryResult = await mcpClient.callTool('scene-query-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); expect(queryResult.code).toBe(200); expect(queryResult.data).toBeDefined(); @@ -155,7 +155,7 @@ describe('MCP Component API', () => { // 验证属性已更改 const queryAfterSet = await mcpClient.callTool('scene-query-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); expect(queryAfterSet.code).toBe(200); expect(queryAfterSet.data).toBeDefined(); @@ -178,13 +178,13 @@ describe('MCP Component API', () => { // 删除组件 const deleteResult = await mcpClient.callTool('scene-delete-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); expect(deleteResult.code).toBe(200); // 验证组件已删除 - 查询应该返回null或失败 const queryAfterDelete = await mcpClient.callTool('scene-query-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); // 组件删除后查询应该失败或返回null expect(queryAfterDelete.code).not.toBe(200); @@ -212,7 +212,7 @@ describe('MCP Component API', () => { // 验证组件已添加 const queryResult = await mcpClient.callTool('scene-query-component', { - component: { path: addResult.data.path } + component: { componentPath: addResult.data.path } }); expect(queryResult.code).toBe(200); expect(queryResult.data).toBeDefined(); @@ -223,7 +223,7 @@ describe('MCP Component API', () => { // 清理添加的组件 for (const componentPath of addedComponents) { await mcpClient.callTool('scene-delete-component', { - component: { path: componentPath } + component: { componentPath: componentPath } }); } }); diff --git a/src/api/scene/component-schema.ts b/src/api/scene/component-schema.ts index d34dc3b28..9a1fb4f32 100644 --- a/src/api/scene/component-schema.ts +++ b/src/api/scene/component-schema.ts @@ -11,12 +11,12 @@ export const SchemaAddComponentInfo = z.object({ // Remove component // 移除组件 export const SchemaRemoveComponent = z.object({ - path: z.string().describe('Component path = node path + "/" + component type name, e.g. "Canvas/Node1/cc.Label" or "Canvas/Node1/cc.Sprite". Must end with the component type (e.g. cc.Label, cc.Sprite). Do NOT pass a bare node path like "Canvas/Node1".'), // 组件路径 = 节点路径 + "/" + 组件类型名称 + componentPath: z.string().describe('Component path = node path + "/" + component type name, e.g. "Canvas/Node1/cc.Label" or "Canvas/Node1/cc.Sprite". Must end with the component type (e.g. cc.Label, cc.Sprite). Do NOT pass a bare node path like "Canvas/Node1".'), // 组件路径 = 节点路径 + "/" + 组件类型名称 }).describe('Information required to remove a component'); // 移除组件需要的信息 // Query component // 查询组件 export const SchemaQueryComponent = z.object({ - path: z.string().describe('Component path = node path + "/" + component type name, e.g. "Canvas/Node1/cc.Label" or "Canvas/Node1/cc.Sprite". Must end with the component type (e.g. cc.Label, cc.Sprite). Do NOT pass a bare node path like "Canvas/Node1".'), // 组件路径 = 节点路径 + "/" + 组件类型名称 + componentPath: z.string().describe('Component path = node path + "/" + component type name, e.g. "Canvas/Node1/cc.Label" or "Canvas/Node1/cc.Sprite". Must end with the component type (e.g. cc.Label, cc.Sprite). Do NOT pass a bare node path like "Canvas/Node1".'), // 组件路径 = 节点路径 + "/" + 组件类型名称 }).describe('Information required to query a component'); // 查询组件需要的信息 // Vec2 diff --git a/src/api/scene/component.ts b/src/api/scene/component.ts index c4f0c13a3..94d11fe86 100644 --- a/src/api/scene/component.ts +++ b/src/api/scene/component.ts @@ -53,7 +53,7 @@ export class ComponentApi { @result(SchemaBooleanResult) async removeComponent(@param(SchemaRemoveComponent) component: TRemoveComponentOptions): Promise> { try { - const result = await Scene.Component.remove(component); + const result = await Scene.Component.remove({ path: component.componentPath }); return { code: COMMON_STATUS.SUCCESS, data: result @@ -75,9 +75,9 @@ export class ComponentApi { @result(SchemaComponentResult) async queryComponent(@param(SchemaQueryComponent) component: TQueryComponentOptions): Promise> { try { - const componentInfo = await Scene.Component.query(component); + const componentInfo = await Scene.Component.query({ path: component.componentPath }); if (!componentInfo) { - throw new Error(`component not found: ${component.path}`); + throw new Error(`component not found: ${component.componentPath}`); } return { code: COMMON_STATUS.SUCCESS, diff --git a/tests/bug-497-api-error-status.test.ts b/tests/bug-497-api-error-status.test.ts index 09226ca28..94a0ea33e 100644 --- a/tests/bug-497-api-error-status.test.ts +++ b/tests/bug-497-api-error-status.test.ts @@ -342,7 +342,7 @@ describe('Bug #497 common API error status codes', () => { it('returns 404 when a queried component is not found', async () => { mockComponentQuery.mockResolvedValue(null); - const result = await new ComponentApi().queryComponent({ path: 'Canvas/Missing/cc.Label' }); + const result = await new ComponentApi().queryComponent({ componentPath: 'Canvas/Missing/cc.Label' }); expect(result.code).toBe(HTTP_STATUS.NOT_FOUND); expect(result.reason).toBe('component not found: Canvas/Missing/cc.Label');