MCPcopy Create free account
hub / github.com/AI45Lab/Code / add_mcp_server_config

Method add_mcp_server_config

sdk/python/src/lib.rs:2602–2616  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

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> {

Callers 1

add_mcpMethod · 0.45

Calls 6

py_dict_to_jsonFunction · 0.85
block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45
add_mcp_serverMethod · 0.45

Tested by

no test coverage detected