feat(server): MCP 工具参数运行时校验与统一错误处理
This commit is contained in:
1 parent
49693bdbd7
commit
31c2a112de
2 files changed
+96
-31
No files matched your search
@@ -5,17 +5,28 @@ import { CorpConfig, CorpConfigSchema } from "./types";
|
||||
const ENTERPRISES_DIR = "./enterprises";
|
||||
|
||||
export function loadCorpConfigs(): CorpConfig[] {
|
||||
let files: string[];
|
||||
try {
|
||||
const files = readdirSync(ENTERPRISES_DIR).filter((f) =>
|
||||
f.endsWith(".json")
|
||||
files = readdirSync(ENTERPRISES_DIR).filter((f) => f.endsWith(".json"));
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[config] failed to read enterprises directory: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
|
||||
return files.map((file) => {
|
||||
const content = readFileSync(join(ENTERPRISES_DIR, file), "utf-8");
|
||||
const parsed = JSON.parse(content);
|
||||
return CorpConfigSchema.parse(parsed);
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
const configs: CorpConfig[] = [];
|
||||
for (const file of files) {
|
||||
try {
|
||||
const content = readFileSync(join(ENTERPRISES_DIR, file), "utf-8");
|
||||
const parsed = JSON.parse(content);
|
||||
configs.push(CorpConfigSchema.parse(parsed));
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[config] failed to load ${file}: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
Reference in new issue
Block a user