Facade over chuk-tool-processor with mcp-cli specific features. Responsibilities: 1. Parse MCP config files and detect server types (HTTP/SSE/STDIO) 2. Integrate with mcp-cli's OAuth TokenManager 3. Filter and validate tools for LLM compatibility 4. Convert between chuk and
| 77 | |
| 78 | |
| 79 | class ToolManager: |
| 80 | """ |
| 81 | Facade over chuk-tool-processor with mcp-cli specific features. |
| 82 | |
| 83 | Responsibilities: |
| 84 | 1. Parse MCP config files and detect server types (HTTP/SSE/STDIO) |
| 85 | 2. Integrate with mcp-cli's OAuth TokenManager |
| 86 | 3. Filter and validate tools for LLM compatibility |
| 87 | 4. Convert between chuk and mcp-cli data models |
| 88 | |
| 89 | For direct tool operations, use the exposed stream_manager property. |
| 90 | """ |
| 91 | |
| 92 | def __init__( |
| 93 | self, |
| 94 | config_file: str, |
| 95 | servers: list[str], |
| 96 | server_names: dict[int, str | None] | None = None, |
| 97 | tool_timeout: float | None = None, |
| 98 | max_concurrency: int = 4, |
| 99 | initialization_timeout: float = 120.0, |
| 100 | runtime_config: RuntimeConfig | None = None, |
| 101 | middleware_config: MiddlewareConfig | None = None, |
| 102 | middleware_enabled: bool = DEFAULT_MIDDLEWARE_ENABLED, |
| 103 | ): |
| 104 | self.config_file = config_file |
| 105 | self.servers = servers |
| 106 | self.server_names = server_names or {} |
| 107 | |
| 108 | # Use runtime config for timeout management (type-safe!) |
| 109 | self.runtime_config = runtime_config or load_runtime_config() |
| 110 | |
| 111 | # Tool timeout with priority: param > runtime_config |
| 112 | if tool_timeout is not None: |
| 113 | self.tool_timeout = tool_timeout |
| 114 | else: |
| 115 | self.tool_timeout = self.runtime_config.get_timeout( |
| 116 | TimeoutType.TOOL_EXECUTION |
| 117 | ) |
| 118 | |
| 119 | # Initialization timeout with priority: param > runtime_config |
| 120 | if initialization_timeout != 120.0: # User provided non-default |
| 121 | self.initialization_timeout = initialization_timeout |
| 122 | else: |
| 123 | self.initialization_timeout = self.runtime_config.get_timeout( |
| 124 | TimeoutType.SERVER_INIT |
| 125 | ) |
| 126 | |
| 127 | self.max_concurrency = max_concurrency |
| 128 | |
| 129 | # Middleware configuration (retry, circuit breaker, rate limiting) |
| 130 | self._middleware_enabled = middleware_enabled |
| 131 | self._middleware_config = middleware_config |
| 132 | |
| 133 | logger.debug( |
| 134 | f"ToolManager initialized with timeouts: " |
| 135 | f"tool={self.tool_timeout}s, init={self.initialization_timeout}s, " |
| 136 | f"middleware_enabled={middleware_enabled}" |
no outgoing calls