pub struct McpServer { /* private fields */ }
Expand description
Main MCP server implementation
Implementations§
Source§impl McpServer
impl McpServer
Sourcepub fn new(name: String, version: String) -> Self
pub fn new(name: String, version: String) -> Self
Create a new MCP server with the given name and version
Sourcepub fn with_config(name: String, version: String, config: ServerConfig) -> Self
pub fn with_config(name: String, version: String, config: ServerConfig) -> Self
Create a new MCP server with custom configuration
Sourcepub fn set_capabilities(&mut self, capabilities: ServerCapabilities)
pub fn set_capabilities(&mut self, capabilities: ServerCapabilities)
Set server capabilities
Sourcepub fn info(&self) -> &ServerInfo
pub fn info(&self) -> &ServerInfo
Get server information
Sourcepub fn capabilities(&self) -> &ServerCapabilities
pub fn capabilities(&self) -> &ServerCapabilities
Get server capabilities
Sourcepub fn config(&self) -> &ServerConfig
pub fn config(&self) -> &ServerConfig
Get server configuration
Sourcepub async fn add_resource<H>(
&self,
name: String,
uri: String,
handler: H,
) -> McpResult<()>where
H: ResourceHandler + 'static,
pub async fn add_resource<H>(
&self,
name: String,
uri: String,
handler: H,
) -> McpResult<()>where
H: ResourceHandler + 'static,
Add a resource to the server
Sourcepub async fn add_resource_detailed<H>(
&self,
info: ResourceInfo,
handler: H,
) -> McpResult<()>where
H: ResourceHandler + 'static,
pub async fn add_resource_detailed<H>(
&self,
info: ResourceInfo,
handler: H,
) -> McpResult<()>where
H: ResourceHandler + 'static,
Add a resource with detailed information
Sourcepub async fn remove_resource(&self, uri: &str) -> McpResult<bool>
pub async fn remove_resource(&self, uri: &str) -> McpResult<bool>
Remove a resource from the server
Sourcepub async fn list_resources(&self) -> McpResult<Vec<ResourceInfo>>
pub async fn list_resources(&self) -> McpResult<Vec<ResourceInfo>>
List all registered resources
Sourcepub async fn read_resource(&self, uri: &str) -> McpResult<Vec<ResourceContents>>
pub async fn read_resource(&self, uri: &str) -> McpResult<Vec<ResourceContents>>
Read a resource
Sourcepub async fn add_tool<H>(
&self,
name: String,
description: Option<String>,
schema: Value,
handler: H,
) -> McpResult<()>where
H: ToolHandler + 'static,
pub async fn add_tool<H>(
&self,
name: String,
description: Option<String>,
schema: Value,
handler: H,
) -> McpResult<()>where
H: ToolHandler + 'static,
Add a tool to the server
Sourcepub async fn add_tool_detailed<H>(
&self,
info: ToolInfo,
handler: H,
) -> McpResult<()>where
H: ToolHandler + 'static,
pub async fn add_tool_detailed<H>(
&self,
info: ToolInfo,
handler: H,
) -> McpResult<()>where
H: ToolHandler + 'static,
Add a tool with detailed information
Sourcepub async fn remove_tool(&self, name: &str) -> McpResult<bool>
pub async fn remove_tool(&self, name: &str) -> McpResult<bool>
Remove a tool from the server
Sourcepub async fn list_tools(&self) -> McpResult<Vec<ToolInfo>>
pub async fn list_tools(&self) -> McpResult<Vec<ToolInfo>>
List all registered tools
Sourcepub async fn call_tool(
&self,
name: &str,
arguments: Option<HashMap<String, Value>>,
) -> McpResult<ToolResult>
pub async fn call_tool( &self, name: &str, arguments: Option<HashMap<String, Value>>, ) -> McpResult<ToolResult>
Call a tool
Sourcepub async fn add_prompt<H>(&self, info: PromptInfo, handler: H) -> McpResult<()>where
H: PromptHandler + 'static,
pub async fn add_prompt<H>(&self, info: PromptInfo, handler: H) -> McpResult<()>where
H: PromptHandler + 'static,
Add a prompt to the server
Sourcepub async fn remove_prompt(&self, name: &str) -> McpResult<bool>
pub async fn remove_prompt(&self, name: &str) -> McpResult<bool>
Remove a prompt from the server
Sourcepub async fn list_prompts(&self) -> McpResult<Vec<PromptInfo>>
pub async fn list_prompts(&self) -> McpResult<Vec<PromptInfo>>
List all registered prompts
Sourcepub async fn get_prompt(
&self,
name: &str,
arguments: Option<HashMap<String, Value>>,
) -> McpResult<PromptResult>
pub async fn get_prompt( &self, name: &str, arguments: Option<HashMap<String, Value>>, ) -> McpResult<PromptResult>
Get a prompt
Sourcepub async fn start<T>(&mut self, transport: T) -> McpResult<()>where
T: ServerTransport + 'static,
pub async fn start<T>(&mut self, transport: T) -> McpResult<()>where
T: ServerTransport + 'static,
Start the server with the given transport
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if the server is running
Sourcepub async fn state(&self) -> ServerState
pub async fn state(&self) -> ServerState
Get the current server state
Sourcepub async fn handle_request(
&self,
request: JsonRpcRequest,
) -> McpResult<JsonRpcResponse>
pub async fn handle_request( &self, request: JsonRpcRequest, ) -> McpResult<JsonRpcResponse>
Handle an incoming JSON-RPC request
Auto Trait Implementations§
impl Freeze for McpServer
impl !RefUnwindSafe for McpServer
impl Send for McpServer
impl Sync for McpServer
impl Unpin for McpServer
impl !UnwindSafe 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