x_mcp_server/
types.rs

1//! Type definitions for X API responses
2
3use serde::{Deserialize, Serialize};
4
5/// User information from X API
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct User {
8    pub id: String,
9    pub name: String,
10    pub username: String,
11    pub description: Option<String>,
12    pub public_metrics: Option<UserMetrics>,
13    pub profile_image_url: Option<String>,
14    pub verified: Option<bool>,
15    pub created_at: Option<String>,
16}
17
18/// User metrics (followers, following, etc.)
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct UserMetrics {
21    pub followers_count: u64,
22    pub following_count: u64,
23    pub tweet_count: u64,
24    pub listed_count: u64,
25}
26
27/// Tweet information from X API
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct Tweet {
30    pub id: String,
31    pub text: String,
32    pub author_id: Option<String>,
33    pub created_at: Option<String>,
34    pub public_metrics: Option<TweetMetrics>,
35    pub context_annotations: Option<Vec<ContextAnnotation>>,
36    pub referenced_tweets: Option<Vec<ReferencedTweet>>,
37}
38
39/// Tweet metrics (likes, retweets, etc.)
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct TweetMetrics {
42    pub retweet_count: u64,
43    pub like_count: u64,
44    pub reply_count: u64,
45    pub quote_count: u64,
46}
47
48/// Context annotation for tweets
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct ContextAnnotation {
51    pub domain: Domain,
52    pub entity: Entity,
53}
54
55/// Domain information
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct Domain {
58    pub id: String,
59    pub name: String,
60    pub description: Option<String>,
61}
62
63/// Entity information
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct Entity {
66    pub id: String,
67    pub name: String,
68    pub description: Option<String>,
69}
70
71/// Referenced tweet information
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct ReferencedTweet {
74    #[serde(rename = "type")]
75    pub tweet_type: String,
76    pub id: String,
77}
78
79/// Response wrapper for X API
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct XResponse<T> {
82    pub data: Option<T>,
83    pub includes: Option<Includes>,
84    pub errors: Option<Vec<XApiError>>,
85    pub meta: Option<serde_json::Value>,
86}
87
88/// Includes section for API responses
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct Includes {
91    pub users: Option<Vec<User>>,
92    pub tweets: Option<Vec<Tweet>>,
93}
94
95/// X API error response
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct XApiError {
98    pub title: String,
99    pub detail: Option<String>,
100    pub resource_type: Option<String>,
101    pub parameter: Option<String>,
102    pub value: Option<String>,
103    #[serde(rename = "type")]
104    pub error_type: Option<String>,
105}
106
107
108
109/// Search tweets request parameters
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct SearchTweetsParams {
112    pub query: String,
113    pub max_results: Option<u32>,
114    pub tweet_fields: Option<Vec<String>>,
115    pub user_fields: Option<Vec<String>>,
116    pub expansions: Option<Vec<String>>,
117}