waypoint 2025.12.1

Waypoint is a Farcaster synchronization tool built in Rust, optimized for memory efficiency.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
//! MCP API handlers for Waypoint

mod casts;
mod common;
mod links;
mod reactions;
mod user_data;
mod utils;

use std::sync::Arc;

use crate::core::types::Fid;
use crate::services::mcp::base::{NullDb, WaypointMcpService};

use rmcp::{
    ErrorData as McpError, RoleServer, ServerHandler,
    handler::server::{
        router::{prompt::PromptRouter, tool::ToolRouter},
        wrapper::Parameters,
    },
    model::CallToolResult,
    model::*,
    prompt, prompt_handler, prompt_router,
    service::RequestContext,
    tool, tool_handler, tool_router,
};

// Non-generic wrapper for WaypointMcpService to use with RMCP macros
#[derive(Clone)]
pub struct WaypointMcpTools {
    service: Arc<WaypointMcpService<NullDb, crate::hub::providers::FarcasterHubClient>>,
    tool_router: ToolRouter<WaypointMcpTools>,
    prompt_router: PromptRouter<WaypointMcpTools>,
}

impl WaypointMcpTools {
    pub fn new(
        service: WaypointMcpService<NullDb, crate::hub::providers::FarcasterHubClient>,
    ) -> Self {
        Self {
            service: Arc::new(service),
            tool_router: Self::tool_router(),
            prompt_router: Self::prompt_router(),
        }
    }
}

// Tool implementations for standard APIs
#[tool_router]
impl WaypointMcpTools {
    fn _create_resource_text(&self, uri: &str, name: &str) -> Resource {
        RawResource::new(uri, name.to_string()).no_annotation()
    }

