()
| 96 | } |
| 97 | |
| 98 | func main() { |
| 99 | flag.Parse() |
| 100 | metadata := &oauthex.ProtectedResourceMetadata{ |
| 101 | Resource: fmt.Sprintf("http://localhost:%d/mcp", *port), |
| 102 | AuthorizationServers: []string{authorizationServer}, |
| 103 | ScopesSupported: []string{"read"}, |
| 104 | } |
| 105 | http.Handle("/.well-known/oauth-protected-resource", auth.ProtectedResourceMetadataHandler(metadata)) |
| 106 | |
| 107 | server := mcp.NewServer(&mcp.Implementation{ |
| 108 | Name: "test-server", |
| 109 | Version: "1.0.0", |
| 110 | }, nil) |
| 111 | server.AddReceivingMiddleware(createLoggingMiddleware()) |
| 112 | mcp.AddTool(server, &mcp.Tool{Name: "echo"}, echo) |
| 113 | |
| 114 | handler := mcp.NewStreamableHTTPHandler(func(req *http.Request) *mcp.Server { |
| 115 | return server |
| 116 | }, nil) |
| 117 | |
| 118 | authMiddleware := auth.RequireBearerToken(verifyToken, &auth.RequireBearerTokenOptions{ |
| 119 | Scopes: []string{"read"}, |
| 120 | ResourceMetadataURL: fmt.Sprintf("http://localhost:%d/.well-known/oauth-protected-resource", *port), |
| 121 | }) |
| 122 | |
| 123 | http.Handle("/mcp", authMiddleware(handler)) |
| 124 | |
| 125 | log.Printf("Starting server on http://localhost:%d", *port) |
| 126 | log.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", *port), nil)) |
| 127 | } |
| 128 | |
| 129 | // createLoggingMiddleware creates an MCP middleware that logs method calls. |
| 130 | func createLoggingMiddleware() mcp.Middleware { |
nothing calls this directly
no test coverage detected
searching dependent graphs…