Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): derive safe names for plugin MCP servers (#10837)

Frezcb12c1e54ebe4
diff --git a/server/internal/daemon/remote_mcp_broker.go b/server/internal/daemon/remote_mcp_broker.go
index 7e92ca0e06..c939778725 100644
--- a/server/internal/daemon/remote_mcp_broker.go
+++ b/server/internal/daemon/remote_mcp_broker.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
+ "crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
@@ -197,10 +198,10 @@ func remoteMCPServerName(connection remotemcp.Connection) string {
}
return '-'
}, strings.ToLower(connection.ContributionKey))
- suffix := strings.ReplaceAll(connection.ContributionID, "-", "")
- if len(suffix) > 8 {
- suffix = suffix[:8]
- }
+ // Plugin contribution IDs share a colon-delimited prefix. Hash the complete
+ // identity so the provider name is safe and different installations stay distinct.
+ digest := sha256.Sum256([]byte(connection.ContributionID))
+ suffix := hex.EncodeToString(digest[:8])
return "plugin-" + name + "-" + suffix
}
diff --git a/server/internal/daemon/remote_mcp_broker_test.go b/server/internal/daemon/remote_mcp_broker_test.go
index 056179268e..2fb37c38a9 100644
--- a/server/internal/daemon/remote_mcp_broker_test.go
+++ b/server/internal/daemon/remote_mcp_broker_test.go
@@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "regexp"
"strings"
"testing"
@@ -17,6 +18,30 @@ import (
"github.com/multica-ai/multica/server/pkg/remotemcp/remotemcptest"
)
+func TestRemoteMCPServerNameUsesSafeDistinctContributionIdentities(t *testing.T) {
+ connections := []remotemcp.Connection{
+ {ContributionKey: "example__toolbox", ContributionID: "plugin:12345678-1234-4234-8234-1234567890ab:toolbox"},
+ {ContributionKey: "example__toolbox", ContributionID: "plugin:12345678-1234-4234-8234-1234567890ac:toolbox"},
+ {ContributionKey: "example__toolbox", ContributionID: "plugin:12345678-1234-4234-8234-1234567890ab:other_hook"},
+ {ContributionKey: "Mixed Case/☃", ContributionID: "00000000-0000-0000-0000-000000000001"},
+ }
+ safeName := regexp.MustCompile(`^[a-z0-9_-]+$`)
+ seen := map[string]bool{}
+ for _, connection := range connections {
+ name := remoteMCPServerName(connection)
+ if !safeName.MatchString(name) {
+ t.Errorf("Codex-incompatible server name %q for %q", name, connection.ContributionID)
+ }
+ if seen[name] {
+ t.Errorf("distinct contribution identities alias to %q", name)
+ }
+ seen[name] = true
+ if again := remoteMCPServerName(connection); again != name {
+ t.Fatalf("server identity changed: %q != %q", again, name)
+ }
+ }
+}
+
func TestRemoteMCPProxyFiltersToolsAndInjectsCredential(t *testing.T) {
fixture := remotemcptest.NewServer()
defer fixture.Close()
@@ -117,7 +142,9 @@ func TestRemoteMCPProxyPreservesAcceptedNotificationStatus(t *testing.T) {
}
func TestRemoteMCPProxyRechecksCredentialBeforeUpstreamCall(t *testing.T) {
+ const contributionID = "plugin:12345678-1234-4234-8234-1234567890ab:toolbox"
called := false
+ credentialChecked := false
upstream := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { called = true }))
defer upstream.Close()
endpoint, _ := url.Parse(upstream.URL)
@@ -125,18 +152,22 @@ func TestRemoteMCPProxyRechecksCredentialBeforeUpstreamCall(t *testing.T) {
endpoint: endpoint, client: upstream.Client(), path: "/capability",
semaphore: make(chan struct{}, remoteMCPMaxConcurrency),
connection: remotemcp.Connection{
- ContributionID: "contribution", CredentialHeader: "Authorization",
+ ContributionID: contributionID, CredentialHeader: "Authorization",
ApprovedTools: []remotemcp.Tool{{Name: "allowed"}},
},
- resolveCredential: func(context.Context, string) (http.Header, error) {
+ resolveCredential: func(_ context.Context, id string) (http.Header, error) {
+ credentialChecked = true
+ if id != contributionID {
+ t.Errorf("credential lookup identity = %q, want original %q", id, contributionID)
+ }
return nil, errors.New("revoked")
},
}
request := httptest.NewRequest(http.MethodPost, "/capability", bytes.NewBufferString(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"allowed","arguments":{}}}`))
response := httptest.NewRecorder()
proxy.ServeHTTP(response, request)
- if called || !strings.Contains(response.Body.String(), "revoked or unavailable") {
- t.Fatalf("called=%v response=%s", called, response.Body.String())
+ if !credentialChecked || called || !strings.Contains(response.Body.String(), "revoked or unavailable") {
+ t.Fatalf("credentialChecked=%v called=%v response=%s", credentialChecked, called, response.Body.String())
}
}