Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions e2e/mcp/api/component.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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 }
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/scene/component-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/api/scene/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ComponentApi {
@result(SchemaBooleanResult)
async removeComponent(@param(SchemaRemoveComponent) component: TRemoveComponentOptions): Promise<CommonResultType<boolean>> {
try {
const result = await Scene.Component.remove(component);
const result = await Scene.Component.remove({ path: component.componentPath });
return {
code: COMMON_STATUS.SUCCESS,
data: result
Expand All @@ -75,9 +75,9 @@ export class ComponentApi {
@result(SchemaComponentResult)
async queryComponent(@param(SchemaQueryComponent) component: TQueryComponentOptions): Promise<CommonResultType<TComponentResult | null>> {
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,
Expand Down
2 changes: 1 addition & 1 deletion tests/bug-497-api-error-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading