Skip to content

Commit 2ba1515

Browse files
author
延枚
committed
Add tag MCP tools for flow operations
Change-Id: I79a5329b2d71d421d1b9da1fa244f5453845b86a Co-developed-by: iFlow <[email protected]>
1 parent de15454 commit 2ba1515

File tree

7 files changed

+480
-3
lines changed

7 files changed

+480
-3
lines changed

common/types.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,20 @@ export {
131131
CreateResourceMemberSchema,
132132
UpdateResourceOwnerSchema,
133133
ResourceMemberSchema,
134-
ResourceMemberBaseSchema
134+
ResourceMemberBaseSchema,
135+
136+
// Tag schemas
137+
CreateTagSchema,
138+
CreateTagGroupSchema,
139+
DeleteTagGroupSchema,
140+
UpdateTagGroupSchema,
141+
DeleteTagSchema,
142+
UpdateTagSchema,
143+
GetTagGroupSchema,
144+
TagGroupSchema,
145+
TagSchema,
146+
TagGroupWithTagsSchema,
147+
BaseTagSchema
135148
} from "../operations/flow/types.js";
136149

137150
// Packages types

operations/flow/tag.ts

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
import * as utils from "../../common/utils.js";
2+
import { z } from "zod";
3+
4+
// 定义标签和标签分类的Zod模式
5+
export const TagGroupSchema = z.object({
6+
id: z.number().int().nullable().optional().describe("标签分类 id"),
7+
name: z.string().nullable().optional().describe("标签分类名称"),
8+
creatorAccountId: z.string().nullable().optional().describe("创建人"),
9+
modifierAccountId: z.string().nullable().optional().describe("更新人"),
10+
});
11+
12+
export const TagSchema = z.object({
13+
id: z.number().int().nullable().optional().describe("标签 id"),
14+
name: z.string().nullable().optional().describe("标签名称"),
15+
color: z.string().nullable().optional().describe("标签颜色"),
16+
creatorAccountId: z.string().nullable().optional().describe("创建人"),
17+
modifierAccountId: z.string().nullable().optional().describe("更新人"),
18+
});
19+
20+
export const TagGroupWithTagsSchema = TagGroupSchema.extend({
21+
flowTagList: z.array(TagSchema).nullable().optional().describe("标签列表"),
22+
});
23+
24+
// 定义API请求参数的Zod模式
25+
export const BaseTagSchema = z.object({
26+
organizationId: z.string().describe("企业Id"),
27+
});
28+
29+
export const CreateTagSchema = BaseTagSchema.extend({
30+
name: z.string().describe("标签名称"),
31+
color: z.string().describe("#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色"),
32+
flowTagGroupId: z.number().int().describe("标签分类 id"),
33+
});
34+
35+
export const CreateTagGroupSchema = BaseTagSchema.extend({
36+
name: z.string().describe("标签分类名称"),
37+
});
38+
39+
export const DeleteTagGroupSchema = BaseTagSchema.extend({
40+
id: z.number().int().describe("标签分类 id"),
41+
});
42+
43+
export const UpdateTagGroupSchema = DeleteTagGroupSchema.extend({
44+
name: z.string().describe("标签分类名称"),
45+
});
46+
47+
export const DeleteTagSchema = BaseTagSchema.extend({
48+
id: z.number().int().describe("标签 id"),
49+
});
50+
51+
export const UpdateTagSchema = DeleteTagSchema.extend({
52+
name: z.string().describe("标签名称"),
53+
color: z.string().describe("#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色"),
54+
flowTagGroupId: z.number().int().describe("标签分类 id"),
55+
});
56+
57+
export const GetTagGroupSchema = DeleteTagGroupSchema;
58+
59+
// 定义类型
60+
export type TagGroup = z.infer<typeof TagGroupSchema>;
61+
export type Tag = z.infer<typeof TagSchema>;
62+
export type TagGroupWithTags = z.infer<typeof TagGroupWithTagsSchema>;
63+
export type CreateTagParams = z.infer<typeof CreateTagSchema>;
64+
export type CreateTagGroupParams = z.infer<typeof CreateTagGroupSchema>;
65+
export type DeleteTagGroupParams = z.infer<typeof DeleteTagGroupSchema>;
66+
export type UpdateTagGroupParams = z.infer<typeof UpdateTagGroupSchema>;
67+
export type DeleteTagParams = z.infer<typeof DeleteTagSchema>;
68+
export type UpdateTagParams = z.infer<typeof UpdateTagSchema>;
69+
export type GetTagGroupParams = z.infer<typeof GetTagGroupSchema>;
70+
71+
/**
72+
* 创建标签
73+
* @param organizationId 企业Id
74+
* @param name 标签名称
75+
* @param color 标签颜色
76+
* @param flowTagGroupId 标签分类 id
77+
* @returns 标签 id
78+
*/
79+
export async function createTagFunc(
80+
organizationId: string,
81+
name: string,
82+
color: string,
83+
flowTagGroupId: number
84+
): Promise<number> {
85+
const url = `/oapi/v1/flow/organizations/${organizationId}/tags`;
86+
87+
const queryParams = { name, color, flowTagGroupId };
88+
const fullUrl = utils.buildUrl(url, queryParams);
89+
90+
const response = await utils.yunxiaoRequest(fullUrl, {
91+
method: "POST",
92+
});
93+
94+
return Number(response);
95+
}
96+
97+
/**
98+
* 创建标签分类
99+
* @param organizationId 企业Id
100+
* @param name 标签分类名称
101+
* @returns 标签分类 id
102+
*/
103+
export async function createTagGroupFunc(
104+
organizationId: string,
105+
name: string
106+
): Promise<number> {
107+
const url = `/oapi/v1/flow/organizations/${organizationId}/tagGroups`;
108+
109+
const queryParams = { name };
110+
const fullUrl = utils.buildUrl(url, queryParams);
111+
112+
const response = await utils.yunxiaoRequest(fullUrl, {
113+
method: "POST",
114+
});
115+
116+
return Number(response);
117+
}
118+
119+
/**
120+
* 获取流水线分类列表
121+
* @param organizationId 企业Id
122+
* @returns 流水线分类列表
123+
*/
124+
export async function listTagGroupsFunc(
125+
organizationId: string
126+
): Promise<TagGroup[]> {
127+
const url = `/oapi/v1/flow/organizations/${organizationId}/tagGroups`;
128+
129+
const response = await utils.yunxiaoRequest(url, {
130+
method: "GET",
131+
});
132+
133+
if (Array.isArray(response)) {
134+
return response.map(item => TagGroupSchema.parse(item));
135+
}
136+
137+
return [];
138+
}
139+
140+
/**
141+
* 删除标签分类
142+
* @param organizationId 企业Id
143+
* @param id 标签分类 id
144+
* @returns 是否成功
145+
*/
146+
export async function deleteTagGroupFunc(
147+
organizationId: string,
148+
id: number
149+
): Promise<boolean> {
150+
const url = `/oapi/v1/flow/organizations/${organizationId}/tagGroups/${id}`;
151+
152+
const response = await utils.yunxiaoRequest(url, {
153+
method: "DELETE",
154+
});
155+
156+
return Boolean(response);
157+
}
158+
159+
/**
160+
* 更新标签分类
161+
* @param organizationId 企业Id
162+
* @param id 标签分类 id
163+
* @param name 标签分类名称
164+
* @returns 是否成功
165+
*/
166+
export async function updateTagGroupFunc(
167+
organizationId: string,
168+
id: number,
169+
name: string
170+
): Promise<boolean> {
171+
const url = `/oapi/v1/flow/organizations/${organizationId}/tagGroups/${id}`;
172+
173+
const queryParams = { name };
174+
const fullUrl = utils.buildUrl(url, queryParams);
175+
176+
const response = await utils.yunxiaoRequest(fullUrl, {
177+
method: "PUT",
178+
});
179+
180+
return Boolean(response);
181+
}
182+
183+
/**
184+
* 获取标签分类
185+
* @param organizationId 企业Id
186+
* @param id 标签分类 id
187+
* @returns 标签分类
188+
*/
189+
export async function getTagGroupFunc(
190+
organizationId: string,
191+
id: number
192+
): Promise<TagGroupWithTags> {
193+
const url = `/oapi/v1/flow/organizations/${organizationId}/tagGroups/${id}`;
194+
195+
const response = await utils.yunxiaoRequest(url, {
196+
method: "GET",
197+
});
198+
199+
return TagGroupWithTagsSchema.parse(response);
200+
}
201+
202+
/**
203+
* 删除标签
204+
* @param organizationId 企业Id
205+
* @param id 标签 id
206+
* @returns 是否成功
207+
*/
208+
export async function deleteTagFunc(
209+
organizationId: string,
210+
id: number
211+
): Promise<boolean> {
212+
const url = `/oapi/v1/flow/organizations/${organizationId}/tags/${id}`;
213+
214+
const response = await utils.yunxiaoRequest(url, {
215+
method: "DELETE",
216+
});
217+
218+
return Boolean(response);
219+
}
220+
221+
/**
222+
* 更新标签
223+
* @param organizationId 企业Id
224+
* @param id 标签 id
225+
* @param name 标签名称
226+
* @param color 标签颜色
227+
* @param flowTagGroupId 标签分类 id
228+
* @returns 是否成功
229+
*/
230+
export async function updateTagFunc(
231+
organizationId: string,
232+
id: number,
233+
name: string,
234+
color: string,
235+
flowTagGroupId: number
236+
): Promise<boolean> {
237+
const url = `/oapi/v1/flow/organizations/${organizationId}/tags/${id}`;
238+
239+
const queryParams = { name, color, flowTagGroupId };
240+
const fullUrl = utils.buildUrl(url, queryParams);
241+
242+
const response = await utils.yunxiaoRequest(fullUrl, {
243+
method: "PUT",
244+
});
245+
246+
return Boolean(response);
247+
}

