@Summary Get MCP server config @x-apidocgen {"skip": true} EXPERIMENTAL: this endpoint is experimental and is subject to change. nolint:revive // HTTP handler writes to ResponseWriter.
(rw http.ResponseWriter, r *http.Request)
| 478 | // |
| 479 | //nolint:revive // HTTP handler writes to ResponseWriter. |
| 480 | func (api *API) getMCPServerConfig(rw http.ResponseWriter, r *http.Request) { |
| 481 | ctx := r.Context() |
| 482 | apiKey := httpmw.APIKey(r) |
| 483 | |
| 484 | mcpServerID, ok := parseMCPServerConfigID(rw, r) |
| 485 | if !ok { |
| 486 | return |
| 487 | } |
| 488 | |
| 489 | isAdmin := api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig) |
| 490 | |
| 491 | var config database.MCPServerConfig |
| 492 | var err error |
| 493 | if isAdmin { |
| 494 | config, err = api.Database.GetMCPServerConfigByID(ctx, mcpServerID) |
| 495 | } else { |
| 496 | //nolint:gocritic // All authenticated users can view enabled MCP server configs. |
| 497 | config, err = api.Database.GetMCPServerConfigByID(dbauthz.AsSystemRestricted(ctx), mcpServerID) |
| 498 | if err == nil && !config.Enabled { |
| 499 | httpapi.ResourceNotFound(rw) |
| 500 | return |
| 501 | } |
| 502 | } |
| 503 | if err != nil { |
| 504 | if httpapi.Is404Error(err) { |
| 505 | httpapi.ResourceNotFound(rw) |
| 506 | return |
| 507 | } |
| 508 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 509 | Message: "Failed to get MCP server config.", |
| 510 | Detail: err.Error(), |
| 511 | }) |
| 512 | return |
| 513 | } |
| 514 | |
| 515 | var sdkConfig codersdk.MCPServerConfig |
| 516 | if isAdmin { |
| 517 | sdkConfig = convertMCPServerConfig(config) |
| 518 | } else { |
| 519 | sdkConfig = convertMCPServerConfigRedacted(config) |
| 520 | } |
| 521 | |
| 522 | // Populate AuthConnected for the calling user. Attempt to |
| 523 | // refresh the token so the status is accurate. |
| 524 | if config.AuthType == "oauth2" { |
| 525 | //nolint:gocritic // Need to check user token for this server. |
| 526 | userTokens, err := api.Database.GetMCPServerUserTokensByUserID(dbauthz.AsSystemRestricted(ctx), apiKey.UserID) |
| 527 | if err != nil { |
| 528 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 529 | Message: "Failed to get user tokens.", |
| 530 | Detail: err.Error(), |
| 531 | }) |
| 532 | return |
| 533 | } |
| 534 | for _, tok := range userTokens { |
| 535 | if tok.MCPServerConfigID == config.ID { |
| 536 | sdkConfig.AuthConnected = api.refreshMCPUserToken(ctx, config, tok, apiKey.UserID) |
| 537 | break |
nothing calls this directly
no test coverage detected