pub struct McpManager { /* private fields */ }Expand description
Central manager for all MCP server connections.
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<Self> ⓘ
pub fn spawn() -> Arc<Self> ⓘ
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<Self> ⓘ
pub fn spawn_with_config(mcp_config: McpConfig) -> Arc<Self> ⓘ
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<Self> ⓘ
pub fn spawn_with_paths( mcp_config: McpConfig, cache_path: Option<PathBuf>, consent_path: Option<PathBuf>, ) -> Arc<Self> ⓘ
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() -> Self
pub fn new_no_spawn() -> Self
Construct a manager without spawning the lifecycle task. Intended for tests that don’t need timer/disconnect behaviour.
Sourcepub fn config(&self) -> RwLockReadGuard<'_, McpConfig>
pub fn config(&self) -> RwLockReadGuard<'_, 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<Self>) -> String
pub async fn status(self: &Arc<Self>) -> String
Get a formatted status summary (legacy mcp({}) interface).
Sourcepub fn dashboard_data(self: &Arc<Self>) -> McpDashboardData
pub fn dashboard_data(self: &Arc<Self>) -> 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<Self>, server_name: &str) -> Result<String>
pub async fn connect(self: &Arc<Self>, server_name: &str) -> Result<String>
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<()>
pub fn trust_server(&self, server_name: &str) -> Result<()>
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<()>
pub fn untrust_server(&self, server_name: &str) -> Result<()>
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<Self>, server_name: &str) -> bool
pub async fn ensure_connected(self: &Arc<Self>, server_name: &str) -> bool
Lazily connect (or return true if already connected).
Sourcepub async fn disconnect(self: &Arc<Self>, server_name: &str) -> Result<bool>
pub async fn disconnect(self: &Arc<Self>, server_name: &str) -> Result<bool>
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<Self>, server_name: &str) -> Result<()>
pub async fn reauth_server(self: &Arc<Self>, server_name: &str) -> Result<()>
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<Self>,
tool_name: &str,
args: Value,
server_override: Option<&str>,
) -> Result<McpCallResult>
pub async fn call_tool( self: &Arc<Self>, tool_name: &str, args: Value, server_override: Option<&str>, ) -> Result<McpCallResult>
Call an MCP tool by name, optionally targeting a specific server.
Sourcepub async fn list_resources(
self: &Arc<Self>,
server_name: &str,
) -> Result<Vec<Value>>
pub async fn list_resources( self: &Arc<Self>, server_name: &str, ) -> Result<Vec<Value>>
List resources from a connected MCP server (v2.3 G5).
Sourcepub async fn read_resource(
self: &Arc<Self>,
server_name: &str,
uri: &str,
) -> Result<Vec<McpContent>>
pub async fn read_resource( self: &Arc<Self>, server_name: &str, uri: &str, ) -> Result<Vec<McpContent>>
Read a resource URI from a connected MCP server (v2.3 G5).
Sourcepub async fn list_prompts(
self: &Arc<Self>,
server_name: &str,
) -> Result<Vec<McpPrompt>>
pub async fn list_prompts( self: &Arc<Self>, server_name: &str, ) -> Result<Vec<McpPrompt>>
List prompt templates from a connected MCP server (v2.3 G5).
Sourcepub async fn get_prompt(
self: &Arc<Self>,
server_name: &str,
name: &str,
arguments: HashMap<String, String>,
) -> Result<Vec<Value>>
pub async fn get_prompt( self: &Arc<Self>, server_name: &str, name: &str, arguments: HashMap<String, String>, ) -> Result<Vec<Value>>
Get a prompt template with arguments (v2.3 G5).
Sourcepub fn reset_idle_timer(self: &Arc<Self>, server_name: &str)
pub fn reset_idle_timer(self: &Arc<Self>, 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<Self>, tool_name: &str) -> Result<String>
pub async fn describe(self: &Arc<Self>, tool_name: &str) -> Result<String>
Describe a tool by name.
Sourcepub async fn search(
self: &Arc<Self>,
query: &str,
regex: bool,
server_filter: Option<&str>,
) -> Result<String>
pub async fn search( self: &Arc<Self>, query: &str, regex: bool, server_filter: Option<&str>, ) -> Result<String>
Search tools by name or description.
Sourcepub async fn list_tools(self: &Arc<Self>, server_name: &str) -> Result<String>
pub async fn list_tools(self: &Arc<Self>, server_name: &str) -> Result<String>
List tools for a specific server.
Sourcepub fn direct_tools_from_cache(self: &Arc<Self>) -> Vec<DirectToolDef>
pub fn direct_tools_from_cache(self: &Arc<Self>) -> 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<Self>) -> bool
pub fn should_disable_proxy(self: &Arc<Self>) -> bool
Whether the mcp proxy tool should be hidden in the tool registry
(Phase 3 — settings.disable_proxy_tool: true).
Trait Implementations§
Source§impl Debug for McpManager
impl Debug for McpManager
Auto Trait Implementations§
impl !Freeze for McpManager
impl !RefUnwindSafe for McpManager
impl !UnwindSafe for McpManager
impl Send for McpManager
impl Sync for McpManager
impl Unpin for McpManager
impl UnsafeUnpin for McpManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSendSync for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.