Skip to content
Open
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
24 changes: 12 additions & 12 deletions e2e/mcp/api/component.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('MCP Component API', () => {
const addResult = await mcpClient.callTool('scene-add-component', {
addComponentInfo: {
nodePath: testNodePath,
componentNameOrUuidOrUrl: 'cc.Label',
component: 'cc.Label',
},
});
expect(addResult.code).toBe(200);
Expand All @@ -97,7 +97,7 @@ describe('MCP Component API', () => {
const addResult = await mcpClient.callTool('scene-add-component', {
addComponentInfo: {
nodePath: testNodePath,
componentNameOrUuidOrUrl: 'cc.Label',
component: 'cc.Label',
},
});
expect(addResult.code).toBe(200);
Expand All @@ -108,7 +108,7 @@ describe('MCP Component API', () => {

// 查询组件
const queryResult = await mcpClient.callTool('scene-query-component', {
component: { pathOrUuidOrUrl: componentPath }
component: { path: componentPath }
});
expect(queryResult.code).toBe(200);
expect(queryResult.data).toBeDefined();
Expand All @@ -124,7 +124,7 @@ describe('MCP Component API', () => {
const addResult = await mcpClient.callTool('scene-add-component', {
addComponentInfo: {
nodePath: testNodePath,
componentNameOrUuidOrUrl: 'cc.Label',
component: 'cc.Label',
},
});
expect(addResult.code).toBe(200);
Expand All @@ -135,7 +135,7 @@ describe('MCP Component API', () => {

// 查询组件初始属性
const queryResult = await mcpClient.callTool('scene-query-component', {
component: { pathOrUuidOrUrl: componentPath }
component: { path: 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: { pathOrUuidOrUrl: componentPath }
component: { path: componentPath }
});
expect(queryAfterSet.code).toBe(200);
expect(queryAfterSet.data).toBeDefined();
Expand All @@ -168,7 +168,7 @@ describe('MCP Component API', () => {
const addResult = await mcpClient.callTool('scene-add-component', {
addComponentInfo: {
nodePath: testNodePath,
componentNameOrUuidOrUrl: 'cc.Label',
component: 'cc.Label',
},
});
expect(addResult.code).toBe(200);
Expand All @@ -178,13 +178,13 @@ describe('MCP Component API', () => {

// 删除组件
const deleteResult = await mcpClient.callTool('scene-delete-component', {
component: { pathOrUuidOrUrl: componentPath }
component: { path: componentPath }
});
expect(deleteResult.code).toBe(200);

// 验证组件已删除 - 查询应该返回null或失败
const queryAfterDelete = await mcpClient.callTool('scene-query-component', {
component: { pathOrUuidOrUrl: componentPath }
component: { path: componentPath }
});
// 组件删除后查询应该失败或返回null
expect(queryAfterDelete.code).not.toBe(200);
Expand All @@ -201,7 +201,7 @@ describe('MCP Component API', () => {
const addResult = await mcpClient.callTool('scene-add-component', {
addComponentInfo: {
nodePath: testNodePath,
componentNameOrUuidOrUrl: componentType,
component: componentType,
},
});
expect(addResult.code).toBe(200);
Expand All @@ -212,7 +212,7 @@ describe('MCP Component API', () => {

// 验证组件已添加
const queryResult = await mcpClient.callTool('scene-query-component', {
component: { pathOrUuidOrUrl: addResult.data.path }
component: { path: 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: { pathOrUuidOrUrl: componentPath }
component: { path: componentPath }
});
}
});
Expand Down
7 changes: 3 additions & 4 deletions src/api/scene/component-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { SchemaCompPrefabInfo } from './prefab-info-schema';
// Create component information // 创建组件信息
export const SchemaAddComponentInfo = z.object({
nodePath: z.string().describe('Node path'), // 节点路径
//component: z.enum(Object.keys(globalComponentType) as [string, ...string[]]).describe('组件类型'),
componentNameOrUuidOrUrl: z.string().describe('Component name, supports component name, component resource URL and UUID'), // 组件名称,支持组件名称、组件资源的 URL 与 UUID
component: z.string().describe('Component name, supports component name, component resource URL and UUID'), // 组件名称,支持组件名称、组件资源的 URL 与 UUID
}).describe('Information for adding a component'); // 添加组件的信息

// Remove component // 移除组件
export const SchemaRemoveComponent = z.object({
pathOrUuidOrUrl: z.string().describe('Path, UUID or URL of the component'), // 组件的路径、uuid 或 url
path: z.string().describe('Path of the component, including node path'), // 组件的路径,包含节点路径
}).describe('Information required to remove a component'); // 移除组件需要的信息

// Query component // 查询组件
export const SchemaQueryComponent = z.object({
pathOrUuidOrUrl: z.string().describe('Path, UUID or URL of the component'), // 组件的路径、uuid 或 url
path: z.string().describe('Path of the component, including node path'), // 组件的路径,包含节点路径
}).describe('Information required to query a component'); // 查询组件需要的信息

// Vec2
Expand Down
4 changes: 2 additions & 2 deletions src/api/scene/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ComponentApi {
@result(SchemaComponentResult)
async addComponent(@param(SchemaAddComponentInfo) addComponentInfo: TAddComponentInfo): Promise<CommonResultType<TComponentResult>> {
try {
const component = await Scene.addComponent({ nodePathOrUuid: addComponentInfo.nodePath, component: addComponentInfo.componentNameOrUuidOrUrl });
const component = await Scene.addComponent({ nodePathOrUuid: addComponentInfo.nodePath, component: addComponentInfo.component });
return {
code: COMMON_STATUS.SUCCESS,
data: component
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ComponentApi {
try {
const componentInfo = await Scene.queryComponent(component);
if (!componentInfo) {
throw new Error(`component not found: ${component.pathOrUuidOrUrl}`);
throw new Error(`component not found: ${component.path}`);
}
return {
code: COMMON_STATUS.SUCCESS,
Expand Down
Loading
Loading