snm_brightdata_client/
types.rs

1// src/types.rs - Fixed version with proper JSON-RPC field names
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5// EXISTING TYPES (preserved)
6#[derive(Debug, Serialize, Deserialize)]
7pub struct ProxyResponse {
8    pub status: String,
9    pub data: serde_json::Value,
10}
11
12#[derive(Debug, Serialize, Deserialize)]
13pub struct ToolCallRequest {
14    pub jsonrpc: String,
15    pub id: u64,
16    pub method: String,
17    pub params: serde_json::Value,
18}
19
20#[derive(Debug, Serialize, Deserialize)]
21pub struct ToolCallResponse {
22    pub id: u64,
23    pub result: Option<serde_json::Value>,
24    pub error: Option<ToolError>,
25}
26
27#[derive(Debug, Serialize, Deserialize)]
28pub struct ToolError {
29    pub code: i64,
30    pub message: String,
31}
32
33// MCP PROTOCOL TYPES (fixed field names)
34#[derive(Debug, Deserialize)]
35pub struct McpRequest {
36    pub jsonrpc: String, // Fixed: Use jsonrpc instead of json_rpc
37    pub id: Option<Value>,
38    pub method: String,
39    pub params: Option<Value>,
40}
41
42#[derive(Debug, Serialize)]
43pub struct McpResponse {
44    pub jsonrpc: String,
45    pub id: Option<Value>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub result: Option<Value>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub error: Option<McpError>,
50}
51
52#[derive(Debug, Serialize)]
53pub struct McpError {
54    pub code: i32,
55    pub message: String,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub data: Option<Value>,
58}
59
60impl McpResponse {
61    pub fn success(id: Option<Value>, result: Value) -> Self {
62        Self {
63            jsonrpc: "2.0".to_string(),
64            id,
65            result: Some(result),
66            error: None,
67        }
68    }
69
70    pub fn error(id: Option<Value>, code: i32, message: &str, data: Option<Value>) -> Self {
71        Self {
72            jsonrpc: "2.0".to_string(),
73            id,
74            result: None,
75            error: Some(McpError {
76                code,
77                message: message.to_string(),
78                data,
79            }),
80        }
81    }
82}