Skip to content

Commit dce82fa

Browse files
update Go version consistently and fix linter
Made the linter a little lax by removing `lll` and `funlen` . We can add these back at a later time if we think they are useful.
1 parent 3b4643f commit dce82fa

File tree

14 files changed

+83
-51
lines changed

14 files changed

+83
-51
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ main ]
88

99
env:
10-
GO_VERSION: '1.23.x'
10+
GO_VERSION: '1.24.x'
1111

1212
jobs:
1313
# Build, Lint, and Validate

.golangci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ linters:
1616
- errorlint
1717
- exhaustive
1818
- forbidigo
19-
- funlen
2019
- gocognit
2120
- goconst
2221
- gocritic
@@ -29,7 +28,6 @@ linters:
2928
- grouper
3029
- importas
3130
- ireturn
32-
- lll
3331
- makezero
3432
- misspell
3533
- nakedret
@@ -56,6 +54,12 @@ linters:
5654
settings:
5755
cyclop:
5856
max-complexity: 20
57+
dupl:
58+
threshold: 300
59+
gocognit:
60+
min-complexity: 51
61+
nestif:
62+
min-complexity: 10
5963
exclusions:
6064
generated: lax
6165
presets:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-alpine AS builder
1+
FROM golang:1.24-alpine AS builder
22
WORKDIR /app
33
COPY . .
44
ARG GO_BUILD_TAGS

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The MCP Registry service provides a centralized repository for MCP server entrie
3434

3535
### Prerequisites
3636

37-
- Go 1.23.x (required - check with `go version`)
37+
- Go 1.24.x (required - check with `go version`)
3838
- MongoDB
3939
- Docker (optional, but recommended for development)
4040

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/modelcontextprotocol/registry
22

3-
go 1.23.0
3+
go 1.24.0
44

55
require (
66
github.com/caarlos0/env/v11 v11.3.1

internal/api/handlers/v0/mocks_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ type MockRegistryService struct {
1313
}
1414

1515
func (m *MockRegistryService) List(cursor string, limit int) ([]model.Server, string, error) {
16-
args := m.Called(cursor, limit) //nolint:typecheck // testify mock embedding issue
16+
args := m.Called(cursor, limit)
1717
return args.Get(0).([]model.Server), args.String(1), args.Error(2)
1818
}
1919

2020
func (m *MockRegistryService) GetByID(id string) (*model.ServerDetail, error) {
21-
args := m.Called(id) //nolint:typecheck // testify mock embedding issue
21+
args := m.Called(id)
2222
return args.Get(0).(*model.ServerDetail), args.Error(1)
2323
}
2424

2525
func (m *MockRegistryService) Publish(serverDetail *model.ServerDetail) error {
26-
args := m.Called(serverDetail) //nolint:typecheck // testify mock embedding issue
26+
args := m.Called(serverDetail)
2727
return args.Error(0)
2828
}
2929

@@ -35,16 +35,16 @@ type MockAuthService struct {
3535
func (m *MockAuthService) StartAuthFlow(
3636
ctx context.Context, method model.AuthMethod, repoRef string,
3737
) (map[string]string, string, error) {
38-
args := m.Called(ctx, method, repoRef) //nolint:typecheck // testify mock embedding issue
38+
args := m.Called(ctx, method, repoRef)
3939
return args.Get(0).(map[string]string), args.String(1), args.Error(2)
4040
}
4141

4242
func (m *MockAuthService) CheckAuthStatus(ctx context.Context, statusToken string) (string, error) {
43-
args := m.Called(ctx, statusToken) //nolint:typecheck // testify mock embedding issue
43+
args := m.Called(ctx, statusToken)
4444
return args.String(0), args.Error(1)
4545
}
4646

4747
func (m *MockAuthService) ValidateAuth(ctx context.Context, authentication model.Authentication) (bool, error) {
48-
args := m.Called(ctx, authentication) //nolint:typecheck // testify mock embedding issue
48+
args := m.Called(ctx, authentication)
4949
return args.Bool(0), args.Error(1)
5050
}

internal/api/handlers/v0/publish_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ func TestPublishHandler(t *testing.T) {
374374
}
375375

376376
// Assert that all expectations were met
377-
mockRegistry.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
378-
mockAuthService.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
377+
mockRegistry.AssertExpectations(t)
378+
mockAuthService.AssertExpectations(t)
379379
})
380380
}
381381
}
@@ -437,15 +437,20 @@ func TestPublishHandlerBearerTokenParsing(t *testing.T) {
437437
requestBody, err := json.Marshal(serverDetail)
438438
assert.NoError(t, err)
439439

440-
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "/publish", bytes.NewBuffer(requestBody))
440+
req, err := http.NewRequestWithContext(
441+
context.Background(),
442+
http.MethodPost,
443+
"/publish",
444+
bytes.NewBuffer(requestBody),
445+
)
441446
assert.NoError(t, err)
442447
req.Header.Set("Authorization", tc.authHeader)
443448

