Add an MCP server with an object config. Preferred for new SDK callers because the transport is typed as a nested object instead of split across positional parameters. Example: session.add_mcp_server_config({ "name": "github", "transport": { "type": "stdio", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], }, "env": {"GITHUB_TOKEN": "..."}, "timeout_ms": 30000, })
(&self, py: Python<'_>, config: &Bound<'_, PyDict>)
| 2600 | /// "timeout_ms": 30000, |
| 2601 | /// }) |
| 2602 | fn add_mcp_server_config(&self, py: Python<'_>, config: &Bound<'_, PyDict>) -> PyResult<usize> { |
| 2603 | let json_str = py_dict_to_json(config)?; |
| 2604 | let value: serde_json::Value = serde_json::from_str(&json_str) |
| 2605 | .map_err(|e| PyValueError::new_err(format!("Invalid MCP server config: {e}")))?; |
| 2606 | let config = normalize_mcp_server_config(value)?; |
| 2607 | let session = self.inner.clone(); |
| 2608 | py.allow_threads(move || { |
| 2609 | get_runtime().block_on(async { |
| 2610 | session |
| 2611 | .add_mcp_server(config) |
| 2612 | .await |
| 2613 | .map_err(|e| PyRuntimeError::new_err(format!("add_mcp_server failed: {e}"))) |
| 2614 | }) |
| 2615 | }) |
| 2616 | } |
| 2617 | |
| 2618 | /// Add an MCP server with the compact object-shaped API. |
| 2619 | fn add_mcp(&self, py: Python<'_>, config: &Bound<'_, PyDict>) -> PyResult<usize> { |
no test coverage detected