Skip to main content

rust_analyzer_mcp/protocol/
mcp.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Serialize, Deserialize)]
5pub struct MCPRequest {
6    pub jsonrpc: String,
7    pub id: Option<Value>,
8    pub method: String,
9    pub params: Option<Value>,
10}
11
12#[derive(Debug, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum MCPResponse {
15    Success {
16        jsonrpc: String,
17        #[serde(skip_serializing_if = "Option::is_none")]
18        id: Option<Value>,
19        result: Value,
20    },
21    Error {
22        jsonrpc: String,
23        #[serde(skip_serializing_if = "Option::is_none")]
24        id: Option<Value>,
25        error: MCPError,
26    },
27}
28
29#[derive(Debug, Serialize, Deserialize)]
30pub struct MCPError {
31    pub code: i32,
32    pub message: String,
33    pub data: Option<Value>,
34}
35
36#[derive(Debug, Serialize, Deserialize)]
37pub struct ToolDefinition {
38    pub name: String,
39    pub description: String,
40    #[serde(rename = "inputSchema")]
41    pub input_schema: Value,
42}
43
44#[derive(Debug, Serialize, Deserialize)]
45pub struct ToolResult {
46    pub content: Vec<ContentItem>,
47}
48
49#[derive(Debug, Serialize, Deserialize)]
50pub struct ContentItem {
51    #[serde(rename = "type")]
52    pub content_type: String,
53    pub text: String,
54}