-
Notifications
You must be signed in to change notification settings - Fork 74
feat: json schema valid for mind-map, network... #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -12,7 +12,6 @@ import { | |||
startStdioMcpServer, | |||
} from "./services"; | |||
import { ChartTypeMapping, generateChartUrl } from "./utils"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这类空行一般还是保留的。
@@ -77,7 +77,17 @@ function setupToolHandlers(server: Server): void { | |||
} | |||
} | |||
|
|||
const url = await generateChartUrl(chartType, args); | |||
const res = await generateChartUrl(chartType, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的改法,应该是在 generateChartUrl 方法中 throw error 会被这个大的 try catch 到。然后返回值还是保持返回 url,
@@ -29,5 +33,5 @@ export async function generateChartUrl( | |||
}, | |||
); | |||
|
|||
return response.data.resultObj; | |||
return response.data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法加判断 success = 0 的情况,然后 throw new Error('xxxx')
width: WidthSchema, | ||
height: HeightSchema, | ||
}) | ||
.refine((data) => validatedFlowNetWorkSchema(data), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 refine 可以加到 data 那一层。
* @param data | ||
* @returns boolean | ||
*/ | ||
export const validatedFlowNetWorkSchema = (data: FlowAndNetWorkOption) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
校验 data 即可,然后数据分成为两类,以内是 TreeData,一类的 NodeEdgeData。这么看,也需要看看矩阵树图的校验。
height: number; | ||
} | ||
/** | ||
* validatedFlowNetWorkSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释描述一下校验的规则有哪些?
- xxx
- yyyy
- zzz
const nodeNames = new Set(data.data.nodes.map((node) => node.name)); | ||
const errors: string[] = []; | ||
|
||
const uniqueNodeNames = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
发现一个错误就跳过,不用发现所有的错误,这样逻辑简单一些。error message 一定需要模型能理解和修正。
`Invalid parameters: ${errors.join("")}`, | ||
); | ||
} | ||
return !(errors.length > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一样的,只要有发现一个,就 throw,代码终止。
@@ -0,0 +1,97 @@ | |||
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文件名叫 validator,名词。
检测一下 treemap 是否也需要检测?另外增加一些校验不通过的规则的单测。 |
入参校验结果

思维导图:
流程图:
