* feat(#606): support auth mode + bearer token when adding HTTP MCP servers - Extend AddMcpServerRequest with auth (none|header|oauth) and bearerToken - Add auth mode FilterChip selector in HTTP add-server dialog - Conditionally show masked bearer token field when auth == header - Wire new fields through McpServersViewModel request builder Backend contract: exactly one of url/command required; bearer_token requires auth == "header"; args/env only for stdio. SnakeCase naming strategy auto-serializes bearerToken -> bearer_token. Fixes #606 * fix(#606): address agy review — remember PasswordVisualTransformation + FlowRow for auth chips - Wrap PasswordVisualTransformation in remember {} to avoid per-recomposition allocation - Use FlowRow for the 3 auth-mode FilterChips so they wrap on narrow screens instead of overflowing
This commit is contained in:
4 files changed
+73
No files matched your search
@@ -31,6 +31,8 @@ data class AddMcpServerRequest(
|
|||||||
val command: String? = null,
|
val command: String? = null,
|
||||||
val args: List<String>? = null,
|
val args: List<String>? = null,
|
||||||
val env: Map<String, String>? = null,
|
val env: Map<String, String>? = null,
|
||||||
|
val auth: String? = null, // "none" | "header" | "oauth"
|
||||||
|
val bearerToken: String? = null, // sent only when auth == "header"
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.compose.foundation.clickable
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
@@ -28,6 +29,7 @@ import androidx.compose.material3.Card
|
|||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.FilterChip
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@@ -51,6 +53,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
@@ -256,6 +259,45 @@ private fun AddServerSection(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.height(spacing.sm))
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.mcp_servers_auth_mode),
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(spacing.xs))
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(spacing.sm),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(spacing.sm),
|
||||||
|
) {
|
||||||
|
FilterChip(
|
||||||
|
selected = state.addServerAuth == "none",
|
||||||
|
onClick = { viewModel.updateAddServerAuth("none") },
|
||||||
|
label = { Text(stringResource(R.string.mcp_servers_auth_none)) },
|
||||||
|
)
|
||||||
|
FilterChip(
|
||||||
|
selected = state.addServerAuth == "header",
|
||||||
|
onClick = { viewModel.updateAddServerAuth("header") },
|
||||||
|
label = { Text(stringResource(R.string.mcp_servers_auth_header)) },
|
||||||
|
)
|
||||||
|
FilterChip(
|
||||||
|
selected = state.addServerAuth == "oauth",
|
||||||
|
onClick = { viewModel.updateAddServerAuth("oauth") },
|
||||||
|
label = { Text(stringResource(R.string.mcp_servers_auth_oauth)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (state.addServerAuth == "header") {
|
||||||
|
Spacer(modifier = Modifier.height(spacing.sm))
|
||||||
|
OutlinedTextField(
|
||||||
|
value = state.addServerBearerToken,
|
||||||
|
onValueChange = viewModel::updateAddServerBearerToken,
|
||||||
|
label = { Text(stringResource(R.string.mcp_servers_field_bearer_token)) },
|
||||||
|
singleLine = true,
|
||||||
|
visualTransformation = remember { PasswordVisualTransformation() },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = state.addServerCommand,
|
value = state.addServerCommand,
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ data class McpServersUiState(
|
|||||||
val addServerUrl: String = "",
|
val addServerUrl: String = "",
|
||||||
val addServerCommand: String = "",
|
val addServerCommand: String = "",
|
||||||
val addServerArgs: String = "",
|
val addServerArgs: String = "",
|
||||||
|
val addServerAuth: String = "none", // "none" | "header" | "oauth"
|
||||||
|
val addServerBearerToken: String = "",
|
||||||
val addingServer: Boolean = false,
|
val addingServer: Boolean = false,
|
||||||
// Env vars for editing
|
// Env vars for editing
|
||||||
val editingEnvFor: String? = null,
|
val editingEnvFor: String? = null,
|
||||||
@@ -204,6 +206,14 @@ class McpServersViewModel :
|
|||||||
_uiState.update { it.copy(addServerArgs = v) }
|
_uiState.update { it.copy(addServerArgs = v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateAddServerAuth(v: String) {
|
||||||
|
_uiState.update { it.copy(addServerAuth = v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateAddServerBearerToken(v: String) {
|
||||||
|
_uiState.update { it.copy(addServerBearerToken = v) }
|
||||||
|
}
|
||||||
|
|
||||||
fun submitAddServer() {
|
fun submitAddServer() {
|
||||||
val state = _uiState.value
|
val state = _uiState.value
|
||||||
if (state.addServerName.isBlank()) {
|
if (state.addServerName.isBlank()) {
|
||||||
@@ -231,6 +241,18 @@ class McpServersViewModel :
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
},
|
},
|
||||||
|
auth =
|
||||||
|
if (state.addMode == AddServerMode.HTTP && state.addServerAuth != "none") {
|
||||||
|
state.addServerAuth
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
bearerToken =
|
||||||
|
if (state.addMode == AddServerMode.HTTP && state.addServerAuth == "header") {
|
||||||
|
state.addServerBearerToken.trim().ifBlank { null }
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
)
|
)
|
||||||
val result =
|
val result =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@@ -246,6 +268,8 @@ class McpServersViewModel :
|
|||||||
addServerUrl = "",
|
addServerUrl = "",
|
||||||
addServerCommand = "",
|
addServerCommand = "",
|
||||||
addServerArgs = "",
|
addServerArgs = "",
|
||||||
|
addServerAuth = "none",
|
||||||
|
addServerBearerToken = "",
|
||||||
toastMessage = "Server '${request.name}' added",
|
toastMessage = "Server '${request.name}' added",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -727,6 +727,11 @@
|
|||||||
<string name="mcp_servers_catalog_installing">Installing…</string>
|
<string name="mcp_servers_catalog_installing">Installing…</string>
|
||||||
<string name="mcp_servers_catalog_source">source: %1$s</string>
|
<string name="mcp_servers_catalog_source">source: %1$s</string>
|
||||||
<string name="mcp_servers_catalog_required_env">Required env vars</string>
|
<string name="mcp_servers_catalog_required_env">Required env vars</string>
|
||||||
|
<string name="mcp_servers_auth_mode">Authentication</string>
|
||||||
|
<string name="mcp_servers_auth_none">None</string>
|
||||||
|
<string name="mcp_servers_auth_header">Header</string>
|
||||||
|
<string name="mcp_servers_auth_oauth">OAuth</string>
|
||||||
|
<string name="mcp_servers_field_bearer_token">Bearer token</string>
|
||||||
|
|
||||||
<!-- Gateway Screen -->
|
<!-- Gateway Screen -->
|
||||||
<string name="gateway_status_running">GATEWAY RUNNING</string>
|
<string name="gateway_status_running">GATEWAY RUNNING</string>
|
||||||
|
|||||||
Reference in new issue
Block a user