Skip to content

Commit e2397a6

Browse files
rdimitrovCopilot
andauthored
Allow remote URLs to be shared across server names (#1806)
A publisher can currently block an endpoint's operator from listing it under their own namespace simply by registering the remote URL first. The registry authenticates namespaces but does not verify remote URL ownership, so registration order cannot establish the canonical publisher. This change allows different server names to reference the same remote URL on both `/v0` and `/v0.1`. It removes the conflict check from publication, admin metadata edits, single-version restores, and all-version restores. Namespace authorization, URL validation, name/version uniqueness, and per-name version history remain intact. Existing records, response schemas, and database indexes are unchanged; no data migration is needed. The existing `remotes_ms` log field is retained at zero. The original uniqueness rule accompanied namespace/hostname matching in #180 and #306; #769 later removed hostname matching. ## Downstream compatibility This changes a previously documented behavioral guarantee, even though the API shape is unchanged. Consumers that use a remote URL as a unique key, or resolve it to a single canonical listing, must support multiple matching server names. Records should be keyed by name/version (and registry when combining sources), with each listing's metadata, headers, and template variables kept separate. A shared endpoint does not establish publisher ownership or endorsement. The publishing guide and changelog explain this change. Review the compatibility implications and coordinate rollout with downstream consumers. Re-enabling uniqueness after shared URLs have been accepted could block those servers' subsequent publications, edits, and restores. Discovery grouping and endpoint ownership verification are outside this PR. ## Validation Updates the indirect `github.com/klauspost/compress` dependency from v1.20.1 to v1.20.2 to fix GO-2026-6865, which was reported by CI's vulnerability scan. Local `govulncheck ./...` and the CI vulnerability scan pass with the update. - Added database-backed regressions for independent metadata, version histories, latest-only pagination, encoded listings, admin edits, and single/all-version restores to active or deprecated. - Added HTTP publish coverage on both API versions proving shared URLs succeed while unauthorized namespaces, duplicate name/version pairs, and invalid remote URLs still fail. - Confirmed the new publication, edit, and active-restore regressions fail against the original service implementation and pass with this change. - Passed `go test -race -coverprofile=coverage.out -covermode=atomic ./internal/... ./cmd/...` using an isolated local PostgreSQL 17 instance. - Passed `make lint` with golangci-lint v2.14.0, `make validate build`, and `git diff --check`. - CI passed all checks, including `make test-all` (with Docker/ko integration tests), build/lint/validation, vulnerability scanning, and CodeQL. The Docker/ko integration harness was not run locally. --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
1 parent 2729b4c commit e2397a6

10 files changed

Lines changed: 289 additions & 358 deletions

File tree

‎docs/modelcontextprotocol-io/remote-servers.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ When you publish, the Registry verifies that you control the namespace in the se
3838

3939
If your remote URL is on a domain you control, consider using DNS or HTTP authentication so the server name reflects that domain. This lets users see that the server name and remote URL belong to the same publisher.
4040

41-
Each remote URL can be used by only one server name. Publishing fails if another server already uses the same URL.
41+
Multiple server names can reference the same remote URL. An existing listing does not reserve that URL or prevent another publisher from listing it under a namespace they control. Sharing a URL does not grant permission to publish, edit, or change the status of another publisher's listing.
42+
43+
Consumers should identify registry records by server name and version, not by remote URL. A URL lookup may match multiple server names, each with its own metadata, headers, and template variables. Do not merge configurations or infer publisher ownership or endorsement from a shared URL.
4244

4345
## Transport Type
4446

‎docs/reference/api/CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Changes to the REST API endpoints and responses.
44

55
## Unreleased
66

7+
### ⚠️ BREAKING CHANGES
8+
9+
#### Remote URLs may be shared across server names
10+
11+
The official registry no longer rejects publishing, admin metadata edits, or restoring deleted versions because another server name references the same remote URL. This applies to both `/v0` and `/v0.1`. Namespace authorization, remote URL validation, and uniqueness of server name/version pairs remain unchanged. Existing records and API response schemas are unchanged; no data migration is required.
12+
13+
**Downstream compatibility:** This relaxes a previously documented publishing restriction and changes the guarantee that a remote URL belongs to only one server name. Consumers that index records by remote URL or select a single canonical listing from a URL must support multiple matching server names. Identify records by server name and version (and registry when combining sources), and preserve each listing's metadata and configuration separately. A shared URL does not establish ownership or endorsement.
14+
15+
Operators should communicate this change to downstream consumers before rollout. Re-enabling the restriction after shared URLs have been published could block subsequent publications, edits, or restores for those servers.
16+
717
### Added
818

919
#### Server Status Management Endpoints

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require (
5353
github.com/jackc/pgpassfile v1.0.0 // indirect
5454
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
5555
github.com/jackc/puddle/v2 v2.2.2 // indirect
56-
github.com/klauspost/compress v1.20.1 // indirect
56+
github.com/klauspost/compress v1.20.2 // indirect
5757
github.com/kr/text v0.2.0 // indirect
5858
github.com/kylelemons/godebug v1.1.0 // indirect
5959
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
9090
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
9191
github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU=
9292
github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXwkPPMeUgOK1k=
93-
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
94-
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
93+
github.com/klauspost/compress v1.20.2 h1:v5tiZvm1KGLyg5d5oXdXe3lsSPrbEUiKoXGia//I7Qo=
94+
github.com/klauspost/compress v1.20.2/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
9595
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
9696
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
9797
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package v0_test
2+
3+
import (
4+
"bytes"
5+
"crypto/ed25519"
6+
"crypto/rand"
7+
"encoding/hex"
8+
"encoding/json"
9+
"net/http"
10+
"net/http/httptest"
11+
"testing"
12+
13+
"github.com/danielgtaylor/huma/v2"
14+
"github.com/danielgtaylor/huma/v2/adapters/humago"
15+
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
17+
18+
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
19+
"github.com/modelcontextprotocol/registry/internal/auth"
20+
"github.com/modelcontextprotocol/registry/internal/config"
21+
"github.com/modelcontextprotocol/registry/internal/database"
22+
"github.com/modelcontextprotocol/registry/internal/service"
23+
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
24+
"github.com/modelcontextprotocol/registry/pkg/model"
25+
)
26+
27+
func TestPublishSharedRemoteURLPreservesValidation(t *testing.T) {
28+
for _, prefix := range []string{"/v0", "/v0.1"} {
29+
t.Run(prefix, func(t *testing.T) {
30+
seed := make([]byte, ed25519.SeedSize)
31+
_, err := rand.Read(seed)
32+
require.NoError(t, err)
33+
cfg := &config.Config{JWTPrivateKey: hex.EncodeToString(seed), EnableRegistryValidation: true}
34+
mux := http.NewServeMux()
35+
api := humago.New(mux, huma.DefaultConfig("Test API", "1.0.0"))
36+
v0.RegisterPublishEndpoint(api, prefix, service.NewRegistryService(database.NewTestDB(t), cfg), cfg)
37+
38+
publisherToken := func(namespace string) string {
39+
t.Helper()
40+
token, err := generateTestJWTToken(cfg, auth.JWTClaims{
41+
AuthMethod: auth.MethodGitHubAT,
42+
Permissions: []auth.Permission{{
43+
Action: auth.PermissionActionPublish, ResourcePattern: namespace + "/*",
44+
}},
45+
})
46+
require.NoError(t, err)
47+
return token
48+
}
49+
aToken := publisherToken("io.github.publisher-a")
50+
bToken := publisherToken("io.github.publisher-b")
51+
publish := func(server apiv0.ServerJSON, token string) *httptest.ResponseRecorder {
52+
t.Helper()
53+
body, err := json.Marshal(server)
54+
require.NoError(t, err)
55+
req := httptest.NewRequest(http.MethodPost, prefix+"/publish", bytes.NewReader(body))
56+
req.Header.Set("Content-Type", "application/json")
57+
req.Header.Set("Authorization", "Bearer "+token)
58+
rr := httptest.NewRecorder()
59+
mux.ServeHTTP(rr, req)
60+
return rr
61+
}
62+
a := apiv0.ServerJSON{
63+
Schema: model.CurrentSchemaURL, Name: "io.github.publisher-a/example", Version: "1.0.0",
64+
Description: "A remote server listing",
65+
Remotes: []model.Transport{{Type: "streamable-http", URL: "https://api.example.com/mcp"}},
66+
}
67+
b := a
68+
b.Name = "io.github.publisher-b/example"
69+
for _, entry := range []struct {
70+
server apiv0.ServerJSON
71+
token string
72+
}{{a, aToken}, {b, bToken}} {
73+
rr := publish(entry.server, entry.token)
74+
require.Equal(t, http.StatusOK, rr.Code, "%s", rr.Body.String())
75+
var got apiv0.ServerResponse
76+
require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &got))
77+
assert.Equal(t, entry.server, got.Server)
78+
}
79+
80+
// A shared endpoint grants no permission over the other publisher's name.
81+
b.Version = "2.0.0"
82+
rr := publish(b, aToken)
83+
require.Equal(t, http.StatusForbidden, rr.Code, "%s", rr.Body.String())
84+
rr = publish(b, bToken)
85+
require.Equal(t, http.StatusOK, rr.Code, "%s", rr.Body.String())
86+
rr = publish(b, bToken)
87+
require.Equal(t, http.StatusBadRequest, rr.Code, "%s", rr.Body.String())
88+
assert.Contains(t, rr.Body.String(), "already exists")
89+
90+
// Relaxing cross-server uniqueness must not relax remote URL validation.
91+
b.Version = "3.0.0"
92+
b.Remotes = []model.Transport{{Type: "streamable-http", URL: "http://api.example.com/mcp"}}
93+
rr = publish(b, bToken)
94+
require.Equal(t, http.StatusUnprocessableEntity, rr.Code, "%s", rr.Body.String())
95+
})
96+
}
97+
}

