fix: prevent crash when invalid OpenAPI spec is loaded for tool servers (#20257)

* enh

* fix
This commit is contained in:
Classic298 2025-12-30 15:02:56 +01:00 committed by GitHub
parent 935808f5ea
commit 697e94e935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View file

@ -379,6 +379,13 @@ export const getToolServersData = async (servers: object[]) => {
} }
if (res) { if (res) {
if (!res.paths) {
return {
error: 'Invalid OpenAPI spec',
url: server?.url
};
}
const { openapi, info, specs } = { const { openapi, info, specs } = {
openapi: res, openapi: res,
info: res.info, info: res.info,

View file

@ -1249,6 +1249,11 @@ function resolveSchema(schemaRef, components, resolvedSchemas = new Set()) {
export const convertOpenApiToToolPayload = (openApiSpec) => { export const convertOpenApiToToolPayload = (openApiSpec) => {
const toolPayload = []; const toolPayload = [];
// Guard against invalid or non-OpenAPI specs (e.g., MCP-style configs)
if (!openApiSpec || !openApiSpec.paths) {
return toolPayload;
}
for (const [path, methods] of Object.entries(openApiSpec.paths)) { for (const [path, methods] of Object.entries(openApiSpec.paths)) {
for (const [method, operation] of Object.entries(methods)) { for (const [method, operation] of Object.entries(methods)) {
if (operation?.operationId) { if (operation?.operationId) {