Merge pull request #51 from pcarion/fix-typescript-mcp-server-weather

update tool response in typescript weather sample to be compliant with spec
This commit is contained in:
David Soria Parra 2024-11-27 11:40:49 +00:00 • committed by GitHub
commit 9fd4c9d2a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -346,18 +346,18 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
} }
return { return {
content: { content: [{
mimeType: "application/json", type: "text",
text: JSON.stringify(forecasts, null, 2) text: JSON.stringify(forecasts, null, 2)
} }]
}; };
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
return { return {
content: { content: [{
mimeType: "text/plain", type: "text",
text: `Weather API error: ${error.response?.data.message ?? error.message}` text: `Weather API error: ${error.response?.data.message ?? error.message}`
}, }],
isError: true, isError: true,
} }
} }