Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

XinyueDu
Copy link
Contributor

@XinyueDu XinyueDu commented Jun 6, 2025

入参校验结果
思维导图:
image

流程图:
image

@@ -12,7 +12,6 @@ import {
startStdioMcpServer,
} from "./services";
import { ChartTypeMapping, generateChartUrl } from "./utils";

Copy link
Member

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);
Copy link
Member

@hustcc hustcc Jun 6, 2025

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;
Copy link
Member

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), {
Copy link
Member

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) => {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释描述一下校验的规则有哪些?

  1. xxx
  2. yyyy
  3. zzz

const nodeNames = new Set(data.data.nodes.map((node) => node.name));
const errors: string[] = [];

const uniqueNodeNames = new Set();
Copy link
Member

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);
Copy link
Member

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名叫 validator,名词。

@hustcc
Copy link
Member

hustcc commented Jun 6, 2025

检测一下 treemap 是否也需要检测?另外增加一些校验不通过的规则的单测。

@hustcc
Copy link
Member

hustcc commented Jun 6, 2025

image

错误前缀有重复。

@hustcc hustcc changed the title Validated mind and network feat: json schema valid for mind-map, network... Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants