Skip to content

Commit f16e32b

Browse files
toreleonCopilot
andauthored
Update src/mcphub/mcp_servers/params.py
Co-authored-by: Copilot <[email protected]>
1 parent 8ef4c52 commit f16e32b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/mcphub/mcp_servers/params.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,29 @@ def _parse_readme_with_openai(self, readme_content: str) -> Dict:
102102
103103
Return only the JSON configuration, nothing else."""
104104

105-
response = self.openai_client.responses.parse(
106-
model="gpt-4o-mini",
107-
input=[
108-
{"role": "system", "content": "You are a helpful assistant that extracts MCP server configuration from READMEs."},
109-
{"role": "user", "content": prompt}
110-
],
111-
text_format=MCPServerConfigSchema
112-
)
113105
try:
106+
response = self.openai_client.responses.parse(
107+
model="gpt-4o-mini",
108+
input=[
109+
{"role": "system", "content": "You are a helpful assistant that extracts MCP server configuration from READMEs."},
110+
{"role": "user", "content": prompt}
111+
],
112+
text_format=MCPServerConfigSchema
113+
)
114+
# Validate response structure
115+
if not hasattr(response, "output_parsed") or not hasattr(response.output_parsed, "model_dump"):
116+
raise ValueError("Unexpected OpenAI API response format")
114117
config = response.output_parsed.model_dump()
115118
return config
116-
except json.JSONDecodeError:
117-
raise ValueError("Failed to parse OpenAI response as JSON")
119+
except json.JSONDecodeError as e:
120+
# Log the problematic response content for debugging
121+
raise ValueError(f"Failed to parse OpenAI response as JSON: {e}")
122+
except openai.error.OpenAIError as e:
123+
# Log OpenAI-specific errors
124+
raise RuntimeError(f"OpenAI API error: {e}")
125+
except Exception as e:
126+
# Catch-all for any other unexpected exceptions
127+
raise RuntimeError(f"Unexpected error while parsing OpenAI response: {e}")
118128

119129
def add_server_from_repo(self, server_name: str, repo_url: str) -> None:
120130
"""Add a new server configuration by analyzing its GitHub repository README."""

0 commit comments

Comments
 (0)