{"slug": "grok-s-public-source-supports-stateless-mcp-on-http-not-stdio", "title": "Grok's public source supports stateless MCP on HTTP, not stdio", "summary": "The public source code for xAI's Grok, in a servers.rs file of 5,256 lines (4,849 lines of code, 219 KB), implements stateless Model Context Protocol (MCP) over HTTP rather than stdio transport. The file listing shows no substantive implementation detail beyond the transport choice, so the practical effect for developers is that Grok's MCP server integration is built around HTTP-based, stateless connections.", "body_md": "## Repository navigation\n\n## Expand file tree\n\n/\n\nCopy path\n# servers.rs\n\nMore file actions\n\n5256 lines (4849 loc) · 219 KB\n\n/\n\nCopy path\n# servers.rs\n\n## File metadata and controls\n\n5256 lines (4849 loc) · 219 KB\n\n1\n\n2\n\n3\n\n4\n\n5\n\n6\n\n7\n\n8\n\n9\n\n10\n\n11\n\n12\n\n13\n\n14\n\n15\n\n16\n\n17\n\n18\n\n19\n\n20\n\n21\n\n22\n\n23\n\n24\n\n25\n\n26\n\n27\n\n28\n\n29\n\n30\n\n31\n\n32\n\n33\n\n34\n\n35\n\n36\n\n37\n\n38\n\n39\n\n40\n\n41\n\n42\n\n43\n\n44\n\n45\n\n46\n\n47\n\n48\n\n49\n\n50\n\n51\n\n52\n\n53\n\n54\n\n55\n\n56\n\n57\n\n58\n\n59\n\n60\n\n61\n\n62\n\n63\n\n64\n\n65\n\n66\n\n67\n\n68\n\n69\n\n70\n\n71\n\n72\n\n73\n\n74\n\n75\n\n76\n\n77\n\n78\n\n79\n\n80\n\n81\n\n82\n\n83\n\n84\n\n85\n\n86\n\n87\n\n88\n\n89\n\n90\n\n91\n\n92\n\n93\n\n94\n\n95\n\n96\n\n97\n\n98\n\n99\n\n100\n\n101\n\n102\n\n103\n\n104\n\n105\n\n106\n\n107\n\n108\n\n109\n\n110\n\n111\n\n112\n\n113\n\n114\n\n115\n\n116\n\n117\n\n118\n\n119\n\n120\n\n121\n\n122\n\n123\n\n124\n\n125\n\n126\n\n127\n\n128\n\n129\n\n130\n\n131\n\n132\n\n133\n\n134\n\n135\n\n136\n\n137\n\n138\n\n139\n\n140\n\n141\n\n142\n\n143\n\n144\n\n145\n\n146\n\n147\n\n148\n\n149\n\n150\n\n151\n\n152\n\n153\n\n154\n\n155\n\n156\n\n157\n\n158\n\n159\n\n160\n\n161\n\n162\n\n163\n\n164\n\n165\n\n166\n\n167\n\n168\n\n169\n\n170\n\n171\n\n172\n\n173\n\n174\n\n175\n\n176\n\n177\n\n178\n\n179\n\n180\n\n181\n\n182\n\n183\n\n184\n\n185\n\n186\n\n187\n\n188\n\n189\n\n190\n\n191\n\n192\n\n193\n\n194\n\n195\n\n196\n\n197\n\n198\n\n199\n\n200\n\n201\n\n202\n\n203\n\n204\n\n205\n\n206\n\n207\n\n208\n\n209\n\n210\n\n211\n\n212\n\n213\n\n214\n\n215\n\n216\n\n217\n\n218\n\n219\n\n220\n\n221\n\n222\n\n223\n\n224\n\n225\n\n226\n\n227\n\n228\n\n229\n\n230\n\n231\n\n232\n\n233\n\n234\n\n235\n\n236\n\n237\n\n238\n\n239\n\n240\n\n241\n\n242\n\n243\n\n244\n\n245\n\n246\n\n247\n\n248\n\n249\n\n250\n\n251\n\n252\n\n253\n\n254\n\n255\n\n256\n\n257\n\n258\n\n259\n\n260\n\n261\n\n262\n\n263\n\n264\n\n265\n\n266\n\n267\n\n268\n\n269\n\n270\n\n271\n\n272\n\n273\n\n274\n\n275\n\n276\n\n277\n\n278\n\n279\n\n280\n\n281\n\n282\n\n283\n\n284\n\n285\n\n286\n\n287\n\n288\n\n289\n\n290\n\n291\n\n292\n\n293\n\n294\n\n295\n\n296\n\n297\n\n298\n\n299\n\n300\n\n301\n\n302\n\n303\n\n304\n\n305\n\n306\n\n307\n\n308\n\n309\n\n310\n\n311\n\n312\n\n313\n\n314\n\n315\n\n316\n\n317\n\n318\n\n319\n\n320\n\n321\n\n322\n\n323\n\n324\n\n325\n\n326\n\n327\n\n328\n\n329\n\n330\n\n331\n\n332\n\n333\n\n334\n\n335\n\n336\n\n337\n\n338\n\n339\n\n340\n\n341\n\n342\n\n343\n\n344\n\n345\n\n346\n\n347\n\n348\n\n349\n\n350\n\n351\n\n352\n\n353\n\n354\n\n355\n\n356\n\n357\n\n358\n\n359\n\n360\n\n361\n\n362\n\n363\n\n364\n\n365\n\n366\n\n367\n\n368\n\n369\n\n370\n\n371\n\n372\n\n373\n\n374\n\n375\n\n376\n\n377\n\n378\n\n379\n\n380\n\n381\n\n382\n\n383\n\n384\n\n385\n\n386\n\n387\n\n388\n\n389\n\n390\n\n391\n\n392\n\n393\n\n394\n\n395\n\n396\n\n397\n\n398\n\n399\n\n400\n\n401\n\n402\n\n403\n\n404\n\n405\n\n406\n\n407\n\n408\n\n409\n\n410\n\n411\n\n412\n\n413\n\n414\n\n415\n\n416\n\n417\n\n418\n\n419\n\n420\n\n421\n\n422\n\n423\n\n424\n\n425\n\n426\n\n427\n\n428\n\n429\n\n430\n\n431\n\n432\n\n433\n\n434\n\n435\n\n436\n\n437\n\n438\n\n439\n\n440\n\n441\n\n442\n\n443\n\n444\n\n445\n\n446\n\n447\n\n448\n\n449\n\n450\n\n451\n\n452\n\n453\n\n454\n\n455\n\n456\n\n457\n\n458\n\n459\n\n460\n\n461\n\n462\n\n463\n\n464\n\n465\n\n466\n\n467\n\n468\n\n469\n\n470\n\n471\n\n472\n\n473\n\n474\n\n475\n\n476\n\n477\n\n478\n\n479\n\n480\n\n481\n\n482\n\n483\n\n484\n\n485\n\n486\n\n487\n\n488\n\n489\n\n490\n\n491\n\n492\n\n493\n\n494\n\n495\n\n496\n\n497\n\n498\n\n499\n\n500\n\n501\n\n502\n\n503\n\n504\n\n505\n\n506\n\n507\n\n508\n\n509\n\n510\n\n511\n\n512\n\n513\n\n514\n\n515\n\n516\n\n517\n\n518\n\n519\n\n520\n\n521\n\n522\n\n523\n\n524\n\n525\n\n526\n\n527\n\n528\n\n529\n\n530\n\n531\n\n532\n\n533\n\n534\n\n535\n\n536\n\n537\n\n538\n\n539\n\n540\n\n541\n\n542\n\n543\n\n544\n\n545\n\n546\n\n547\n\n548\n\n549\n\n550\n\n551\n\n552\n\n553\n\n554\n\n555\n\n556\n\n557\n\n558\n\n559\n\n560\n\n561\n\n562\n\n563\n\n564\n\n565\n\n566\n\n567\n\n568\n\n569\n\n570\n\n571\n\n572\n\n573\n\n574\n\n575\n\n576\n\n577\n\n578\n\n579\n\n580\n\n581\n\n582\n\n583\n\n584\n\n585\n\n586\n\n587\n\n588\n\n589\n\n590\n\n591\n\n592\n\n593\n\n594\n\n595\n\n596\n\n597\n\n598\n\n599\n\n600\n\n601\n\n602\n\n603\n\n604\n\n605\n\n606\n\n607\n\n608\n\n609\n\n610\n\n611\n\n612\n\n613\n\n614\n\n615\n\n616\n\n617\n\n618\n\n619\n\n620\n\n621\n\n622\n\n623\n\n624\n\n625\n\n626\n\n627\n\n628\n\n629\n\n630\n\n631\n\n632\n\n633\n\n634\n\n635\n\n636\n\n637\n\n638\n\n639\n\n640\n\n641\n\n642\n\n643\n\n644\n\n645\n\n646\n\n647\n\n648\n\n649\n\n650\n\n651\n\n652\n\n653\n\n654\n\n655\n\n656\n\n657\n\n658\n\n659\n\n660\n\n661\n\n662\n\n663\n\n664\n\n665\n\n666\n\n667\n\n668\n\n669\n\n670\n\n671\n\n672\n\n673\n\n674\n\n675\n\n676\n\n677\n\n678\n\n679\n\n680\n\n681\n\n682\n\n683\n\n684\n\n685\n\n686\n\n687\n\n688\n\n689\n\n690\n\n691\n\n692\n\n693\n\n694\n\n695\n\n696\n\n697\n\n698\n\n699\n\n700\n\n701\n\n702\n\n703\n\n704\n\n705\n\n706\n\n707\n\n708\n\n709\n\n710\n\n711\n\n712\n\n713\n\n714\n\n715\n\n716\n\n717\n\n718\n\n719\n\n720\n\n721\n\n722\n\n723\n\n724\n\n725\n\n726\n\n727\n\n728\n\n729\n\n730\n\n731\n\n732\n\n733\n\n734\n\n735\n\n736\n\n737\n\n738\n\n739\n\n740\n\n741\n\n742\n\n743\n\n744\n\n745\n\n746\n\n747\n\n748\n\n749\n\n750\n\n751\n\n752\n\n753\n\n754\n\n755\n\n756\n\n757\n\n758\n\n759\n\n760\n\n761\n\n762\n\n763\n\n764\n\n765\n\n766\n\n767\n\n768\n\n769\n\n770\n\n771\n\n772\n\n773\n\n774\n\n775\n\n776\n\n777\n\n778\n\n779\n\n780\n\n781\n\n782\n\n783\n\n784\n\n785\n\n786\n\n787\n\n788\n\n789\n\n790\n\n791\n\n792\n\n793\n\n794\n\n795\n\n796\n\n797\n\n798\n\n799\n\n800\n\n801\n\n802\n\n803\n\n804\n\n805\n\n806\n\n807\n\n808\n\n809\n\n810\n\n811\n\n812\n\n813\n\n814\n\n815\n\n816\n\n817\n\n818\n\n819\n\n820\n\n821\n\n822\n\n823\n\n824\n\n825\n\n826\n\n827\n\n828\n\n829\n\n830\n\n831\n\n832\n\n833\n\n834\n\n835\n\n836\n\n837\n\n838\n\n839\n\n840\n\n841\n\n842\n\n843\n\n844\n\n845\n\n846\n\n847\n\n848\n\n849\n\n850\n\n851\n\n852\n\n853\n\n854\n\n855\n\n856\n\n857\n\n858\n\n859\n\n860\n\n861\n\n862\n\n863\n\n864\n\n865\n\n866\n\n867\n\n868\n\n869\n\n870\n\n871\n\n872\n\n873\n\n874\n\n875\n\n876\n\n877\n\n878\n\n879\n\n880\n\n881\n\n882\n\n883\n\n884\n\n885\n\n886\n\n887\n\n888\n\n889\n\n890\n\n891\n\n892\n\n893\n\n894\n\n895\n\n896\n\n897\n\n898\n\n899\n\n900\n\n901\n\n902\n\n903\n\n904\n\n905\n\n906\n\n907\n\n908\n\n909\n\n910\n\n911\n\n912\n\n913\n\n914\n\n915\n\n916\n\n917\n\n918\n\n919\n\n920\n\n921\n\n922\n\n923\n\n924\n\n925\n\n926\n\n927\n\n928\n\n929\n\n930\n\n931\n\n932\n\n933\n\n934\n\n935\n\n936\n\n937\n\n938\n\n939\n\n940\n\n941\n\n942\n\n943\n\n944\n\n945\n\n946\n\n947\n\n948\n\n949\n\n950\n\n951\n\n952\n\n953\n\n954\n\n955\n\n956\n\n957\n\n958\n\n959\n\n960\n\n961\n\n962\n\n963\n\n964\n\n965\n\n966\n\n967\n\n968\n\n969\n\n970\n\n971\n\n972\n\n973\n\n974\n\n975\n\n976\n\n977\n\n978\n\n979\n\n980\n\n981\n\n982\n\n983\n\n984\n\n985\n\n986\n\n987\n\n988\n\n989\n\n990\n\n991\n\n992\n\n993\n\n994\n\n995\n\n996\n\n997\n\n998\n\n999\n\n1000\n\n//! MCP server integration using the official rmcp SDK.\n\nuse std::collections::HashMap;\n\nuse std::ffi::OsString;\n\nuse std::future::Future;\n\nuse std::sync::{Arc, LazyLock};\n\nuse xai_grok_config::BearerTokenPath;\n\nuse xai_grok_telemetry::region;\n\nuse xai_grok_telemetry::region::Parent;\n\nuse agent_client_protocol as acp;\n\nuse tokio::{\n\n    io::{AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader},\n\n    process::{ChildStderr, Command},\n\n    sync::{Mutex, Notify},\n\n};\n\nuse rmcp::{\n\n ClientHandler, ClientLifecycleMode, ClientServiceExt,\n\n    model::{\n\n CallToolRequestParams, ClientCapabilities, ClientConfig, Implementation,\n\n PaginatedRequestParams,\n\n },\n\n    service::{\n\n ClientInitializeError, NotificationContext, RequestContext, RoleClient, RunningService,\n\n ServiceError,\n\n },\n\n    service::{RxJsonRpcMessage, TxJsonRpcMessage},\n\n    transport::{\n\n StreamableHttpClientTransport, Transport,\n\n        streamable_http_client::StreamableHttpClientTransportConfig,\n\n },\n\n};\n\npub use crate::auth_status::McpOauthDiscovery;\n\nuse crate::auth_status::{HttpAuthDecision, decide_http_auth_from_disk};\n\nuse crate::bearer_token_file::BearerTokenFile;\n\nuse crate::call_result::mcp_output_from_call_result;\n\npub use crate::generation::{Generation, Replacement, Superseded};\n\nuse crate::oauth::OAUTH_DISCOVERY_TIMEOUT;\n\nuse crate::oauth_config::McpOAuthConfig;\n\npub use crate::shared_mcp_state::SharedMcpState;\n\nuse xai_grok_tools::types::{\n\n    output::{MCPOutputDetails, ToolOutput},\n\n    tool::{ToolKind, ToolNamespace},\n\n    tool_metadata::ToolMetadata,\n\n};\n\nuse xai_grok_tools::util::{ProcessGroup, ProcessScope};\n\npub use crate::tool_name::{\n\n MCP_QUALIFIED_NAME_MAX_CHARS, McpToolAdmissionError, PROVIDER_TOOL_NAME_MAX_CHARS,\n\n    parse_mcp_qualified_name, parse_mcp_tool_name, qualify_mcp_tool_name, validate_tool_name,\n\n};\n\n/// MCP tool name delimiter: server names are qualified as `\"server__tool\"`.\n\n/// Canonical definition lives in `xai_grok_workspace_types`; re-exported here for callers that historically imported it from this module.\n\npub use xai_grok_workspace_types::MCP_TOOL_NAME_DELIMITER;\n\n/// Routing hint for first-party local app MCP endpoints: which agent/session a request belongs to. **Advisory only, never authentication** — any local process can set it, so receivers must not treat it as proof of identity.\n\n/// Caller-supplied configs cannot smuggle it: the header is stripped from every HTTP/SSE config and re-added only when the spawn context asks for it (mirroring the `GROK_SESSION_ID` env protection on stdio servers).\n\npub const GROK_AGENT_ID_HEADER: &str = \"X-Grok-Agent-ID\";\n\n/// Reqwest 0.13 twin of the 0.12 adapters in `xai_grok_extra_ca`.\n\nfn with_extra_root_certificates(mut builder: reqwest::ClientBuilder) -> reqwest::ClientBuilder {\n\n    xai_grok_extra_ca::ensure_default_crypto_provider();\n\n    builder = builder.tls_backend_rustls();\n\n for der in xai_grok_extra_ca::extra_root_ders() {\n\n match reqwest::Certificate::from_der(der) {\n\n Ok(cert) => builder = builder.add_root_certificate(cert),\n\n Err(e) => tracing::warn!(\n\n                error = %e,\n\n \"extra CA bundle: validated DER rejected by reqwest 0.13; skipping cert\"\n\n ),\n\n }\n\n }\n\n    builder\n\n}\n\n/// Max protocol icons kept per server/tool at ingest.\n\npub const MAX_MCP_ICONS_PER_ENTITY: usize = 8;\n\n/// Max bytes for a single icon `src` (including data URIs) at ingest.\n\npub const MAX_MCP_ICON_SRC_BYTES: usize = 64 * 1024;\n\n/// Max bytes for a single icon `mime_type` string at ingest.\n\npub const MAX_MCP_ICON_MIME_TYPE_BYTES: usize = 128;\n\n/// Max size tokens kept per icon (`48x48`, `any`, …) at ingest.\n\npub const MAX_MCP_ICON_SIZES: usize = 8;\n\n/// Max bytes for a single size token at ingest.\n\npub const MAX_MCP_ICON_SIZE_TOKEN_BYTES: usize = 32;\n\n/// Wire theme for MCP protocol icons.\n\n#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]\n\n#[serde(rename_all = \"lowercase\")]\n\npub enum McpIconTheme {\n\n Light,\n\n Dark,\n\n #[serde(other)]\n\n Unknown,\n\n}\n\n/// ACP-facing MCP protocol icon (SEP-973), mirrored from rmcp so clients never depend on the quarantined SDK types.\n\n#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]\n\n#[serde(rename_all = \"camelCase\")]\n\npub struct McpIcon {\n\n pub src: String,\n\n #[serde(default, skip_serializing_if = \"Option::is_none\")]\n\n pub mime_type: Option<String>,\n\n #[serde(default, skip_serializing_if = \"Option::is_none\")]\n\n pub sizes: Option<Vec<String>>,\n\n #[serde(default, skip_serializing_if = \"Option::is_none\")]\n\n pub theme: Option<McpIconTheme>,\n\n}\n\nimpl McpIcon {\n\n /// Convert an rmcp icon with ingest rules: trim `src`, allow only `https://` and `data:image/…`, drop empty/oversized values.\n\n pub fn from_rmcp(icon: rmcp::model::Icon) -> Option<Self> {\n\n let src = icon.src.trim();\n\n if src.is_empty() || src.len() > MAX_MCP_ICON_SRC_BYTES {\n\n return None;\n\n }\n\n if !is_allowed_mcp_icon_src(src) {\n\n return None;\n\n }\n\n let theme = match icon.theme {\n\n Some(rmcp::model::IconTheme::Light) => Some(McpIconTheme::Light),\n\n Some(rmcp::model::IconTheme::Dark) => Some(McpIconTheme::Dark),\n\n            _ => None,\n\n };\n\n let mime_type = icon.mime_type.and_then(|mime| {\n\n let mime = mime.trim();\n\n if mime.is_empty() || mime.len() > MAX_MCP_ICON_MIME_TYPE_BYTES {\n\n None\n\n } else {\n\n Some(mime.to_owned())\n\n }\n\n });\n\n let sizes = icon.sizes.map(|sizes| {\n\n            sizes\n\n .into_iter()\n\n .filter_map(|size| {\n\n let size = size.trim();\n\n if size.is_empty() || size.len() > MAX_MCP_ICON_SIZE_TOKEN_BYTES {\n\n None\n\n } else {\n\n Some(size.to_owned())\n\n }\n\n })\n\n .take(MAX_MCP_ICON_SIZES)\n\n .collect::<Vec<_>>()\n\n });\n\n let sizes = sizes.filter(|sizes| !sizes.is_empty());\n\n Some(Self {\n\n src: src.to_owned(),\n\n            mime_type,\n\n            sizes,\n\n            theme,\n\n })\n\n }\n\n pub fn from_rmcp_list(icons: Option<Vec<rmcp::model::Icon>>) -> Vec<Self> {\n\n        icons\n\n .unwrap_or_default()\n\n .into_iter()\n\n .filter_map(Self::from_rmcp)\n\n .take(MAX_MCP_ICONS_PER_ENTITY)\n\n .collect()\n\n }\n\n}\n\nfn is_allowed_mcp_icon_src(src: &str) -> bool {\n\n    src.starts_with(\"data:image/\") || src.starts_with(\"https://\")\n\n}\n\n/// Sanitize an MCP server or tool name into a single safe path segment (e.g. `\"user-Hugging Face\"` becomes `user-Hugging_Face`).\n\n/// Shared so the per-server folder advertised in the prompt matches the tool files on disk.\n\npub fn sanitize_descriptor_segment(s: &str) -> String {\n\n let mut out = String::with_capacity(s.len());\n\n for c in s.chars() {\n\n if c.is_ascii_alphanumeric() || c == '-' || c == '_' || c == '.' {\n\n            out.push(c);\n\n } else {\n\n            out.push('_');\n\n }\n\n }\n\n if out.is_empty() {\n\n        out.push('_');\n\n }\n\n    out\n\n}\n\n/// Result of a diff-based MCP config update.\n\n#[derive(Debug)]\n\npub struct McpConfigDiff {\n\n /// Server names that are new or had their config changed.\n\n pub added: Vec<McpServerName>,\n\n /// Server names that were removed or had their config changed (old instance torn down).\n\n pub removed: Vec<McpServerName>,\n\n /// Server names whose config is identical, so their clients stay alive.\n\n pub retained: Vec<McpServerName>,\n\n}\n\n/// A server-set change together with the claim for the pass that covers it, taken in one critical section.\n\n#[must_use = \"dropping the change releases the successor pass's claim\"]\n\npub struct McpConfigChange {\n\n pub diff: McpConfigDiff,\n\n pub claim: InitClaimGuard,\n\n}\n\n/// MCP server name used as the key in client/tool maps (e.g. `\"github\"`, `\"grok_com_linear\"`).\n\npub type McpServerName = String;\n\n/// Unqualified MCP tool name (e.g. `\"create_issue\"`, without the `server__` prefix).\n\ntype ToolName = String;\n\n/// Init state. `Starting` precedes `finish_init`, which fires early so the session is not blocked on MCP; `Finished`\n\n/// may still have handshakes draining; `Complete` is set by the pass once its last publication has landed.\n\n#[derive(Debug, Default)]\n\npub enum InitProgress {\n\n #[default]\n\n NotStarted,\n\n Starting {\n\n /// Set once `mark_handshaking` has seeded the set.\n\n seeded: bool,\n\n handshaking: std::collections::HashSet<McpServerName>,\n\n },\n\n Finished {\n\n handshaking: std::collections::HashSet<McpServerName>,\n\n },\n\n Complete,\n\n}\n\nimpl InitProgress {\n\n pub fn is_complete(&self) -> bool {\n\n matches!(self, Self::Complete)\n\n }\n\n /// Init work is outstanding, including the pass's final publication.\n\n pub fn is_in_progress(&self) -> bool {\n\n matches!(self, Self::Starting { .. } | Self::Finished { .. })\n\n }\n\n /// True iff `finish_init` has fired, regardless of whether background handshakes are still draining.\n\n /// Used for diagnostic logging that tells the pre-finish window apart from finished with handshakes still draining.\n\n pub fn has_finished_init(&self) -> bool {\n\n matches!(self, Self::Finished { .. } | Self::Complete)\n\n }\n\n /// True iff the named server is currently handshaking.\n\n pub fn is_server_handshaking(&self, name: &str) -> bool {\n\n match self {\n\n Self::Starting { handshaking, .. } | Self::Finished { handshaking } => {\n\n                handshaking.contains(name)\n\n }\n\n Self::NotStarted | Self::Complete => false,\n\n }\n\n }\n\n /// Iterate over server names whose background handshake is still in flight.\n\n /// Empty when [`Self::NotStarted`] or fully complete.\n\n pub fn handshaking_servers(&self) -> impl Iterator<Item = &McpServerName> {\n\n match self {\n\n Self::Starting { handshaking, .. } | Self::Finished { handshaking } => {\n\n Some(handshaking.iter())\n\n }\n\n Self::NotStarted | Self::Complete => None,\n\n }\n\n .into_iter()\n\n .flatten()\n\n }\n\n /// Number of in-flight per-server handshakes.\n\n pub fn handshaking_count(&self) -> usize {\n\n match self {\n\n Self::Starting { handshaking, .. } | Self::Finished { handshaking } => {\n\n                handshaking.len()\n\n }\n\n Self::NotStarted | Self::Complete => 0,\n\n }\n\n }\n\n /// Transition `Starting` to `Finished`, preserving the handshaking set.\n\n /// No-op if already `Finished`; warns and stays put if called from `NotStarted`, which would be a caller bug.\n\n pub fn finish(&mut self) {\n\n match self {\n\n Self::Starting { handshaking, .. } => {\n\n // Move only the inner set, leaving the outer `&mut self` ready to be reassigned\n\n // `mem::take(self)` would force a `NotStarted` placeholder and a redundant put-back in the already-Finished arm below\n\n let handshaking = std::mem::take(handshaking);\n\n *self = Self::Finished { handshaking };\n\n }\n\n // Idempotent: already past the finish boundary\n\n // Per-server handshakes continue draining via `mark_handshake_complete`\n\n Self::Finished { .. } | Self::Complete => {}\n\n Self::NotStarted => {\n\n                tracing::warn!(\n\n \"InitProgress::finish called from NotStarted; staying in NotStarted\"\n\n );\n\n }\n\n }\n\n }\n\n pub fn complete(&mut self) {\n\n *self = Self::Complete;\n\n }\n\n /// Transition any state to `NotStarted`, clearing all per-server progress.\n\n /// Used on generation mismatch (config change racing active init) and on full reset.\n\n pub fn cancel(&mut self) {\n\n *self = Self::NotStarted;\n\n }\n\n /// Add names to the handshaking set; only meaningful in `Starting` or `Finished`.\n\n /// Warns if called from `NotStarted`: a handshake starting without `try_start_init` is a caller bug.\n\n pub fn mark_handshaking(&mut self, names: impl IntoIterator<Item = McpServerName>) {\n\n match self {\n\n Self::Starting {\n\n                seeded,\n\n                handshaking,\n\n } => {\n\n *seeded = true;\n\n                handshaking.extend(names);\n\n }\n\n Self::Finished { handshaking } => {\n\n                handshaking.extend(names);\n\n }\n\n Self::NotStarted | Self::Complete => {\n\n                tracing::warn!(\"InitProgress::mark_handshaking called outside a pass; ignoring\");\n\n }\n\n }\n\n }\n\n /// Remove a server from the handshaking set (on success or failure of its handshake).\n\n /// No-op if not present or if `NotStarted`.\n\n pub fn mark_handshake_complete(&mut self, name: &str) {\n\n match self {\n\n Self::Starting { handshaking, .. } | Self::Finished { handshaking } => {\n\n                handshaking.remove(name);\n\n }\n\n Self::NotStarted | Self::Complete => {}\n\n }\n\n }\n\n}\n\n/// One in-process SDK MCP server registration: its tool-namespace name and the SDK-side id echoed back in `x.ai/mcp/sdk_call`.\n\n/// A named struct (rather than a `(String, String)` tuple) so callers can't transpose the two strings.\n\n/// `Deserialize` d from a `_meta[\"x.ai/mcp/servers\"]` entry, so the `serverId` wire field name is declared (and serde-checked) exactly once here.\n\n#[derive(Debug, Clone, serde::Deserialize)]\n\npub struct AcpServerEntry {\n\n pub name: McpServerName,\n\n #[serde(rename = \"serverId\")]\n\n pub server_id: String,\n\n}\n\n/// The session's in-process SDK MCP servers (declared via `_meta[\"x.ai/mcp/servers\"]`), bundled with the shared reverse-RPC invoker.\n\n/// The registry survives `update_configs` clears; config reloads only touch `configs`/` owned_clients`.\n\nstruct AcpMcpRegistry {\n\n /// Registered servers (`name -> serverId`).\n\n servers: Vec<AcpServerEntry>,\n\n /// Shared reverse-RPC invoker all these servers' tools are called through (emits `x.ai/mcp/sdk_call` over the ACP connection).\n\n invoker: Arc<dyn crate::acp_transport::AcpReverseInvoker>,\n\n}\n\n/// `Cooling` waits out the backoff; `InFlight` marks a running respawn attempt and carries the token that attempt must present to settle.\n\n/// An in-flight server is never handed to another trigger, and a token invalidated by config teardown makes the stale attempt's results unusable.\n\n#[derive(Debug, Clone, Copy)]\n\nenum UnreachableRetry {\n\n Cooling {\n\n retry_at: std::time::Instant,\n\n },\n\n InFlight {\n\n token: u64,\n\n started_at: std::time::Instant,\n\n },\n\n}\n\n/// Ownership of init. [`McpState`] keeps only a `Weak` to it, so a dropped pass releases ownership and the next\n\n/// waiter re-owns.\n\n#[must_use = \"dropping the guard releases init ownership\"]\n\npub struct InitClaimGuard {\n\n token: std::sync::Arc<()>,\n\n signal: std::sync::Arc<tokio::sync::Notify>,\n\n}\n\nimpl Drop for InitClaimGuard {\n\n fn drop(&mut self) {\n\n self.signal.notify_waiters();\n\n }\n\n}\n\n/// Admitted server list shared with the session handle.\n\n///\n\n/// `update_configs` and `update_configs_diff` publish into this cell, so a", "url": "https://wpnews.pro/news/grok-s-public-source-supports-stateless-mcp-on-http-not-stdio", "canonical_source": "https://github.com/xai-org/grok-build/blob/2bdd1d6a6369de0e8c68132ea4539e9abd9e14a8/crates/codegen/xai-grok-mcp/src/servers.rs", "published_at": "2026-11-16 00:00:00+00:00", "updated_at": "2026-11-16 20:23:28.544501+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "large-language-models"], "entities": ["Grok", "xAI", "Model Context Protocol", "servers.rs"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/grok-s-public-source-supports-stateless-mcp-on-http-not-stdio", "markdown": "https://wpnews.pro/news/grok-s-public-source-supports-stateless-mcp-on-http-not-stdio.md", "text": "https://wpnews.pro/news/grok-s-public-source-supports-stateless-mcp-on-http-not-stdio.txt", "jsonld": "https://wpnews.pro/news/grok-s-public-source-supports-stateless-mcp-on-http-not-stdio.jsonld"}}