Skip to content

Commit 4e221e4

Browse files
tadasantchlowell
andauthored
Add linting documentation and pre-commit hooks (modelcontextprotocol#177)
## Summary This PR improves the developer experience by adding clear linting documentation and optional pre-commit hooks to catch issues before CI. Helpful to avoid fighting Claude Code / Copilot on "please make sure linting passes CI". ## Changes - Updated `README.md` with: - Go 1.23.x requirement (was "1.18 or later") - golangci-lint v1.61.0 in prerequisites - New Development section with linting instructions - Updated `CLAUDE.md` with: - Development Setup section - Added `.githooks/pre-commit`: - Runs golangci-lint and gofmt checks - References README for installation instructions - Can be bypassed with `--no-verify` when needed ## Test Plan - [x] Verified pre-commit hook blocks commits when golangci-lint is missing - [x] Confirmed hook shows clear error message pointing to README - [x] Tested that linting passes with Go 1.23.0 and golangci-lint v1.61.0 - [x] Verified gofmt correctly identifies formatting issues Co-authored w/ Claude Code --------- Co-authored-by: Charles Lowell <[email protected]>
1 parent 3c42f68 commit 4e221e4

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

.githooks/pre-commit

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Pre-commit hook for MCP Registry
4+
# Runs linting and formatting checks before allowing commits
5+
6+
set -e
7+
8+
echo "Running pre-commit checks..."
9+
10+
# Check if golangci-lint is installed
11+
if ! command -v golangci-lint &> /dev/null; then
12+
echo "❌ golangci-lint is not installed!"
13+
echo "See README.md Prerequisites section for installation instructions."
14+
exit 1
15+
fi
16+
17+
# Run golangci-lint
18+
echo "Running golangci-lint..."
19+
if ! golangci-lint run --timeout=5m; then
20+
echo "❌ Linting failed! Please fix the issues above."
21+
exit 1
22+
fi
23+
24+
# Check formatting
25+
echo "Checking Go formatting..."
26+
UNFORMATTED=$(gofmt -s -l .)
27+
if [ -n "$UNFORMATTED" ]; then
28+
echo "❌ The following files need formatting:"
29+
echo "$UNFORMATTED"
30+
echo ""
31+
echo "Run 'gofmt -s -w .' to fix formatting issues."
32+
exit 1
33+
fi
34+
35+
echo "✅ All pre-commit checks passed!"

CLAUDE.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Overview
66
MCP Registry is a community-driven registry service for Model Context Protocol (MCP) servers. It provides a centralized repository for discovering and managing MCP implementations.
77

8+
## Development Setup
9+
10+
### Prerequisites
11+
- **Go 1.23.x** - The project requires this specific version (check with `go version`)
12+
- Consider using a Go version manager like `g` or `gvm` if you work on multiple projects
13+
- **golangci-lint v1.61.0** - Install with:
14+
```bash
15+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
16+
```
17+
18+
### Git Hooks (Optional)
19+
To run linting automatically before commits:
20+
```bash
21+
git config core.hooksPath .githooks
22+
```
23+
824
## Common Development Commands
925

1026
### Build
@@ -46,16 +62,18 @@ export BEARER_TOKEN=your_github_token_here
4662

4763
### Lint
4864
```bash
49-
# Install golangci-lint if needed
50-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
51-
52-
# Run linting
65+
# Run linting (same as CI)
5366
golangci-lint run --timeout=5m
5467

5568
# Check formatting
5669
gofmt -s -l .
70+
71+
# Fix formatting issues
72+
gofmt -s -w .
5773
```
5874

75+
**Note**: The project uses golangci-lint v1.61.0 with 62 enabled linters. Always run linting locally before pushing to avoid CI failures.
76+
5977
## Architecture Overview
6078

6179
The codebase follows a clean architecture pattern:

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ The MCP Registry service provides a centralized repository for MCP server entrie
2424

2525
### Prerequisites
2626

27-
- Go 1.18 or later
27+
- Go 1.23.x (required - check with `go version`)
2828
- MongoDB
2929
- Docker (optional, but recommended for development)
3030

31+
For development:
32+
- golangci-lint v1.61.0 - Install with:
33+
```bash
34+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
35+
```
36+
3137
## Running
3238

3339
The easiest way to get the registry running is to use `docker compose`. This will setup the MCP Registry service, import the seed data and run MongoDB in a local Docker environment.
@@ -54,6 +60,33 @@ This will create the `registry` binary in the current directory. You'll need to
5460

5561
By default, the service will run on `http://localhost:8080`.
5662

63+
## Development
64+
65+
### Linting
66+
67+
The project uses golangci-lint with extensive checks. Always run linting before pushing:
68+
69+
```bash
70+
# Run all linters (same as CI)
71+
golangci-lint run --timeout=5m
72+
73+
# Check formatting
74+
gofmt -s -l .
75+
76+
# Fix formatting
77+
gofmt -s -w .
78+
```
79+
80+
### Git Hooks (Optional)
81+
82+
To automatically run linting before commits:
83+
84+
```bash
85+
git config core.hooksPath .githooks
86+
```
87+
88+
This will prevent commits that fail linting or have formatting issues.
89+
5790
## Project Structure
5891

5992
```

0 commit comments

Comments
 (0)