Skip to main content

agentic_memory_mcp/protocol/
validator.rs

1//! JSON-RPC message validation per MCP spec.
2
3use crate::types::{JsonRpcRequest, McpError, McpResult, JSONRPC_VERSION};
4
5/// Validate that a JSON-RPC request is well-formed.
6pub fn validate_request(request: &JsonRpcRequest) -> McpResult<()> {
7    if request.jsonrpc != JSONRPC_VERSION {
8        return Err(McpError::InvalidRequest(format!(
9            "Expected jsonrpc version \"{JSONRPC_VERSION}\", got \"{}\"",
10            request.jsonrpc
11        )));
12    }
13
14    if request.method.is_empty() {
15        return Err(McpError::InvalidRequest(
16            "Method name must not be empty".to_string(),
17        ));
18    }
19
20    Ok(())
21}