    // User data APIs
    #[tool(description = "Get Farcaster user data by FID")]
    async fn get_user_by_fid(
        &self,
        Parameters(common::UserByFidRequest { fid }): Parameters<common::UserByFidRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_user_by_fid(fid).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get verified addresses for a Farcaster user")]
    async fn get_verifications_by_fid(
        &self,
        Parameters(common::GetVerificationsRequest { fid, limit }): Parameters<
            common::GetVerificationsRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_verifications_by_fid(fid, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Find a Farcaster user's FID by their username")]
    async fn get_fid_by_username(
        &self,
        Parameters(common::GetFidByUsernameRequest { username }): Parameters<
            common::GetFidByUsernameRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let result = self.service.do_get_fid_by_username(&username).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get a complete Farcaster user profile by username")]
    async fn get_user_by_username(
        &self,
        Parameters(common::GetFidByUsernameRequest { username }): Parameters<
            common::GetFidByUsernameRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let result = self.service.do_get_user_by_username(&username).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    // Cast APIs
    #[tool(description = "Get a specific cast by FID and hash")]
    async fn get_cast(
        &self,
        Parameters(common::GetCastRequest { fid, hash }): Parameters<common::GetCastRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_cast(fid, &hash).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get casts by a specific Farcaster user")]
    async fn get_casts_by_fid(
        &self,
        Parameters(common::GetCastsRequest { fid, limit }): Parameters<common::GetCastsRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_casts_by_fid(fid, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get casts that mention a specific Farcaster user")]
    async fn get_casts_by_mention(
        &self,
        Parameters(common::GetCastMentionsRequest { fid, limit }): Parameters<
            common::GetCastMentionsRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_casts_by_mention(fid, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get cast replies to a specific parent cast")]
    async fn get_casts_by_parent(
        &self,
        Parameters(common::GetCastRepliesRequest { parent_fid, parent_hash, limit }): Parameters<
            common::GetCastRepliesRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let parent_fid = Fid::from(parent_fid);
        let result = self.service.do_get_casts_by_parent(parent_fid, &parent_hash, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get cast replies to a specific URL")]
    async fn get_casts_by_parent_url(
        &self,
        Parameters(common::GetCastRepliesByUrlRequest { parent_url, limit }): Parameters<
            common::GetCastRepliesByUrlRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let result = self.service.do_get_casts_by_parent_url(&parent_url, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get all casts from a user with optional timestamp filtering")]
    async fn get_all_casts_by_fid(
        &self,
        Parameters(common::GetAllCastsWithTimeRequest { fid, limit, start_time, end_time }): Parameters<common::GetAllCastsWithTimeRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_all_casts_by_fid(fid, limit, start_time, end_time).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get conversation details for a cast, including participants and replies")]
    async fn get_conversation(
        &self,
        Parameters(common::GetConversationRequest {
            fid,
            cast_hash,
            recursive,
            max_depth,
            limit
        }): Parameters<common::GetConversationRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = match fid.parse::<u64>() {
            Ok(fid) => Fid::from(fid),
            Err(_) => return Err(McpError::invalid_params("Invalid FID format", None)),
        };

        let result =
            self.service.do_get_conversation(fid, &cast_hash, recursive, max_depth, limit).await;

        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    // Reaction APIs
    #[tool(description = "Get a specific reaction")]
    async fn get_reaction(
        &self,
        Parameters(common::ReactionRequest {
            fid,
            reaction_type,
            target_cast_fid,
            target_cast_hash,
            target_url,
        }): Parameters<common::ReactionRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let target_cast_fid = target_cast_fid.map(Fid::from);

        // Convert hex hash to bytes if provided
        let target_cast_hash_bytes = if let Some(hash) = &target_cast_hash {
            match hex::decode(hash.trim_start_matches("0x")) {
                Ok(bytes) => Some(bytes),
                Err(_) => {
                    return Err(McpError::invalid_params(
                        "Invalid hash format",
                        Some(serde_json::json!({ "hash": hash })),
                    ));
                },
            }
        } else {
            None
        };

        let target_cast_hash_ref = target_cast_hash_bytes.as_deref();
        let target_url_ref = target_url.as_deref();

        let result = self
            .service
            .do_get_reaction(
                fid,
                reaction_type,
                target_cast_fid,
                target_cast_hash_ref,
                target_url_ref,
            )
            .await;

        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get reactions by a specific Farcaster user")]
    async fn get_reactions_by_fid(
        &self,
        Parameters(common::ReactionsByFidRequest { fid, reaction_type, limit }): Parameters<
            common::ReactionsByFidRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_reactions_by_fid(fid, reaction_type, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get reactions for a target (cast or URL)")]
    async fn get_reactions_by_target(
        &self,
        Parameters(common::ReactionsByTargetRequest {
            target_cast_fid,
            target_cast_hash,
            target_url,
            reaction_type,
            limit,
        }): Parameters<common::ReactionsByTargetRequest>,
    ) -> Result<CallToolResult, McpError> {
        let target_cast_fid = target_cast_fid.map(Fid::from);

        // Convert hex hash to bytes if provided
        let target_cast_hash_bytes = if let Some(hash) = &target_cast_hash {
            match hex::decode(hash.trim_start_matches("0x")) {
                Ok(bytes) => Some(bytes),
                Err(_) => {
                    return Err(McpError::invalid_params(
                        "Invalid hash format",
                        Some(serde_json::json!({ "hash": hash })),
                    ));
                },
            }
        } else {
            None
        };

        let target_cast_hash_ref = target_cast_hash_bytes.as_deref();
        let target_url_ref = target_url.as_deref();

        let result = self
            .service
            .do_get_reactions_by_target(
                target_cast_fid,
                target_cast_hash_ref,
                target_url_ref,
                reaction_type,
                limit,
            )
            .await;

        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get all reactions from a user with optional timestamp filtering")]
    async fn get_all_reactions_by_fid(
        &self,
        Parameters(common::FidTimestampRequest { fid, limit, start_time, end_time }): Parameters<
            common::FidTimestampRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result =
            self.service.do_get_all_reactions_by_fid(fid, limit, start_time, end_time).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    // Link APIs
    #[tool(description = "Get a specific link")]
    async fn get_link(
        &self,
        Parameters(common::LinkRequest { fid, link_type, target_fid }): Parameters<
            common::LinkRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let target_fid = Fid::from(target_fid);
        let result = self.service.do_get_link(fid, &link_type, target_fid).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get links by a specific Farcaster user")]
    async fn get_links_by_fid(
        &self,
        Parameters(common::LinksByFidRequest { fid, link_type, limit }): Parameters<
            common::LinksByFidRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        // Use "follow" as default when None is explicitly provided
        let link_type_ref = match link_type {
            Some(ref lt) if lt.is_empty() => Some("follow"),
            Some(ref lt) => Some(lt.as_str()),
            None => Some("follow"),
        };
        let result = self.service.do_get_links_by_fid(fid, link_type_ref, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get links to a target Farcaster user")]
    async fn get_links_by_target(
        &self,
        Parameters(common::LinksByTargetRequest { target_fid, link_type, limit }): Parameters<
            common::LinksByTargetRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let target_fid = Fid::from(target_fid);
        // Use "follow" as default when None is explicitly provided
        let link_type_ref = match link_type {
            Some(ref lt) if lt.is_empty() => Some("follow"),
            Some(ref lt) => Some(lt.as_str()),
            None => Some("follow"),
        };
        let result = self.service.do_get_links_by_target(target_fid, link_type_ref, limit).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get link compact state messages for a Farcaster user")]
    async fn get_link_compact_state_by_fid(
        &self,
        Parameters(common::FidRequest { fid }): Parameters<common::FidRequest>,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_link_compact_state_by_fid(fid).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }

    #[tool(description = "Get all links from a user with optional timestamp filtering")]
    async fn get_all_links_by_fid(
        &self,
        Parameters(common::FidTimestampRequest { fid, limit, start_time, end_time }): Parameters<
            common::FidTimestampRequest,
        >,
    ) -> Result<CallToolResult, McpError> {
        let fid = Fid::from(fid);
        let result = self.service.do_get_all_links_by_fid(fid, limit, start_time, end_time).await;
        Ok(CallToolResult::success(vec![Content::text(result)]))
    }
}

#[prompt_router]
impl WaypointMcpTools {
    /// A prompt that helps with Farcaster data querying and takes an FID parameter
    #[prompt(name = "waypoint_prompt")]
    async fn waypoint_prompt(
        &self,
        Parameters(common::WaypointPromptArgs { fid, username }): Parameters<
            common::WaypointPromptArgs,
        >,
        _ctx: RequestContext<RoleServer>,
    ) -> Result<GetPromptResult, McpError> {
        // Check if username is provided, ensuring we preserve any .eth suffix
        let username_context = if let Some(username) = username {
            // Make sure to use the full username including .eth if present
            format!(" (username: {})", username)
        } else {
            "".to_string()
        };

        let prompt = format!(
            "You are a helpful assistant for exploring Farcaster data. You're currently focusing on FID {}{}. You can help fetch user data, verifications, casts, reactions, and links for this user using the appropriate tools.",
            fid, username_context
        );

        Ok(GetPromptResult {
            description: Some("A prompt for Farcaster data exploration".to_string()),
            messages: vec![PromptMessage {
                role: PromptMessageRole::Assistant,
                content: PromptMessageContent::text(prompt),
            }],
        })
    }
}

#[tool_handler]
#[prompt_handler]
impl ServerHandler for WaypointMcpTools {
    fn get_info(&self) -> ServerInfo {
        ServerInfo {
            protocol_version: ProtocolVersion::V_2024_11_05,
            capabilities: ServerCapabilities::builder()
                .enable_prompts()
                .enable_resources()
                .enable_tools()
                .build(),
            server_info: Implementation::from_build_env(),
            instructions: Some("Waypoint MCP service with tools to query Farcaster data. Access user data, verifications, casts, reactions, and links with comprehensive APIs for exploring the Farcaster social graph.".to_string()),
        }
    }

    async fn list_resources(
        &self,
        _request: Option<PaginatedRequestParam>,
        _: RequestContext<RoleServer>,
    ) -> Result<ListResourcesResult, McpError> {
        Ok(ListResourcesResult {
            resources: vec![
                self._create_resource_text("str:///waypoint/docs", "waypoint-docs"),
                self._create_resource_text("memo://farcaster-info", "farcaster-info"),
            ],
            next_cursor: None,
        })
    }

    async fn read_resource(
        &self,
        ReadResourceRequestParam { uri }: ReadResourceRequestParam,
        _: RequestContext<RoleServer>,
    ) -> Result<ReadResourceResult, McpError> {
        match uri.as_str() {
            "str:///waypoint/docs" => {
                let docs = "Waypoint is a Farcaster data indexer that streams data from the Farcaster network and allows querying by FID.";
                Ok(ReadResourceResult { contents: vec![ResourceContents::text(docs, uri)] })
            },
            "memo://farcaster-info" => {
                let info = "Farcaster is a decentralized social network built on Ethereum. Users have an FID (Farcaster ID) that identifies them on the network.";
                Ok(ReadResourceResult { contents: vec![ResourceContents::text(info, uri)] })
            },
            _ => Err(McpError::resource_not_found(
                format!("Resource not found: {}", uri),
                Some(serde_json::json!({
                    "uri": uri
                })),
            )),
        }
    }

    async fn list_resource_templates(
        &self,
        _request: Option<PaginatedRequestParam>,
        _: RequestContext<RoleServer>,
    ) -> Result<ListResourceTemplatesResult, McpError> {
        Ok(ListResourceTemplatesResult { resource_templates: vec![], next_cursor: None })
    }
}