pub struct McpServer { /* private fields */ }Expand description
Serves an application’s tools to an external AI client.
Transport-agnostic: it turns a request into a response and nothing more, so the same server works over stdio, over a local HTTP endpoint, or over an in-memory pipe in a test.
Implementations§
Source§impl McpServer
impl McpServer
pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
Sourcepub fn with_permissions(self, permissions: AiPermissions) -> Self
pub fn with_permissions(self, permissions: AiPermissions) -> Self
What an external AI is allowed to do. Nothing, unless the product says so.
Sourcepub fn with_confirmation(
self,
confirmation: Arc<dyn ConfirmationService>,
) -> Self
pub fn with_confirmation( self, confirmation: Arc<dyn ConfirmationService>, ) -> Self
Ask a human before a mutating tool takes effect.
Without this, Commit and Delete tools are refused at the boundary — the
safest default. A product that grants mutation must wire a confirmer (a native
dialog, a policy file) at composition time.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The id this session is logged under.
pub fn with_tool(self, tool: Arc<dyn Tool>) -> Self
Sourcepub async fn handle(&self, request: Request) -> Option<Response>
pub async fn handle(&self, request: Request) -> Option<Response>
Handle one request. Returns None for a notification.
Sourcepub async fn handle_line(&self, line: &str) -> Option<Response>
pub async fn handle_line(&self, line: &str) -> Option<Response>
Parse and handle one line of JSON. Convenience for line-based transports.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for McpServer
impl !RefUnwindSafe for McpServer
impl !UnwindSafe for McpServer
impl Send for McpServer
impl Sync for McpServer
impl Unpin for McpServer
impl UnsafeUnpin for McpServer
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
Mutably borrows from an owned value. Read more