444449
rr := httptest.NewRecorder()
445450
handler.ServeHTTP(rr, req)
446451

447452
assert.Equal(t, http.StatusCreated, rr.Code)
448-
mockAuthService.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
453+
mockAuthService.AssertExpectations(t)
449454
})
450455
}
451456
}
@@ -502,15 +507,20 @@ func TestPublishHandlerAuthMethodSelection(t *testing.T) {
502507
requestBody, err := json.Marshal(serverDetail)
503508
assert.NoError(t, err)
504509

505-
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "/publish", bytes.NewBuffer(requestBody))
510+
req, err := http.NewRequestWithContext(
511+
context.Background(),
512+
http.MethodPost,
513+
"/publish",
514+
bytes.NewBuffer(requestBody),
515+
)
506516
assert.NoError(t, err)
507517
req.Header.Set("Authorization", "Bearer test_token")
508518

509519
rr := httptest.NewRecorder()
510520
handler.ServeHTTP(rr, req)
511521

512522
assert.Equal(t, http.StatusCreated, rr.Code)
513-
mockAuthService.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
523+
mockAuthService.AssertExpectations(t)
514524
})
515525
}
516526
}

internal/api/handlers/v0/servers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func TestServersHandler(t *testing.T) {
257257
}
258258

259259
// Verify mock expectations
260-
mockRegistry.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
260+
mockRegistry.AssertExpectations(t)
261261
})
262262
}
263263
}
@@ -321,7 +321,7 @@ func TestServersHandlerIntegration(t *testing.T) {
321321
assert.Empty(t, paginatedResp.Metadata.NextCursor)
322322

323323
// Verify mock expectations
324-
mockRegistry.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
324+
mockRegistry.AssertExpectations(t)
325325
}
326326

327327
// TestServersDetailHandlerIntegration tests the servers detail handler with actual HTTP requests
@@ -387,5 +387,5 @@ func TestServersDetailHandlerIntegration(t *testing.T) {
387387
assert.Equal(t, *serverDetail, serverDetailResp)
388388

389389
// Verify mock expectations
390-
mockRegistry.AssertExpectations(t) //nolint:typecheck // testify mock embedding issue
390+
mockRegistry.AssertExpectations(t)
391391
}

internal/database/import.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"github.com/modelcontextprotocol/registry/internal/model"
1717
)
1818

