Clarify Protocol Roles
Determine client vs. server from the call direction, and avoid conflating the internal Hub Server with an MCP Server.
A production-grade client also handles config merging, OAuth, capability discovery, namespace isolation, model visibility control, state push, and connection recovery. The source code distributes these responsibilities across the MCP crate and Session Actor.
Determine client vs. server from the call direction, and avoid conflating the internal Hub Server with an MCP Server.
Explain how tools flow from tools/list into the snapshot, search index, and model registry.
Place OAuth, state coalescing, client identity, and restart back-off within a single connection lifecycle.
McpClient initiates a stdio or Streamable HTTP connection and performs initialization, list_tools, and call_tool. The Computer Hub MCP Adapter is also described as bridging MCP Server tools into the Hub routing layer.
The Hub Server in xai-grok-workspace belongs to the xAI Computer Hub protocol. The current snapshot contains no entry point exposing Grok Build itself to arbitrary MCP clients via MCP transport, so this lesson confirms only the client role.
oauth_client_id
oauth_client_secret_env_var
oauth_scopescrates/codegen/xai-grok-config-types/src/mcp.rslet path = grok_home
.join("mcp_credentials.json");
// lock + load + insert + atomic saveThe source stores credentials in this file, handling concurrent writes with file locks and atomic saves.
crates/codegen/xai-grok-mcp/src/credentials.rs · oauth.rsserver__toolThe registration name consists of the server name, the reserved separator __, and the original tool name. The source requires exactly one separator occurrence in the full name to avoid parsing ambiguity and ensures that same-named tools from two servers have distinct ToolIds.
Disabled tools are stored in disabled_tool_registrations; only tools where model_visible is true enter the model-side Tool Bridge; tools with ui.resourceUri can be routed to UI notifications independently.
ToolMetadataSnapshot stores tool and server metadata. The BM25 index supports exact hits by qualified name or bare tool name before returning search results. mcp_initialized signals the search layer when capability discovery is complete.
pub struct ToolMetadataSnapshot {
pub tools: Vec<ToolMetadata>,
pub servers: Vec<ServerMetadata>,
pub mcp_initialized: bool,
}crates/codegen/xai-grok-shell/src/session/tool_index.rsmcp_dispatcher keys events on (server_name, event_kind) and applies last-write-wins within a 50 ms tumbling window. High-frequency tools/list_changed events ultimately push only a single ACP state update.
Before removing a dead client, the code compares client_id. If the disconnect event belongs to an already-replaced old client, the current client is preserved and the stale state is discarded.
stdio auto-restart uses a fixed back-off of 1s → 4s → 16s and checks guards for shutting down, disabled, and config-removed states. HTTP first attempts in-client recovery with its own back-off. After a successful reconnect, tools are re-discovered and re-registered, then the snapshot is refreshed.
Deliverables
State diagram + 6 test cases
tools/list_changed events and write out the expected notification count after 50 ms coalescing.client_id guard protects the new connection.The engineering effort in MCP integration concentrates at the protocol periphery. Naming, visibility, identity, state coalescing, and recovery strategy together determine whether a connection stays reliably operational over time.
Source Snapshot Note: This page is compiled from the local grok-build-main source code covering MCP, config-types, shell session, and computer-hub adapter. Code excerpts are for educational purposes. Conclusions about the MCP server role are stated conservatively; the internal Hub Server is not treated as evidence of a general-purpose MCP server.