Skip to content

Commit 2a7eb96

Browse files
authored
Fail production builds on MCPMetadata fetch errors (#190)
* Run thv version to verify installation * Fail production builds if MCPMetadata fetch fails * Revert temporary fix --------- Signed-off-by: Dan Barr <[email protected]> Co-authored-by: Dan Barr <[email protected]>
1 parent dca5cf3 commit 2a7eb96

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

docusaurus.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const config: Config = {
2323
'./plugins/mcp-metadata-plugin',
2424
{
2525
thvCommand: 'thv', // Can be customized if thv is in a different path
26+
failOnError:
27+
process.env.NODE_ENV === 'production' || process.env.CI === 'true',
2628
},
2729
],
2830
],

plugins/mcp-metadata-plugin/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function mcpMetadataPlugin(
1414
context: LoadContext,
1515
options: PluginOptions = {}
1616
): Plugin<PluginContent> {
17-
const { thvCommand = 'thv' } = options;
17+
const { thvCommand = 'thv', failOnError = false } = options;
1818

1919
return {
2020
name: 'mcp-metadata-plugin',
@@ -53,6 +53,11 @@ export default function mcpMetadataPlugin(
5353
`Failed to fetch data for MCP server: ${serverName}`,
5454
error
5555
);
56+
57+
if (failOnError) {
58+
throw error; // This will fail the build
59+
}
60+
5661
// Store error message as fallback
5762
serverData[serverName] = `# Error fetching data for ${serverName}
5863
# ${error.message}

plugins/mcp-metadata-plugin/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
export interface PluginOptions {
55
thvCommand?: string; // Custom thv command path
6+
failOnError?: boolean; // Whether to fail the build on thv command errors
67
}
78

89
export interface PluginContent {

scripts/install-thv.sh

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,23 @@ if ! command -v jq >/dev/null 2>&1; then
1313
exit 1
1414
fi
1515

16-
#API_ENDPOINT="https://api.github.com/repos/stacklok/toolhive/releases/latest"
16+
API_ENDPOINT="https://api.github.com/repos/stacklok/toolhive/releases/latest"
1717

1818
# Fetch release information
19-
#RELEASE_JSON=$(curl -sf "$API_ENDPOINT" || {
20-
# echo "Failed to fetch release information from GitHub API"
21-
# exit 1
22-
#})
23-
#RELEASE_VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name // empty' | sed 's/^v//')
24-
#RELEASE_TARBALL=$(echo "$RELEASE_JSON" | jq -r \
25-
# --arg version "$RELEASE_VERSION" \
26-
# '.assets[] | select(.name == "toolhive_" + $version + "_linux_amd64.tar.gz") | .browser_download_url // empty')
27-
28-
#if [ -z "$RELEASE_TARBALL" ]; then
29-
# echo "Failed to get release tarball URL for release: ${RELEASE_VERSION}"
30-
# echo "Please check if the tag exists in the repository"
31-
# exit 1
32-
#fi
33-
34-
# Temporary fix for early exit if container runtime isn't found
19+
RELEASE_JSON=$(curl -sf "$API_ENDPOINT" || {
20+
echo "Failed to fetch release information from GitHub API"
21+
exit 1
22+
})
23+
RELEASE_VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name // empty' | sed 's/^v//')
24+
RELEASE_TARBALL=$(echo "$RELEASE_JSON" | jq -r \
25+
--arg version "$RELEASE_VERSION" \
26+
'.assets[] | select(.name == "toolhive_" + $version + "_linux_amd64.tar.gz") | .browser_download_url // empty')
3527

36-
RELEASE_VERSION="v0.2.17"
37-
RELEASE_TARBALL="https://github.com/stacklok/toolhive/releases/download/v0.2.17/toolhive_0.2.17_linux_amd64.tar.gz"
28+
if [ -z "$RELEASE_TARBALL" ]; then
29+
echo "Failed to get release tarball URL for release: ${RELEASE_VERSION}"
30+
echo "Please check if the tag exists in the repository"
31+
exit 1
32+
fi
3833

3934
# Determine installation location based on write permissions
4035
if [[ -w "/usr/local/bin" ]]; then
@@ -72,5 +67,9 @@ chmod +x /tmp/thv
7267
cp /tmp/thv "$INSTALL_DIR/thv"
7368
rm -f /tmp/toolhive.tar.gz /tmp/thv
7469

75-
echo "ToolHive CLI (thv) installed successfully. Version: $RELEASE_VERSION"
76-
echo "The 'thv' command is now available in your PATH."
70+
thv version || {
71+
echo "Installation failed: 'thv' command is not working."
72+
exit 1
73+
}
74+
75+
echo "ToolHive CLI (thv) installed successfully."

0 commit comments

Comments
 (0)