pub struct McpManager { /* private fields */ }Expand description
Created via McpManager::spawn() which returns an Arc<Self>.
Use McpManager::new_no_spawn() only in tests where the lifecycle
task is not needed.
Implementations§
Source§impl McpManager
impl McpManager
Sourcepub fn spawn() -> Arc<McpManager> ⓘ
pub fn spawn() -> Arc<McpManager> ⓘ
Spawns the background lifecycle task using the oxicode-default config
and disk paths (~/.config/oxicode/), and eagerly connects to any
Eager / KeepAlive servers.
Returns Arc<Self> so it can be shared freely across the agent
loop, the TUI dashboard, and the lifecycle task (via Weak).
Sourcepub fn spawn_with_config(mcp_config: McpConfig) -> Arc<McpManager> ⓘ
pub fn spawn_with_config(mcp_config: McpConfig) -> Arc<McpManager> ⓘ
Spawn with a programmatically-supplied config (used by the SDK
OxicodeBuilder::with_mcp_config). Disk paths default to the oxicode
standard locations (~/.config/oxicode/).
Sourcepub fn spawn_with_paths(
mcp_config: McpConfig,
cache_path: Option<PathBuf>,
consent_path: Option<PathBuf>,
) -> Arc<McpManager> ⓘ
pub fn spawn_with_paths( mcp_config: McpConfig, cache_path: Option<PathBuf>, consent_path: Option<PathBuf>, ) -> Arc<McpManager> ⓘ
Primary constructor. Spawn with a programmatically-supplied config and optional custom disk paths for the metadata cache and consent store.
Pass None for either path to use the oxicode default
(~/.config/oxicode/mcp-cache.json / mcp-consent.json).
This is the constructor SDK consumers (e.g. oxios) should use when
they self-host MCP state under their own config directory. It
spawns the background lifecycle task and eagerly connects to any
Eager / KeepAlive servers.
Returns Arc<Self> so it can be shared freely across the agent
loop, the TUI dashboard, and the lifecycle task (via Weak).
Sourcepub fn new_no_spawn() -> McpManager
pub fn new_no_spawn() -> McpManager
Construct a manager without spawning the lifecycle task. Intended for tests that don’t need timer/disconnect behaviour.
Sourcepub fn config(&self) -> RwLockReadGuard<'_, RawRwLock, McpConfig>
pub fn config(&self) -> RwLockReadGuard<'_, RawRwLock, McpConfig>
Get a snapshot of the current config.
Sourcepub fn replace_config(&self, new_config: McpConfig)
pub fn replace_config(&self, new_config: McpConfig)
Hot-replace the in-memory MCP configuration.
Used by the /mcp management overlay after it writes a new
config to disk: the updated server map becomes visible to
connect(), status(), and the proxy tool without a full
process restart. Existing live connections are left untouched;
newly added servers connect lazily on first use (or eagerly if
their LifecycleMode is eager/keep-alive).
Direct-tool registration happens once at boot from the cache, so
newly-added directTools servers still require a restart to
surface as first-class agent tools — but the mcp proxy tool
can reach them immediately.
Sourcepub fn set_credential_provider(&self, provider: Arc<dyn McpCredentialProvider>)
pub fn set_credential_provider(&self, provider: Arc<dyn McpCredentialProvider>)
Inject a credential provider. Replaces the noop default. Called by oxicode-cli bootstrap (or any host product) to enable authenticated MCP servers.
Existing transports retain the provider they were constructed with; new transports created after this call pick up the new one at their next construction.
Sourcepub fn consent(&self) -> &ConsentManager
pub fn consent(&self) -> &ConsentManager
Get the consent manager.
Sourcepub fn cache(&self) -> &MetadataCache
pub fn cache(&self) -> &MetadataCache
Get the metadata cache.
Sourcepub async fn status(self: &Arc<McpManager>) -> String
pub async fn status(self: &Arc<McpManager>) -> String
Get a formatted status summary (legacy mcp({}) interface).
Sourcepub fn dashboard_data(self: &Arc<McpManager>) -> McpDashboardData
pub fn dashboard_data(self: &Arc<McpManager>) -> McpDashboardData
Snapshot of dashboard data (Phase 2). Synchronous — only reads
parking_lot-guarded state and in-memory copies of cached tool
lists, so it is safe to call from render().
Sourcepub async fn connect(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<String, Error>
pub async fn connect( self: &Arc<McpManager>, server_name: &str, ) -> Result<String, Error>
Connect to a specific MCP server by name. Selects the transport
from the entry: command → stdio (spawn), url → Streamable HTTP.
Stores the connected client and updates the metadata cache.
Sourcepub fn trust_server(&self, server_name: &str) -> Result<(), Error>
pub fn trust_server(&self, server_name: &str) -> Result<(), Error>
Trust an MCP server for spawn consent (persist Allow to disk).
Used by oxicode mcp trust <server>. After this, the server’s next
connect() proceeds past the consent gate.
Sourcepub fn untrust_server(&self, server_name: &str) -> Result<(), Error>
pub fn untrust_server(&self, server_name: &str) -> Result<(), Error>
Revoke spawn trust for an MCP server (persist Deny to disk).
Used by oxicode mcp untrust <server>. After this, the server’s next
connect() is denied with McpError::ConsentDenied.
Sourcepub async fn ensure_connected(self: &Arc<McpManager>, server_name: &str) -> bool
pub async fn ensure_connected(self: &Arc<McpManager>, server_name: &str) -> bool
Lazily connect (or return true if already connected).
Sourcepub async fn disconnect(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<bool, Error>
pub async fn disconnect( self: &Arc<McpManager>, server_name: &str, ) -> Result<bool, Error>
Manually disconnect a single server. Exposed for the MCP
dashboard’s D key. Idempotent — returns Ok(true) if a live
connection was actually closed, Ok(false) if the server was
already disconnected.
Sourcepub async fn reauth_server(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<(), Error>
pub async fn reauth_server( self: &Arc<McpManager>, server_name: &str, ) -> Result<(), Error>
Force-refresh the OAuth credential for server_name (v2.2).
Used by /mcp reauth <server> to rotate credentials without
restarting the process. Returns an error if no credential
provider is configured, the server has no url, or the
refresh fails.
Sourcepub async fn call_tool(
self: &Arc<McpManager>,
tool_name: &str,
args: Value,
server_override: Option<&str>,
) -> Result<McpCallResult, Error>
pub async fn call_tool( self: &Arc<McpManager>, tool_name: &str, args: Value, server_override: Option<&str>, ) -> Result<McpCallResult, Error>
Call an MCP tool by name, optionally targeting a specific server.
Sourcepub async fn list_resources(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<Vec<Value>, Error>
pub async fn list_resources( self: &Arc<McpManager>, server_name: &str, ) -> Result<Vec<Value>, Error>
List resources from a connected MCP server (v2.3 G5).
Sourcepub async fn read_resource(
self: &Arc<McpManager>,
server_name: &str,
uri: &str,
) -> Result<Vec<McpContent>, Error>
pub async fn read_resource( self: &Arc<McpManager>, server_name: &str, uri: &str, ) -> Result<Vec<McpContent>, Error>
Read a resource URI from a connected MCP server (v2.3 G5).
Sourcepub async fn list_prompts(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<Vec<McpPrompt>, Error>
pub async fn list_prompts( self: &Arc<McpManager>, server_name: &str, ) -> Result<Vec<McpPrompt>, Error>
List prompt templates from a connected MCP server (v2.3 G5).
Sourcepub async fn get_prompt(
self: &Arc<McpManager>,
server_name: &str,
name: &str,
arguments: HashMap<String, String>,
) -> Result<Vec<Value>, Error>
pub async fn get_prompt( self: &Arc<McpManager>, server_name: &str, name: &str, arguments: HashMap<String, String>, ) -> Result<Vec<Value>, Error>
Get a prompt template with arguments (v2.3 G5).
Sourcepub fn reset_idle_timer(self: &Arc<McpManager>, server_name: &str)
pub fn reset_idle_timer(self: &Arc<McpManager>, server_name: &str)
Reset (or start) the idle-disconnect timer for a server. Called after every successful tool use.
Sourcepub async fn describe(
self: &Arc<McpManager>,
tool_name: &str,
) -> Result<String, Error>
pub async fn describe( self: &Arc<McpManager>, tool_name: &str, ) -> Result<String, Error>
Describe a tool by name.
Sourcepub async fn search(
self: &Arc<McpManager>,
query: &str,
regex: bool,
server_filter: Option<&str>,
) -> Result<String, Error>
pub async fn search( self: &Arc<McpManager>, query: &str, regex: bool, server_filter: Option<&str>, ) -> Result<String, Error>
Search tools by name or description.
Sourcepub async fn list_tools(
self: &Arc<McpManager>,
server_name: &str,
) -> Result<String, Error>
pub async fn list_tools( self: &Arc<McpManager>, server_name: &str, ) -> Result<String, Error>
List tools for a specific server.
Sourcepub fn direct_tools_from_cache(self: &Arc<McpManager>) -> Vec<DirectToolDef>
pub fn direct_tools_from_cache(self: &Arc<McpManager>) -> Vec<DirectToolDef>
Direct tool definitions for ToolRegistry registration (Phase 3).
Reads from the metadata cache, applies direct_tools /
exclude_tools filters, and returns the precomputed prefixed names.
Sourcepub fn should_disable_proxy(self: &Arc<McpManager>) -> bool
pub fn should_disable_proxy(self: &Arc<McpManager>) -> bool
Whether the mcp proxy tool should be hidden in the tool registry
(Phase 3 — settings.disable_proxy_tool: true).