docs: Add Rustdoc comments for info and mcp modules and grep plugin
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -4,44 +4,61 @@ use serde_json::Value;
|
||||
use crate::modes::server::common::AppState;
|
||||
use super::tools::{KeepTools, ToolError};
|
||||
|
||||
#[derive(Clone)]
|
||||
/// Server handler for MCP (Model Context Protocol) requests.
|
||||
///
|
||||
/// Routes requests to appropriate tools and handles responses.
|
||||
/// Routes requests to appropriate tools and handles responses. Clones AppState for tool usage.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `state` - The shared application state (DB, config, etc.).
|
||||
#[derive(Clone)]
|
||||
pub struct KeepMcpServer {
|
||||
state: AppState,
|
||||
}
|
||||
|
||||
/// Creates a new `KeepMcpServer` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - The application state containing DB, config, and services.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A new `KeepMcpServer` instance.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let server = KeepMcpServer::new(app_state);
|
||||
/// ```
|
||||
impl KeepMcpServer {
|
||||
/// Creates a new `KeepMcpServer` instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - The application state containing DB and config.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A new `KeepMcpServer`.
|
||||
pub fn new(state: AppState) -> Self {
|
||||
Self { state }
|
||||
}
|
||||
|
||||
/// Handles an MCP request by routing to the appropriate tool.
|
||||
///
|
||||
/// Supports methods like save_item, get_item, etc.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `method` - The MCP method name.
|
||||
/// * `params` - Optional JSON parameters.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// JSON string response on success, or ToolError.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns ToolError::UnknownTool for unsupported methods.
|
||||
/// Handles an MCP request by routing to the appropriate tool.
|
||||
///
|
||||
/// Supports methods like "save_item", "get_item", "list_items". Logs the request and delegates to KeepTools.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `method` - The MCP method name (string).
|
||||
/// * `params` - Optional JSON parameters as serde_json::Value.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// `Ok(String)` with JSON-serialized response on success, or `Err(ToolError)` on failure.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * ToolError::UnknownTool if method unsupported.
|
||||
/// * Propagates tool-specific errors (e.g., invalid args, DB failures).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let result = server.handle_request("save_item", Some(params)).await?;
|
||||
/// ```
|
||||
pub async fn handle_request(&self, method: &str, params: Option<Value>) -> Result<String, ToolError> {
|
||||
debug!("MCP: Handling request '{}' with params: {:?}", method, params);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user