fix: use a catalog entry's static OAuth credentials when generating tool previews - #6831
fix: use a catalog entry's static OAuth credentials when generating tool previews#6831we4sz wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for resolving static OAuth credentials for ephemeral “tool preview” MCP servers by carrying the originating catalog entry name through preview server creation and OAuth lookup.
Changes:
- Pass catalog entry name/ID into
tempServerAndConfigand stamp it onto the temporaryMCPServerspec. - Carry
MCPServerCatalogEntryNameinto the OAuth handler so credentials can be resolved without fetching a persisted server. - Update OAuth credential lookup to prefer the carried catalog entry name, with fallback to reading it from a persisted server.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/api/handlers/mcpgateway/oauth/mcpoauthhandler.go | Carries catalog entry name into the OAuth handler and uses it to resolve static OAuth credentials. |
| pkg/api/handlers/mcpcatalogs.go | Threads catalog entry name into temp preview server creation so OAuth lookup can resolve credentials for non-persisted servers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| req.ObotNamespace, | ||
| entry.Namespace, | ||
| catalogName, | ||
| componentEntry.CatalogEntryID, | ||
| componentEntry.Manifest, | ||
| config.Config, | ||
| config.URL, |
| } | ||
|
|
||
| func tempServerAndConfig(ctx context.Context, gatewayClient *gclient.Client, client client.Client, localK8sClient client.Client, obotNamespace, namespace, catalogName string, entryManifest types.MCPServerCatalogEntryManifest, config map[string]string, url, baseURL string) (v1.MCPServer, mcp.ServerConfig, error) { | ||
| func tempServerAndConfig(ctx context.Context, gatewayClient *gclient.Client, client client.Client, localK8sClient client.Client, obotNamespace, namespace, catalogName, catalogEntryName string, entryManifest types.MCPServerCatalogEntryManifest, config map[string]string, url, baseURL string) (v1.MCPServer, mcp.ServerConfig, error) { |
| gatewayClient *client.Client | ||
| stateMgr *stateManager | ||
| mcpID string | ||
| catalogEntryName string | ||
| mcpURL string |
…ool previews GenerateToolPreviews launches an ephemeral, never-persisted MCP server (tool-preview-<hash>) to enumerate tools. For an OAuth-protected remote server this needs the catalog entry's configured static OAuth client, but it could never be found: the temp server had no MCPServerCatalogEntryName, and the OAuth ClientCredLookup resolves the static client by fetching the server from storage by name and reading that field off it. Since the temp server isn't persisted, the lookup returned 'no credentials found' and fell back to Dynamic Client Registration, which strict IdPs (e.g. Keycloak) reject. Set MCPServerCatalogEntryName on the temp preview server, carry it on the OAuth handler (from the passed mcpServer), and have Lookup use the carried entry name directly, falling back to the storage lookup for persisted servers.
5805ea6 to
db6abcf
Compare
|
Thanks for the review. Addressing the three points:
gofmt clean; affected packages build. Verified end-to-end against a Keycloak-fronted remote server with static OAuth configured on the entry — tool previews now resolve the entry’s static client and complete the login flow instead of falling back to DCR. |
Generating tool previews for an OAuth-protected remote catalog entry fails even when the entry has static OAuth credentials configured.
Problem
GenerateToolPreviewslaunches an ephemeral, never-persisted MCP server (tool-preview-<hash>) and connects to it to enumerate tools. For an OAuth-protected remote server this should use the catalog entry's configured static OAuth client, but it never can:tempServerAndConfigbuilds the temp server without settingSpec.MCPServerCatalogEntryName.ClientCredLookup(mcpOAuthHandler.Lookup) resolves the static client by fetching the server from storage by name and readingMCPServerCatalogEntryNameoff it. The temp preview server isn't persisted, so thatGetfails,Lookupreturns "no credentials found", and the client falls back to Dynamic Client Registration — which strict IdPs (e.g. Keycloak) reject (invalid_client_metadata), surfacing as a 500.Fix
MCPServerCatalogEntryNameon the temp preview server (alltempServerAndConfigcall sites pass the entry / component catalog-entry name).mcpOAuthHandler(set inCheckForMCPAuthfrom the passedmcpServer).Lookupuses the carried entry name to resolve the static OAuth credentials directly, falling back to the storage lookup for persisted servers.Testing
Built locally and verified against an OAuth-protected remote server (Keycloak-fronted) with static OAuth credentials configured on the catalog entry: "Populate Tool Preview" now resolves the entry's static client, performs the normal login flow, and lists tools — instead of falling back to DCR and returning a 500.
gofmtclean; affected packages build.