atxtechbro / atxtechbro/dotfiles

Add git hooks to prevent committing with unmatched curly braces in mcp.json

Open
#186 0 comments 0 reactions 0 assignees View on GitHub
enhancement git-hooks mcp
Dominant language
Shell
Stars
27
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## Problem

Currently, there's no validation when committing changes to `mcp.json` files. This can lead to syntax errors with unmatched curly braces that break MCP server configurations and cause runtime errors that are difficult to debug.

## Proposed Solution

Add a pre-commit git hook that validates JSON syntax in `mcp.json` files before allowing commits. This would:

1. Detect and prevent commits with malformed JSON
2. Specifically check for unmatched curly braces
3. Provide helpful error messages indicating the location of syntax errors

## Implementation Details

The git hook should:

- Be stored in the dotfiles repository at `.git-hooks/pre-commit`
- Be automatically installed by the setup script
- Use a simple JSON validation tool (like `jq`) to check syntax
- Only validate files that match the pattern `**/mcp*.json`
- Exit with a non-zero status code and descriptive error message if validation fails

## Example Implementation

```bash
#!/bin/bash

# Find all mcp*.json files that are staged for commit
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E 'mcp.*\.json$')

if [ -n "$files" ]; then
for file in $files; do
# Check if file exists (it may have been deleted)
if [ -f "$file" ]; then
# Validate JSON syntax
if ! jq . "$file" > /dev/null 2>&1; then
echo "Error: Invalid JSON syntax in $file"
echo "Please fix the JSON syntax before committing."
exit 1
fi
fi
done
fi

exit 0
```

## Benefits

- Prevents broken configurations from being committed
- Improves developer experience by catching errors early
- Follows our best practices of automating validation
- Aligns with the "spilled coffee" principle by ensuring reproducible configurations

## Related Work

This is part of our ongoing effort to improve the robustness of our MCP integrations and follows the git hook opportunities identified in our development workflow.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting .git-hooks/pre-commit and the repository's setup script to determine how hooks are installed. Exercise the hook with staged mcp*.json files, including invalid JSON and deleted files, and confirm that valid files pass while malformed files produce a descriptive error and block the commit.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, shell
Domain
devops, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.