19-
// ReadSeedFile reads and parses seed data from either:
19+
// ReadSeedFile reads seed data from various sources:
2020
// 1. Local file paths (*.json files)
2121
// 2. Direct HTTP URLs to seed.json files
2222
// 3. Registry root URLs (automatically appends /v0/servers and paginates)
23-
func ReadSeedFile(path string) ([]model.ServerDetail, error) {
23+
func ReadSeedFile(ctx context.Context, path string) ([]model.ServerDetail, error) {
2424
log.Printf("Reading seed data from %s", path)
2525

2626
// Set default seed file path if not provided
@@ -37,14 +37,14 @@ func ReadSeedFile(path string) ([]model.ServerDetail, error) {
3737
// Determine if this is a direct seed file URL or a registry root URL
3838
if strings.HasSuffix(path, ".json") || strings.Contains(path, "seed.json") {
3939
// Direct seed file URL - read directly
40-
fileContent, err := readFromHTTP(path)
40+
fileContent, err := readFromHTTP(ctx, path)
4141
if err != nil {
4242
return nil, fmt.Errorf("failed to read from HTTP URL: %w", err)
4343
}
4444
return parseSeedJSON(fileContent)
4545
}
4646
// Registry root URL - paginate through /v0/servers endpoint
47-
return readFromRegistry(path)
47+
return readFromRegistryWithContext(ctx, path)
4848
}
4949
// Read from local file
5050
fileContent, err := os.ReadFile(path)
@@ -55,12 +55,12 @@ func ReadSeedFile(path string) ([]model.ServerDetail, error) {
5555
}
5656

5757
// readFromHTTP reads content from an HTTP URL with timeout
58-
func readFromHTTP(url string) ([]byte, error) {
58+
func readFromHTTP(ctx context.Context, url string) ([]byte, error) {
5959
client := &http.Client{
6060
Timeout: 30 * time.Second,
6161
}
6262

63-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
63+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
6464
if err != nil {
6565
return nil, fmt.Errorf("failed to create request: %w", err)
6666
}
@@ -113,8 +113,8 @@ type Metadata struct {
113113
Total int `json:"total,omitempty"`
114114
}
115115

116-
// readFromRegistry reads all servers from a registry by paginating through /v0/servers endpoint
117-
func readFromRegistry(registryURL string) ([]model.ServerDetail, error) {
116+
// readFromRegistryWithContext reads all servers from a registry by paginating through /v0/servers endpoint
117+
func readFromRegistryWithContext(ctx context.Context, registryURL string) ([]model.ServerDetail, error) {
118118
log.Printf("Reading from registry: %s", registryURL)
119119

120120
// Ensure the URL doesn't have a trailing slash
@@ -167,7 +167,11 @@ func readFromRegistry(registryURL string) ([]model.ServerDetail, error) {
167167
}
168168

169169
// Fetch the page
170-
resp, err := client.Get(serverURL)
170+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, serverURL, nil)
171+
if err != nil {
172+
return nil, fmt.Errorf("failed to create request for %s: %w", serverURL, err)
173+
}
174+
resp, err := client.Do(req)
171175
if err != nil {
172176
return nil, fmt.Errorf("failed to fetch servers from %s: %w", serverURL, err)
173177
}
@@ -196,7 +200,7 @@ func readFromRegistry(registryURL string) ([]model.ServerDetail, error) {
196200
// Build URL for server detail
197201
detailURL := registryURL + "/v0/servers/" + server.ID
198202

199-
detailReq, err := http.NewRequestWithContext(context.Background(), http.MethodGet, detailURL, nil)
203+
detailReq, err := http.NewRequestWithContext(ctx, http.MethodGet, detailURL, nil)
200204
if err != nil {
201205
log.Printf("Warning: failed to create request for server %s: %v", server.ID, err)
202206
// Fall back to basic server information

internal/database/import_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package database_test
22

33
import (
4+
"context"
45
"encoding/json"
56
"net/http"
67
"net/http/httptest"
@@ -52,7 +53,7 @@ func TestReadSeedFile_LocalFile(t *testing.T) {
5253
defer os.Remove(tempFile)
5354

5455
// Test reading the file
55-
result, err := database.ReadSeedFile(tempFile)
56+
result, err := database.ReadSeedFile(context.Background(), tempFile)
5657
assert.NoError(t, err)
5758
assert.Len(t, result, 1)
5859
assert.Equal(t, "test-server-1", result[0].Name)
@@ -79,7 +80,7 @@ func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
7980
defer server.Close()
8081

8182
// Test reading from HTTP URL ending in .json
82-
result, err := database.ReadSeedFile(server.URL + "/seed.json")
83+
result, err := database.ReadSeedFile(context.Background(), server.URL+"/seed.json")
8384
assert.NoError(t, err)
8485
assert.Len(t, result, 1)
8586
assert.Equal(t, "test-server-1", result[0].Name)
@@ -155,19 +156,23 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
155156
// Handle individual server detail endpoints
156157
mux.HandleFunc("/v0/servers/server-1", func(w http.ResponseWriter, _ *http.Request) {
157158
w.Header().Set("Content-Type", "application/json")
158-
json.NewEncoder(w).Encode(serverDetail1)
159+
if err := json.NewEncoder(w).Encode(serverDetail1); err != nil {
160+
http.Error(w, err.Error(), http.StatusInternalServerError)
161+
}
159162
})
160163

161164
mux.HandleFunc("/v0/servers/server-2", func(w http.ResponseWriter, _ *http.Request) {
162165
w.Header().Set("Content-Type", "application/json")
163-
json.NewEncoder(w).Encode(serverDetail2)
166+
if err := json.NewEncoder(w).Encode(serverDetail2); err != nil {
167+
http.Error(w, err.Error(), http.StatusInternalServerError)
168+
}
164169
})
165170

166171
server := httptest.NewServer(mux)
167172
defer server.Close()
168173

169174
// Test reading from registry root URL (this should trigger pagination)
170-
result, err := database.ReadSeedFile(server.URL)
175+
result, err := database.ReadSeedFile(context.Background(), server.URL)
171176
assert.NoError(t, err)
172177
assert.Len(t, result, 2)
173178

0 commit comments

Comments
 (0)