context_creator/mcp_server/
rmcp_handlers.rs

1//! Helper functions for RMCP server implementation
2
3use anyhow::{bail, Result};
4use std::path::Path;
5
6/// Validate path for security issues
7pub fn validate_path(path: &Path) -> Result<()> {
8    // Check for path traversal attempts
9    let path_str = path.to_string_lossy();
10    if path_str.contains("..") || path_str.contains('~') {
11        bail!("Path traversal attempt detected");
12    }
13
14    // Check if path exists
15    if !path.exists() {
16        bail!("Path does not exist: {}", path.display());
17    }
18
19    // Check if we have read permissions
20    if !path.is_dir() && !path.is_file() {
21        bail!("Path is not a file or directory: {}", path.display());
22    }
23
24    Ok(())
25}
26
27/// Validate URL for security
28pub fn validate_url(url: &str) -> Result<()> {
29    // Basic URL validation
30    if !url.starts_with("https://") && !url.starts_with("http://") {
31        bail!("Invalid URL: must start with http:// or https://");
32    }
33
34    // GitHub URL validation
35    if url.contains("github.com") && !url.contains("/") {
36        bail!("Invalid GitHub URL format");
37    }
38
39    Ok(())
40}