Skip to content

Commit 7af461e

Browse files
Add OpenAI MCP server ownership verification route (#62)
Serve the OpenAI verification token at `/.well-known/openai-apps-challenge` to complete the app validation flow for their MCP directory listing. GitOrigin-RevId: 14efe30183c45bd8aac9444f52bced0cb60e6578
1 parent 5dbf258 commit 7af461e

6 files changed

Lines changed: 42 additions & 15 deletions

File tree

cmd/server.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"log"
5+
"net/http"
56
"os"
67

78
"github.com/mark3labs/mcp-go/server"
@@ -53,13 +54,26 @@ func Serve(transport string) *server.MCPServer {
5354
log.Print("using in-memory session store\n")
5455
sessionStore = session.NewInMemoryStore()
5556
}
56-
err := server.
57-
NewStreamableHTTPServer(s, server.WithHTTPContextFunc(multicontext.MultiHTTPContextFunc(
58-
session.ContextWithHTTPSession(sessionStore),
59-
authn.ContextWithAPITokenFromHeader,
60-
httpcontext.ContextWithHTTPRequest,
61-
))).
62-
Start(":10000")
57+
streamableServer := server.NewStreamableHTTPServer(s, server.WithHTTPContextFunc(multicontext.MultiHTTPContextFunc(
58+
session.ContextWithHTTPSession(sessionStore),
59+
authn.ContextWithAPITokenFromHeader,
60+
httpcontext.ContextWithHTTPRequest,
61+
)))
62+
63+
mux := http.NewServeMux()
64+
mux.Handle("/mcp", streamableServer)
65+
if token := os.Getenv("OPENAI_VERIFICATION_TOKEN"); token != "" {
66+
mux.HandleFunc("/.well-known/openai-apps-challenge", func(w http.ResponseWriter, r *http.Request) {
67+
w.Header().Set("Content-Type", "text/plain")
68+
w.Write([]byte(token))
69+
})
70+
}
71+
72+
httpServer := &http.Server{
73+
Addr: ":10000",
74+
Handler: mux,
75+
}
76+
err := httpServer.ListenAndServe()
6377
if err != nil {
6478
log.Fatalf("Starting Streamable server: %v\n:", err)
6579
}

pkg/keyvalue/tools_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keyvalue
33
import (
44
"context"
55
"net/http"
6+
"path/filepath"
67
"testing"
78

89
"github.com/mark3labs/mcp-go/mcp"
@@ -64,7 +65,7 @@ func TestCreateKeyValueTool(t *testing.T) {
6465
},
6566
}, nil)
6667

67-
ctx := createTestContext(ownerId)
68+
ctx := createTestContext(t, ownerId)
6869

6970
args := map[string]any{
7071
"name": kvName,
@@ -91,7 +92,9 @@ func TestCreateKeyValueTool(t *testing.T) {
9192
}
9293
}
9394

94-
func createTestContext(workspaceID string) context.Context {
95+
func createTestContext(t *testing.T, workspaceID string) context.Context {
96+
t.Helper()
97+
t.Setenv("RENDER_CONFIG_PATH", filepath.Join(t.TempDir(), "mcp-server.yaml"))
9598
ctx := session.ContextWithStdioSession(context.Background())
9699
sess := session.FromContext(ctx)
97100
sess.SetWorkspace(ctx, workspaceID)

pkg/metrics/test_helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package metrics
33
import (
44
"context"
55
"net/http"
6+
"path/filepath"
67
"time"
78

89
"github.com/render-oss/render-mcp-server/pkg/client"
@@ -86,10 +87,11 @@ type MetricsTestSuite struct {
8687
}
8788

8889
func (s *MetricsTestSuite) SetupTest() {
90+
s.T().Setenv("RENDER_CONFIG_PATH", filepath.Join(s.T().TempDir(), "mcp-server.yaml"))
8991
s.mockClient = &MockClientWithResponses{}
9092
s.repo = NewRepo(s.mockClient)
9193
s.ctx = session.ContextWithStdioSession(context.Background())
92-
94+
9395
// Set up a workspace for tests
9496
sess := session.FromContext(s.ctx)
9597
err := sess.SetWorkspace(s.ctx, "test-workspace-123")

pkg/postgres/tools_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package postgres
33
import (
44
"context"
55
"net/http"
6+
"path/filepath"
67
"testing"
78

89
"github.com/mark3labs/mcp-go/mcp"
@@ -65,7 +66,7 @@ func TestCreatePostgresTool(t *testing.T) {
6566
},
6667
}, nil)
6768

68-
ctx := createTestContext(ownerId)
69+
ctx := createTestContext(t, ownerId)
6970

7071
args := map[string]any{
7172
"name": dbName,
@@ -92,7 +93,9 @@ func TestCreatePostgresTool(t *testing.T) {
9293
}
9394
}
9495

95-
func createTestContext(workspaceID string) context.Context {
96+
func createTestContext(t *testing.T, workspaceID string) context.Context {
97+
t.Helper()
98+
t.Setenv("RENDER_CONFIG_PATH", filepath.Join(t.TempDir(), "mcp-server.yaml"))
9699
ctx := session.ContextWithStdioSession(context.Background())
97100
sess := session.FromContext(ctx)
98101
sess.SetWorkspace(ctx, workspaceID)

pkg/service/tools_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"path/filepath"
78
"testing"
89

910
"github.com/mark3labs/mcp-go/mcp"
@@ -201,7 +202,7 @@ func TestCreateWebServiceTool(t *testing.T) {
201202
},
202203
}, nil)
203204

204-
ctx := createTestContext(ownerId)
205+
ctx := createTestContext(t, ownerId)
205206

206207
args := map[string]any{
207208
"name": serviceName,
@@ -373,7 +374,7 @@ func TestCreateCronJobTool(t *testing.T) {
373374
}, nil)
374375

375376
// Create a test context with a session
376-
ctx := createTestContext(ownerId)
377+
ctx := createTestContext(t, ownerId)
377378

378379
// Build the request
379380
request := mcp.CallToolRequest{}
@@ -410,7 +411,9 @@ func TestCreateCronJobTool(t *testing.T) {
410411
}
411412

412413
// createTestContext creates a test context with a session that has the given workspace ID
413-
func createTestContext(workspaceID string) context.Context {
414+
func createTestContext(t *testing.T, workspaceID string) context.Context {
415+
t.Helper()
416+
t.Setenv("RENDER_CONFIG_PATH", filepath.Join(t.TempDir(), "mcp-server.yaml"))
414417
ctx := session.ContextWithStdioSession(context.Background())
415418
sess := session.FromContext(ctx)
416419
sess.SetWorkspace(ctx, workspaceID)

render.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
buildCommand: go build -tags netgo -ldflags '-s -w' -o app
1212
startCommand: ./app --transport http
1313
envVars:
14+
- key: OPENAI_VERIFICATION_TOKEN
15+
sync: false
1416
- key: REDIS_URL
1517
fromService:
1618
name: mcp-kv

0 commit comments

Comments
 (0)