Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cmd/registry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
defer cancel()

// Connect to MongoDB
db, err = database.NewMongoDB(ctx, cfg.DatabaseURL, cfg.DatabaseName, cfg.CollectionName)
db, err = database.NewMongoDB(ctx, cfg.DatabaseURL, cfg.DatabaseName, cfg.CollectionName, cfg.VerificationCollectionName)
if err != nil {
log.Printf("Failed to connect to MongoDB: %v", err)
return
Expand All @@ -65,6 +65,7 @@ func main() {
registryService = service.NewRegistryServiceWithDB(db)
log.Printf("MongoDB database name: %s", cfg.DatabaseName)
log.Printf("MongoDB collection name: %s", cfg.CollectionName)
log.Printf("MongoDB verification collection name: %s", cfg.VerificationCollectionName)

// Store the MongoDB instance for later cleanup
defer func() {
Expand Down
54 changes: 54 additions & 0 deletions examples/dns-verify/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"fmt"
"log"
"os"

"github.com/modelcontextprotocol/registry/internal/verification"
)

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: dns-verify <domain> <token>")
fmt.Println("Example: dns-verify example.com TBeVXe_X4npM6p8vpzStnA")
os.Exit(1)
}

domain := os.Args[1]
token := os.Args[2]

fmt.Printf("🔍 Verifying DNS record for domain: %s\n", domain)
fmt.Printf("🎯 Expected token: %s\n", token)
fmt.Printf("📋 Expected DNS record: mcp-verify=%s\n\n", token)

// Perform DNS verification
result, err := verification.VerifyDNSRecord(domain, token)
if err != nil {
log.Printf("❌ DNS verification error: %v", err)
os.Exit(1)
}

// Display results
fmt.Printf("📊 Verification Results:\n")
fmt.Printf(" Success: %t\n", result.Success)
fmt.Printf(" Domain: %s\n", result.Domain)
fmt.Printf(" Token: %s\n", result.Token)
fmt.Printf(" Duration: %s\n", result.Duration)
fmt.Printf(" Message: %s\n", result.Message)

if len(result.TXTRecords) > 0 {
fmt.Printf("\n📝 Found TXT Records:\n")
for i, record := range result.TXTRecords {
fmt.Printf(" %d. %s\n", i+1, record)
}
}

if result.Success {
fmt.Println("\n✅ Domain verification successful!")
os.Exit(0)
} else {
fmt.Println("\n❌ Domain verification failed!")
os.Exit(1)
}
}
111 changes: 111 additions & 0 deletions internal/api/handlers/v0/domain_normalization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package v0

import (
"testing"
)

func TestNormalizeDomain(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "simple domain",
input: "example.com",
expected: "example.com",
},
{
name: "domain with subdomain",
input: "api.example.com",
expected: "api.example.com",
},
{
name: "domain with https protocol",
input: "https://example.com",
expected: "example.com",
},
{
name: "domain with http protocol",
input: "http://example.com",
expected: "example.com",
},
{
name: "domain with path",
input: "https://example.com/path/to/resource",
expected: "example.com",
},
{
name: "domain with query parameters",
input: "https://example.com?param=value",
expected: "example.com",
},
{
name: "domain with port",
input: "https://example.com:8080",
expected: "example.com:8080",
},
{
name: "mixed case domain",
input: "EXAMPLE.COM",
expected: "example.com",
},
{
name: "domain with mixed case and protocol",
input: "https://API.EXAMPLE.COM/path",
expected: "api.example.com",
},
{
name: "github.io domain",
input: "username.github.io",
expected: "username.github.io",
},
{
name: "github.io with protocol and path",
input: "https://username.github.io/project",
expected: "username.github.io",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := normalizeDomain(tt.input)
if err != nil {
t.Errorf("normalizeDomain(%q) returned unexpected error: %v", tt.input, err)
return
}
if result != tt.expected {
t.Errorf("normalizeDomain(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}

func TestNormalizeDomainErrors(t *testing.T) {
errorTests := []struct {
name string
input string
}{
{
name: "empty string",
input: "",
},
{
name: "whitespace only",
input: " ",
},
{
name: "malformed URL",
input: "http://",
},
}

for _, tt := range errorTests {
t.Run(tt.name, func(t *testing.T) {
result, err := normalizeDomain(tt.input)
if err == nil {
t.Errorf("normalizeDomain(%q) = %q, expected error", tt.input, result)
}
})
}
}
Loading