operations/flow/types.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,73 @@ export type UpdateResourceMemberParams = z.infer<typeof UpdateResourceMemberSche
462462
export type CreateResourceMemberParams = z.infer<typeof CreateResourceMemberSchema>;
463463
export type UpdateResourceOwnerParams = z.infer<typeof UpdateResourceOwnerSchema>;
464464

465+
// Tag schemas
466+
export const TagGroupSchema = z.object({
467+
id: z.number().int().nullable().optional().describe("标签分类 id"),
468+
name: z.string().nullable().optional().describe("标签分类名称"),
469+
creatorAccountId: z.string().nullable().optional().describe("创建人"),
470+
modifierAccountId: z.string().nullable().optional().describe("更新人"),
471+
});
472+
473+
export const TagSchema = z.object({
474+
id: z.number().int().nullable().optional().describe("标签 id"),
475+
name: z.string().nullable().optional().describe("标签名称"),
476+
color: z.string().nullable().optional().describe("标签颜色"),
477+
creatorAccountId: z.string().nullable().optional().describe("创建人"),
478+
modifierAccountId: z.string().nullable().optional().describe("更新人"),
479+
});
480+
481+
export const TagGroupWithTagsSchema = TagGroupSchema.extend({
482+
flowTagList: z.array(TagSchema).nullable().optional().describe("标签列表"),
483+
});
484+
485+
// Define base schema for common parameters
486+
export const BaseTagSchema = z.object({
487+
organizationId: z.string().describe("企业Id"),
488+
});
489+
490+
export const CreateTagSchema = BaseTagSchema.extend({
491+
name: z.string().describe("标签名称"),
492+
color: z.string().describe("#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色"),
493+
flowTagGroupId: z.number().int().describe("标签分类 id"),
494+
});
495+
496+
export const CreateTagGroupSchema = BaseTagSchema.extend({
497+
name: z.string().describe("标签分类名称"),
498+
});
499+
500+
export const DeleteTagGroupSchema = BaseTagSchema.extend({
501+
id: z.number().int().describe("标签分类 id"),
502+
});
503+
504+
export const UpdateTagGroupSchema = DeleteTagGroupSchema.extend({
505+
name: z.string().describe("标签分类名称"),
506+
});
507+
508+
export const DeleteTagSchema = BaseTagSchema.extend({
509+
id: z.number().int().describe("标签 id"),
510+
});
511+
512+
export const UpdateTagSchema = DeleteTagSchema.extend({
513+
name: z.string().describe("标签名称"),
514+
color: z.string().describe("#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色"),
515+
flowTagGroupId: z.number().int().describe("标签分类 id"),
516+
});
517+
518+
export const GetTagGroupSchema = DeleteTagGroupSchema;
519+
520+
// Tag type exports
521+
export type TagGroup = z.infer<typeof TagGroupSchema>;
522+
export type Tag = z.infer<typeof TagSchema>;
523+
export type TagGroupWithTags = z.infer<typeof TagGroupWithTagsSchema>;
524+
export type CreateTagParams = z.infer<typeof CreateTagSchema>;
525+
export type CreateTagGroupParams = z.infer<typeof CreateTagGroupSchema>;
526+
export type DeleteTagGroupParams = z.infer<typeof DeleteTagGroupSchema>;
527+
export type UpdateTagGroupParams = z.infer<typeof UpdateTagGroupSchema>;
528+
export type DeleteTagParams = z.infer<typeof DeleteTagSchema>;
529+
export type UpdateTagParams = z.infer<typeof UpdateTagSchema>;
530+
export type GetTagGroupParams = z.infer<typeof GetTagGroupSchema>;
531+
465532
// Flow type exports
466533
export type PipelineDetail = z.infer<typeof PipelineDetailSchema>;
467534
export type PipelineListItem = z.infer<typeof PipelineListItemSchema>;

tool-handlers/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { handleAppStackDeploymentResourceTools } from './appstack-deployment-res
1515
import { handleAppStackChangeOrderTools } from './appstack-change-orders.js';
1616
import { handleEffortTools } from './effort.js';
1717
import { handleResourceMemberTools } from './resourceMember.js';
18+
import { handleTagTools } from './tag.js';
1819

1920
export const handleToolRequest = async (request: any) => {
2021
// Try each handler in sequence until one returns a result
@@ -35,7 +36,8 @@ export const handleToolRequest = async (request: any) => {
3536
handleAppStackDeploymentResourceTools,
3637
handleAppStackChangeOrderTools,
3738
handleEffortTools,
38-
handleResourceMemberTools
39+
handleResourceMemberTools,
40+
handleTagTools
3941
];
4042

4143
for (const handler of handlers) {

0 commit comments

Comments
 (0)