Skip to content

Commit e5cc182

Browse files
pree-dewtadasant
andauthored
Change fields related to server json struct to follow camelCase instead of snake_case (#488)
## Motivation and Context Aligns with issue #428 To bring consistency across naming convention ## How Has This Been Tested? - Locally test cases are tested ## Breaking Changes - Yes, they have to update the server fields - ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [ ] I have added appropriate error handling - [x] I have added or updated documentation as needed --------- Co-authored-by: tadasant <[email protected]>
1 parent 013ce80 commit e5cc182

File tree

27 files changed

+4018
-3314
lines changed

27 files changed

+4018
-3314
lines changed

cmd/publisher/commands/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func createServerJSON(
301301

302302
// Create server structure
303303
return apiv0.ServerJSON{
304-
Schema: "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json",
304+
Schema: "https://static.modelcontextprotocol.io/schemas/2025-09-16/server.schema.json",
305305
Name: name,
306306
Description: description,
307307
Status: model.StatusActive,

cmd/publisher/commands/publish.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ func PublishCommand(args []string) error {
3737
return fmt.Errorf("invalid server.json: %w", err)
3838
}
3939

40+
// Check for deprecated schema and recommend migration
41+
// Allow empty schema (will use default) but reject old schemas
42+
if serverJSON.Schema != "" && !strings.Contains(serverJSON.Schema, "2025-09-16") {
43+
return fmt.Errorf(`deprecated schema detected :%s.
44+
45+
Migrate to the current schema format for new servers.
46+
47+
📋 Migration checklist: https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/CHANGELOG.md#migration-checklist-for-publishers
48+
📖 Full changelog with examples: https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/CHANGELOG.md`, serverJSON.Schema)
49+
}
50+
4051
// Load saved token
4152
homeDir, err := os.UserHomeDir()
4253
if err != nil {
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package commands
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
10+
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
11+
"github.com/modelcontextprotocol/registry/pkg/model"
12+
)
13+
14+
func TestPublishCommand_DeprecatedSchema(t *testing.T) {
15+
// Create a temporary directory for test files
16+
tempDir, err := os.MkdirTemp("", "mcp-publisher-test")
17+
if err != nil {
18+
t.Fatalf("Failed to create temp dir: %v", err)
19+
}
20+
defer os.RemoveAll(tempDir)
21+
22+
// Change to temp directory
23+
originalDir, err := os.Getwd()
24+
if err != nil {
25+
t.Fatalf("Failed to get current dir: %v", err)
26+
}
27+
defer os.Chdir(originalDir)
28+
29+
if err := os.Chdir(tempDir); err != nil {
30+
t.Fatalf("Failed to change to temp dir: %v", err)
31+
}
32+
33+
tests := []struct {
34+
name string
35+
schema string
36+
expectError bool
37+
errorSubstr string
38+
}{
39+
{
40+
name: "deprecated 2025-07-09 schema should show warning",
41+
schema: "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json",
42+
expectError: true,
43+
errorSubstr: "deprecated schema detected",
44+
},
45+
{
46+
name: "current 2025-09-16 schema should pass validation",
47+
schema: "https://static.modelcontextprotocol.io/schemas/2025-09-16/server.schema.json",
48+
expectError: false,
49+
},
50+
{
51+
name: "empty schema should pass validation",
52+
schema: "",
53+
expectError: false,
54+
},
55+
{
56+
name: "custom schema without 2025-07-09 should pass validation",
57+
schema: "https://example.com/custom.schema.json",
58+
expectError: true,
59+
errorSubstr: "deprecated schema detected",
60+
},
61+
}
62+
63+
for _, tt := range tests {
64+
t.Run(tt.name, func(t *testing.T) {
65+
// Create test server.json with specific schema
66+
serverJSON := apiv0.ServerJSON{
67+
Schema: tt.schema,
68+
Name: "com.example/test-server",
69+
Description: "A test server",
70+
Version: "1.0.0",
71+
Status: model.StatusActive,
72+
Repository: model.Repository{
73+
URL: "https://github.com/example/test",
74+
Source: "github",
75+
},
76+
Packages: []model.Package{
77+
{
78+
RegistryType: model.RegistryTypeNPM,
79+
RegistryBaseURL: model.RegistryURLNPM,
80+
Identifier: "@example/test-server",
81+
Version: "1.0.0",
82+
Transport: model.Transport{
83+
Type: model.TransportTypeStdio,
84+
},
85+
},
86+
},
87+
}
88+
89+
jsonData, err := json.MarshalIndent(serverJSON, "", " ")
90+
if err != nil {
91+
t.Fatalf("Failed to marshal test JSON: %v", err)
92+
}
93+
94+
// Write server.json to temp directory
95+
serverFile := filepath.Join(tempDir, "server.json")
96+
if err := os.WriteFile(serverFile, jsonData, 0o600); err != nil {
97+
t.Fatalf("Failed to write server.json: %v", err)
98+
}
99+
100+
err = PublishCommand([]string{})
101+
102+
if tt.expectError {
103+
if err == nil {
104+
t.Errorf("Expected error for deprecated schema, but got none")
105+
return
106+
}
107+
if !strings.Contains(err.Error(), tt.errorSubstr) {
108+
t.Errorf("Expected error containing '%s', got: %v", tt.errorSubstr, err)
109+
}
110+
// Check that the error contains the migration links
111+
if !strings.Contains(err.Error(), "Migration checklist:") {
112+
t.Errorf("Expected error to contain migration checklist link")
113+
}
114+
if !strings.Contains(err.Error(), "Full changelog with examples:") {
115+
t.Errorf("Expected error to contain changelog link")
116+
}
117+
} else {
118+
// For non-deprecated schemas, we expect the command to fail at auth step, not schema validation
119+
if err != nil && strings.Contains(err.Error(), "deprecated schema detected") {
120+
t.Errorf("Unexpected deprecated schema error for schema '%s': %v", tt.schema, err)
121+
}
122+
123+
// We expect auth errors for valid schemas since we don't have a token
124+
if err != nil && !strings.Contains(err.Error(), "not authenticated") && !strings.Contains(err.Error(), "failed to read token") {
125+
t.Logf("Expected auth error for valid schema, got: %v", err)
126+
}
127+
}
128+
129+
// Clean up for next test
130+
os.Remove(serverFile)
131+
})
132+
}
133+
}

0 commit comments

Comments
 (0)