mcp_protocol/
constants.rs

1// mcp-protocol/src/constants.rs
2
3/// The current protocol version
4pub const PROTOCOL_VERSION: &str = "2024-11-05";
5
6/// JSON-RPC method names
7pub mod methods {
8    // Lifecycle methods
9    pub const INITIALIZE: &str = "initialize";
10    pub const INITIALIZED: &str = "notifications/initialized";
11
12    // Tool methods
13    pub const TOOLS_LIST: &str = "tools/list";
14    pub const TOOLS_CALL: &str = "tools/call";
15    
16    // Tool notifications
17    pub const TOOLS_LIST_CHANGED: &str = "notifications/tools/list_changed";
18    
19    // Resource methods
20    pub const RESOURCES_LIST: &str = "resources/list";
21    pub const RESOURCES_READ: &str = "resources/read";
22    pub const RESOURCES_SUBSCRIBE: &str = "resources/subscribe";
23    pub const RESOURCES_UNSUBSCRIBE: &str = "resources/unsubscribe";
24    
25    // Resource template methods
26    pub const RESOURCES_TEMPLATES_LIST: &str = "resources/templates/list";
27    
28    // Prompt methods
29    pub const PROMPTS_LIST: &str = "prompts/list";
30    pub const PROMPTS_GET: &str = "prompts/get";
31    
32    // Prompt notifications
33    pub const PROMPTS_LIST_CHANGED: &str = "notifications/prompts/list_changed";
34    
35    // Completion methods
36    pub const COMPLETION_COMPLETE: &str = "completion/complete";
37    
38    // Resource notifications
39    pub const RESOURCES_UPDATED: &str = "notifications/resources/updated";
40    pub const RESOURCES_LIST_CHANGED: &str = "notifications/resources/list_changed";
41    
42    // Sampling methods
43    pub const SAMPLING_CREATE_MESSAGE: &str = "sampling/createMessage";
44    
45    // Logging notifications
46    pub const LOG: &str = "notifications/log";
47}
48
49/// JSON-RPC error codes
50pub mod error_codes {
51    // Standard JSON-RPC error codes
52    pub const PARSE_ERROR: i32 = -32700;
53    pub const INVALID_REQUEST: i32 = -32600;
54    pub const METHOD_NOT_FOUND: i32 = -32601;
55    pub const INVALID_PARAMS: i32 = -32602;
56    pub const INTERNAL_ERROR: i32 = -32603;
57    
58    // MCP specific error codes
59    pub const RESOURCE_NOT_FOUND: i32 = -32002;
60    pub const SERVER_NOT_INITIALIZED: i32 = -32003;
61    pub const SAMPLING_NOT_ENABLED: i32 = -32004;
62    pub const SAMPLING_NO_CALLBACK: i32 = -32005;
63    pub const SAMPLING_ERROR: i32 = -32006;
64}