Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/mcp_registry/registry/logo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ defmodule McpRegistry.Registry.Logo do

defp valid_login(_), do: nil

# avatars.githubusercontent.com answers a login directly with the image, no
# redirect -- github.com/<login>.png costs an extra round trip per logo.
defp avatar(login), do: "https://avatars.githubusercontent.com/#{login}?size=#{@avatar_px}"
# github.com/<login>.png, not the avatars.githubusercontent.com/<login>
# shortcut. The shortcut saves a redirect but returns GitHub's grey ghost
# placeholder for some organisations -- Microsoft and GitHub both got it --
# so on the live grid unrelated listings shared one blank octocat. The
# documented form redirects to the real image, and 404s for a login that
# does not exist, which lets the monogram show through.
defp avatar(login), do: "https://github.com/#{login}.png?size=#{@avatar_px}"

# Lower sorts first. Dark-theme icons last; then SVG; then the smallest
# raster that is big enough; then any raster; unknown sizes in the middle.
Expand Down
6 changes: 3 additions & 3 deletions test/mcp_registry/logo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ defmodule McpRegistry.Registry.LogoTest do

test "an io.github namespace gets that verified owner's avatar" do
assert {:github, url} = Logo.for_server(server(%{name: "io.github.troyhunt/hibp"}))
assert url == "https://avatars.githubusercontent.com/troyhunt?size=96"
assert url == "https://github.com/troyhunt.png?size=96"
end

test "a domain namespace falls back to its repository owner" do
s = server(%{repository_url: "https://github.com/cloudflare/mcp-server-cloudflare"})
assert {:repository, url} = Logo.for_server(s)
assert url =~ "/cloudflare?"
assert url =~ "/cloudflare.png?"
end

test "the namespace beats the repository, because only it is verified" do
s = server(%{name: "io.github.alice/x", repository_url: "https://github.com/bob/x"})
assert {:github, url} = Logo.for_server(s)
assert url =~ "/alice?"
assert url =~ "/alice.png?"
end

test "nothing on the record means no logo, never a guess" do
Expand Down
6 changes: 3 additions & 3 deletions test/mcp_registry_web/live/server_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ defmodule McpRegistryWeb.ServerLiveTest do

{:ok, _view, html} = live(conn, "/servers/#{server.name}")

assert html =~ "https://avatars.githubusercontent.com/troyhunt?size=96"
assert html =~ "https://github.com/troyhunt.png?size=96"
# It removes itself if it fails, so the monogram beneath shows instead.
assert html =~ ~s(onerror="this.remove\(\)")
assert html =~ ~s(referrerpolicy="no-referrer")
Expand All @@ -104,7 +104,7 @@ defmodule McpRegistryWeb.ServerLiveTest do
{:ok, _view, html} = live(conn, "/servers/#{server.name}")

assert html =~ "https://acme.test/logo.svg"
refute html =~ "avatars.githubusercontent.com"
refute html =~ "github.com/acme.png"
assert html =~ "object-contain"
end

Expand All @@ -125,7 +125,7 @@ defmodule McpRegistryWeb.ServerLiveTest do
server_fixture(%{name: "io.github.gridowner/x-#{System.unique_integer([:positive])}"})
{:ok, _view, html} = live(conn, ~p"/servers")

assert html =~ "avatars.githubusercontent.com/gridowner"
assert html =~ "github.com/gridowner.png"
end
end

Expand Down
Loading