Preserve MCP registration scope across client operations (#61257)

## Why

MCP servers registered under the same name in different environments need distinct inventory, routing, and status reporting.

## What changed

- Keep MCP inventory and runtime status keyed by registration scope so same-named servers remain separate.
- Add optional `environmentId` selectors for status lookup, tool calls, resource reads, and OAuth login. Omitting the selector preserves existing name-only routing.
- Carry environment identity through startup notifications, elicitation requests, and tool-call history, and display it in the TUI.
- Support `/mcp login <name> --environment <id>` and update generated protocol schemas and SDK types.

## Testing

Add integration coverage for two environments with identically named MCP servers, tools, and resource URIs. Verify separate inventory, explicit environment routing, legacy routing when the selector is omitted, and errors for unknown environments. Update protocol and TUI tests for environment identity.

GitOrigin-RevId: 074a3db10549438cb6aff33eb7bed10791adae4d
This commit is contained in:
sayan-oai
2026-11-13 04:51:06 +00:00
committed by copyberry
parent 7eaaee4270
commit 6fcfa75a9f
190 changed files with 1821 additions and 502 deletions
@@ -77,6 +77,7 @@ pub(crate) fn historical_tool_fallback(
}
ThreadItemPayload::McpToolCall {
server,
environment_id,
tool,
status,
result,
@@ -88,6 +89,10 @@ pub(crate) fn historical_tool_fallback(
McpToolCallStatus::Completed => "Completed · result unavailable",
McpToolCallStatus::Failed => "Failed · result unavailable",
};
let server = crate::app_server_approval_conversions::mcp_server_label(
server,
environment_id.as_deref(),
);
vec![format!("mcp tool: {server}/{tool} · {status}").dim().into()]
}
ThreadItemPayload::CollabAgentToolCall {
@@ -207,6 +212,7 @@ impl McpHistory {
let ThreadItemPayload::McpToolCall {
id,
server,
environment_id,
tool,
status,
arguments,
@@ -238,6 +244,7 @@ impl McpHistory {
id,
invocation: McpInvocation {
server,
environment_id,
tool,
arguments: Some(arguments),
},
@@ -37,6 +37,7 @@ fn command_item(status: CommandExecutionStatus) -> ThreadItemPayload {
fn mcp_item(server: &str, id: &str) -> ThreadItemPayload {
ThreadItemPayload::McpToolCall {
environment_id: None,
id: id.to_string(),
server: server.to_string(),
tool: "js".to_string(),