From d092dd6390f1c64add83303517c4d00bfc65433e Mon Sep 17 00:00:00 2001 From: Avish Porwal Date: Thu, 4 Dec 2025 22:53:15 +0530 Subject: [PATCH] Fix issue-743 by sanitizing the URL (#809) This PR aims to fix https://github.com/modelcontextprotocol/registry/issues/743#event-20985516896 ## Motivation and Context This is needed to ensure we are sanitizing the URL before creating server.json to be inline with the validations. ## How Has This Been Tested? Tested via UTs and also tested CLI locally to ensure the expected behavior. ## Breaking Changes ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context Co-authored-by: Avish Porwal --- cmd/publisher/commands/init.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/publisher/commands/init.go b/cmd/publisher/commands/init.go index 6a7381d..d1ac9a1 100644 --- a/cmd/publisher/commands/init.go +++ b/cmd/publisher/commands/init.go @@ -213,6 +213,10 @@ func detectDescription() string { } func detectRepoURL() string { + sanitizeURL := func(url string) string { + return strings.TrimPrefix(url, "git+") + } + // Try git remote ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -233,11 +237,11 @@ func detectRepoURL() string { if json.Unmarshal(data, &pkg) == nil { if repo, ok := pkg["repository"].(map[string]any); ok { if url, ok := repo["url"].(string); ok { - return strings.TrimSuffix(url, ".git") + return sanitizeURL(strings.TrimSuffix(url, ".git")) } } if repo, ok := pkg["repository"].(string); ok { - return strings.TrimSuffix(repo, ".git") + return sanitizeURL(strings.TrimSuffix(repo, ".git")) } } }