(
&self,
py: Python<'_>,
name: &str,
transport: &str,
command: Option<&str>,
args: Option<Vec<String>>,
url: Option<&str>,
headers: Opti
| 2514 | #[allow(clippy::too_many_arguments)] |
| 2515 | #[pyo3(signature = (name, transport="stdio", command=None, args=None, url=None, headers=None, env=None, timeout_ms=None))] |
| 2516 | fn add_mcp_server( |
| 2517 | &self, |
| 2518 | py: Python<'_>, |
| 2519 | name: &str, |
| 2520 | transport: &str, |
| 2521 | command: Option<&str>, |
| 2522 | args: Option<Vec<String>>, |
| 2523 | url: Option<&str>, |
| 2524 | headers: Option<std::collections::HashMap<String, String>>, |
| 2525 | env: Option<std::collections::HashMap<String, String>>, |
| 2526 | timeout_ms: Option<u64>, |
| 2527 | ) -> PyResult<usize> { |
| 2528 | use a3s_code_core::mcp::protocol::{McpServerConfig, McpTransportConfig}; |
| 2529 | |
| 2530 | let transport_config = match transport { |
| 2531 | "stdio" => { |
| 2532 | let command = command.ok_or_else(|| { |
| 2533 | PyRuntimeError::new_err("'command' is required for stdio transport") |
| 2534 | })?; |
| 2535 | McpTransportConfig::Stdio { |
| 2536 | command: command.to_string(), |
| 2537 | args: args.unwrap_or_default(), |
| 2538 | } |
| 2539 | } |
| 2540 | "http" => { |
| 2541 | let url = url.ok_or_else(|| { |
| 2542 | PyRuntimeError::new_err("'url' is required for http transport") |
| 2543 | })?; |
| 2544 | McpTransportConfig::Http { |
| 2545 | url: url.to_string(), |
| 2546 | headers: headers.unwrap_or_default(), |
| 2547 | } |
| 2548 | } |
| 2549 | "streamable-http" | "streamable_http" => { |
| 2550 | let url = url.ok_or_else(|| { |
| 2551 | PyRuntimeError::new_err("'url' is required for streamable-http transport") |
| 2552 | })?; |
| 2553 | McpTransportConfig::StreamableHttp { |
| 2554 | url: url.to_string(), |
| 2555 | headers: headers.unwrap_or_default(), |
| 2556 | } |
| 2557 | } |
| 2558 | other => { |
| 2559 | return Err(PyRuntimeError::new_err(format!( |
| 2560 | "Unknown transport '{}'. Use 'stdio', 'http', or 'streamable-http'", |
| 2561 | other |
| 2562 | ))) |
| 2563 | } |
| 2564 | }; |
| 2565 | |
| 2566 | let tool_timeout_secs = timeout_ms.map(|ms| (ms / 1000).max(1)).unwrap_or(60); |
| 2567 | let config = McpServerConfig { |
| 2568 | name: name.to_string(), |
| 2569 | transport: transport_config, |
| 2570 | enabled: true, |
| 2571 | env: env.unwrap_or_default(), |
| 2572 | oauth: None, |
| 2573 | tool_timeout_secs, |
no test coverage detected