Skip to main content

mcp_context_server/protocol/
request.rs

1use serde::{Deserialize, Serialize};
2
3/// JSON-RPC 2.0 ID — may be a number or string per spec.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(untagged)]
6pub enum RpcId {
7    Number(i64),
8    Str(String),
9}
10
11/// JSON-RPC 2.0 request envelope.
12#[derive(Debug, Clone, Deserialize)]
13pub struct JsonRpcRequest {
14    pub jsonrpc: String,
15    pub id: Option<RpcId>,
16    pub method: String,
17    pub params: Option<serde_json::Value>,
18}
19
20/// Parameters for the `context.resolve` tool.
21#[derive(Debug, Clone, Deserialize)]
22pub struct ResolveContextParams {
23    pub cache: String,
24    pub query: String,
25    /// Accepts i64 so we can detect negative values before casting to usize.
26    pub budget: i64,
27}
28
29/// Parameters for the `context.list_caches` tool.
30#[derive(Debug, Clone, Deserialize)]
31pub struct ListCachesParams {
32    pub root: String,
33}
34
35/// Parameters for the `context.inspect_cache` tool.
36#[derive(Debug, Clone, Deserialize)]
37pub struct InspectCacheParams {
38    pub cache: String,
39}
40
41/// MCP `initialize` params.
42#[derive(Debug, Clone, Deserialize)]
43pub struct InitializeParams {
44    #[serde(rename = "protocolVersion")]
45    pub protocol_version: Option<String>,
46    #[serde(rename = "clientInfo")]
47    pub client_info: Option<ClientInfo>,
48}
49
50/// Client information sent during `initialize`.
51#[derive(Debug, Clone, Deserialize)]
52pub struct ClientInfo {
53    pub name: Option<String>,
54    pub version: Option<String>,
55}
56
57/// Parameters for `tools/call`.
58#[derive(Debug, Clone, Deserialize)]
59pub struct ToolCallParams {
60    pub name: String,
61    pub arguments: Option<serde_json::Value>,
62}