sovran_mcp/
commands.rs

1// commands.rs
2use crate::types::{
3    CallToolRequest, CallToolResponse, GetPromptRequest, GetPromptResponse, InitializeRequest,
4    InitializeResponse, ListPromptsRequest, ListPromptsResponse, ListResourcesRequest,
5    ListResourcesResponse, ListToolsRequest, ListToolsResponse, ReadResourceRequest,
6    ReadResourceResponse, SubscribeRequest, UnsubscribeRequest,
7};
8use crate::types::{CreateMessageRequest, CreateMessageResponse, EmptyResult};
9use serde::{Deserialize, Serialize};
10
11pub trait McpCommand {
12    const COMMAND: &'static str;
13    type Request: Serialize;
14    type Response: for<'de> Deserialize<'de>;
15}
16
17#[derive(Debug, Clone)]
18pub struct Initialize;
19impl McpCommand for Initialize {
20    const COMMAND: &'static str = "initialize";
21    type Request = InitializeRequest;
22    type Response = InitializeResponse;
23}
24
25#[derive(Debug, Clone)]
26pub struct ListTools;
27impl McpCommand for ListTools {
28    const COMMAND: &'static str = "tools/list";
29    type Request = ListToolsRequest;
30    type Response = ListToolsResponse;
31}
32
33#[derive(Debug, Clone)]
34pub struct CallTool;
35impl McpCommand for CallTool {
36    const COMMAND: &'static str = "tools/call";
37    type Request = CallToolRequest;
38    type Response = CallToolResponse;
39}
40
41#[derive(Debug, Clone)]
42pub struct ListPrompts;
43impl McpCommand for ListPrompts {
44    const COMMAND: &'static str = "prompts/list";
45    type Request = ListPromptsRequest;
46    type Response = ListPromptsResponse;
47}
48
49#[derive(Debug, Clone)]
50pub struct GetPrompt;
51impl McpCommand for GetPrompt {
52    const COMMAND: &'static str = "prompts/get";
53    type Request = GetPromptRequest;
54    type Response = GetPromptResponse;
55}
56
57#[derive(Debug, Clone)]
58pub struct ListResources;
59impl McpCommand for ListResources {
60    const COMMAND: &'static str = "resources/list";
61    type Request = ListResourcesRequest;
62    type Response = ListResourcesResponse;
63}
64
65#[derive(Debug, Clone)]
66pub struct ReadResource;
67impl McpCommand for ReadResource {
68    const COMMAND: &'static str = "resources/read";
69    type Request = ReadResourceRequest;
70    type Response = ReadResourceResponse;
71}
72
73#[derive(Debug, Clone)]
74pub struct Subscribe;
75impl McpCommand for Subscribe {
76    const COMMAND: &'static str = "resources/subscribe";
77    type Request = SubscribeRequest;
78    type Response = EmptyResult; // Just returns {}
79}
80
81#[derive(Debug, Clone)]
82pub struct Unsubscribe;
83impl McpCommand for Unsubscribe {
84    const COMMAND: &'static str = "resources/unsubscribe";
85    type Request = UnsubscribeRequest;
86    type Response = EmptyResult;
87}
88
89#[derive(Debug, Clone)]
90pub struct CreateMessage;
91impl McpCommand for CreateMessage {
92    const COMMAND: &'static str = "sampling/createMessage";
93    type Request = CreateMessageRequest;
94    type Response = CreateMessageResponse;
95}