‎internal/database/database.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
// ServerFilter defines filtering options for server queries
2424
type ServerFilter struct {
2525
Name *string // for finding versions of same server
26-
RemoteURL *string // for duplicate URL detection
26+
RemoteURL *string // exact remote URL lookup; may match multiple server names
2727
UpdatedSince *time.Time // for incremental sync filtering
2828
SubstringName *string // for substring search on name
2929
Version *string // for exact version matching

‎internal/database/postgres.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ func buildFilterConditions(filter *ServerFilter, argIndex int) ([]string, []any,
137137
// idx_servers_json_remotes on (value -> 'remotes'). The previously-used
138138
// EXISTS / jsonb_array_elements / ->> form is logically equivalent but
139139
// the planner can't translate the per-row array unfolding into a GIN
140-
// search — it falls back to scanning every row. validateNoDuplicateRemoteURLs
141-
// in the publish path ran this filter and was measured at ~10s on prod's
140+
// search — it falls back to scanning every row. The former URL uniqueness
141+
// check in the publish path ran this filter and was measured at ~10s on prod's
142142
// 21K-row table on 2026-04-28; the containment form is GIN-indexable and
143143
// completes in low single-digit ms.
144144
conditions = append(conditions, fmt.Sprintf("value -> 'remotes' @> jsonb_build_array(jsonb_build_object('url', $%d::text))", argIndex))

‎internal/service/registry_service.go‎

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ const maxServerVersionsPerServer = 10000
2323
// transaction; the rest inside createServerInTransaction. Constants because
2424
// version_checks is reported from multiple branches.
2525
const (
26-
phaseValidate = "validate"
27-
phaseTxBegin = "tx_begin"
28-
phaseAcquireLock = "acquire_lock"
29-
phaseValidateRemoteURLs = "validate_remote_urls"
30-
phaseVersionChecks = "version_checks"
31-
phaseUnmarkLatest = "unmark_latest"
32-
phaseDBCreate = "db_create"
33-
phaseCommit = "commit"
26+
phaseValidate = "validate"
27+
phaseTxBegin = "tx_begin"
28+
phaseAcquireLock = "acquire_lock"
29+
phaseVersionChecks = "version_checks"
30+
phaseUnmarkLatest = "unmark_latest"
31+
phaseDBCreate = "db_create"
32+
phaseCommit = "commit"
3433
)
3534

3635
// publishTimings accumulates the per-phase durations reported on the single
@@ -57,7 +56,6 @@ type publishTimings struct {
5756
validateMs int64
5857
txBeginMs int64
5958
lockMs int64
60-
remotesMs int64
6159
versionChecksMs int64
6260
unmarkMs int64
6361
createMs int64
@@ -86,7 +84,8 @@ func (t *publishTimings) log(ctx context.Context, serverJSON apiv0.ServerJSON, t
8684
"validate_ms", t.validateMs,
8785
"tx_begin_ms", t.txBeginMs,
8886
"lock_ms", t.lockMs,
89-
"remotes_ms", t.remotesMs,
87+
// Retain the former URL uniqueness timing field for log consumers.
88+
"remotes_ms", int64(0),
9089
"version_checks_ms", t.versionChecksMs,
9190
"unmark_ms", t.unmarkMs,
9291
"create_ms", t.createMs,
@@ -275,13 +274,6 @@ func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx
275274
return nil, err
276275
}
277276

278-
// Check for duplicate remote URLs
279-
if err = t.run(phaseValidateRemoteURLs, &t.remotesMs, func() error {
280-
return s.validateNoDuplicateRemoteURLs(ctx, tx, serverJSON)
281-
}); err != nil {
282-
return nil, err
283-
}
284-
285277
// Version checks: count, exists, current-latest (small DB lookups, but on a
286278
// starved pool any of them stalls until a connection is free). Bundled under
287279
// one phase since they share a logical step.
@@ -407,29 +399,6 @@ func pickLatestVersion(versions []*apiv0.ServerResponse, allowDeleted bool) *api
407399
return winner
408400
}
409401

410-
// validateNoDuplicateRemoteURLs checks that no other server is using the same remote URLs
411-
func (s *registryServiceImpl) validateNoDuplicateRemoteURLs(ctx context.Context, tx pgx.Tx, serverDetail apiv0.ServerJSON) error {
412-
// Check each remote URL in the new server for conflicts
413-
for _, remote := range serverDetail.Remotes {
414-
// Use filter to find servers with this remote URL
415-
filter := &database.ServerFilter{RemoteURL: &remote.URL}
416-
417-
conflictingServers, _, err := s.db.ListServers(ctx, tx, filter, "", 1000)
418-
if err != nil {
419-
return fmt.Errorf("failed to check remote URL conflict: %w", err)
420-
}
421-
422-
// Check if any conflicting server has a different name
423-
for _, conflictingServer := range conflictingServers {
424-
if conflictingServer.Server.Name != serverDetail.Name {
425-
return fmt.Errorf("remote URL %s is already used by server %s", remote.URL, conflictingServer.Server.Name)
426-
}
427-
}
428-
}
429-
430-
return nil
431-
}
432-
433402
// UpdateServer updates an existing server with new details
434403
func (s *registryServiceImpl) UpdateServer(ctx context.Context, serverName, version string, req *apiv0.ServerJSON, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
435404
// Wrap the entire operation in a transaction
@@ -475,11 +444,6 @@ func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx
475444
// Merge the request with the current server, preserving metadata
476445
updatedServer := *req
477446

478-
// Check for duplicate remote URLs using the updated server
479-
if err := s.validateNoDuplicateRemoteURLs(ctx, tx, updatedServer); err != nil {
480-
return nil, err
481-
}
482-
483447
// Update server in database
484448
updatedServerResponse, err := s.db.UpdateServer(ctx, tx, serverName, version, &updatedServer)
485449
if err != nil {
@@ -511,27 +475,11 @@ func (s *registryServiceImpl) UpdateServerStatus(ctx context.Context, serverName
511475

512476
// updateServerStatusInTransaction contains the actual UpdateServerStatus logic within a transaction
513477
func (s *registryServiceImpl) updateServerStatusInTransaction(ctx context.Context, tx pgx.Tx, serverName, version string, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
514-
// Get current server to verify it exists and check current status
515-
// Include deleted servers since we may need to restore them
516-
currentServer, err := s.db.GetServerByNameAndVersion(ctx, tx, serverName, version, true)
517-
if err != nil {
518-
return nil, err
519-
}
520-
521478
// Acquire advisory lock to prevent concurrent edits of servers with same name
522479
if err := s.db.AcquirePublishLock(ctx, tx, serverName); err != nil {
523480
return nil, err
524481
}
525482

526-
// When transitioning to active from deleted, validate remote URLs don't conflict
527-
if statusChange.NewStatus == model.StatusActive &&
528-
currentServer.Meta.Official != nil &&
529-
currentServer.Meta.Official.Status == model.StatusDeleted {
530-
if err := s.validateNoDuplicateRemoteURLs(ctx, tx, currentServer.Server); err != nil {
531-
return nil, err
532-
}
533-
}
534-
535483
// Update only the status metadata
536484
if _, err := s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage); err != nil {
537485
return nil, err
@@ -558,27 +506,6 @@ func (s *registryServiceImpl) updateAllVersionsStatusInTransaction(ctx context.C
558506
return nil, err
559507
}
560508

561-
// When transitioning to active, validate remote URLs for any versions currently deleted
562-
if statusChange.NewStatus == model.StatusActive {
563-
includeDeleted := true
564-
565-
// When transitioning to active, it means the current status is either deprecated or deleted, so it should include deleted server also
566-
filter := &database.ServerFilter{Name: &serverName, IncludeDeleted: &includeDeleted}
567-
versions, _, err := s.db.ListServers(ctx, tx, filter, "", 1000)
568-
if err != nil {
569-
return nil, fmt.Errorf("failed to list server versions: %w", err)
570-
}
571-
572-
for _, version := range versions {
573-
if version.Meta.Official != nil &&
574-
version.Meta.Official.Status == model.StatusDeleted {
575-
if err := s.validateNoDuplicateRemoteURLs(ctx, tx, version.Server); err != nil {
576-
return nil, err
577-
}
578-
}
579-
}
580-
}
581-
582509
// Update all versions' status in a single database call
583510
if _, err := s.db.SetAllVersionsStatus(ctx, tx, serverName, statusChange.NewStatus, statusChange.StatusMessage); err != nil {
584511
return nil, err

0 commit comments

Comments
 (0)