Skip to main content

mcpkit_core/
methods.rs

1//! Spec-defined method and notification names.
2//!
3//! These live in core because they are protocol facts, not server facts. They
4//! were previously declared only in `mcpkit-server`, which left every other
5//! crate — core, client, testing, the examples — writing the names as string
6//! literals. That is how three separate places shipped a non-spec
7//! `"initialized"`, and how the debug validator registered it as a known method.
8//!
9//! Use these at any site that **sends** or **matches** a method name. Do not
10//! use them in tests that assert what the wire name is: an assertion against
11//! the constant passes even when the constant is wrong, which is precisely how
12//! those defects stayed green. Tests should spell the literal out.
13//!
14//! Completeness is enforced against the vendored schema — see
15//! `mcpkit/tests/protocol_behaviour_conformance.rs`.
16
17// ---------------------------------------------------------------------------
18// Request methods (20 in 2025-11-25)
19// ---------------------------------------------------------------------------
20
21/// Initialize the connection and negotiate capabilities.
22pub const INITIALIZE: &str = "initialize";
23/// Ping to check if the connection is alive.
24pub const PING: &str = "ping";
25
26/// List available tools.
27pub const TOOLS_LIST: &str = "tools/list";
28/// Call a specific tool with arguments.
29pub const TOOLS_CALL: &str = "tools/call";
30
31/// List available resources.
32pub const RESOURCES_LIST: &str = "resources/list";
33/// Read the contents of a resource.
34pub const RESOURCES_READ: &str = "resources/read";
35/// List available resource templates.
36pub const RESOURCES_TEMPLATES_LIST: &str = "resources/templates/list";
37/// Subscribe to resource updates.
38pub const RESOURCES_SUBSCRIBE: &str = "resources/subscribe";
39/// Unsubscribe from resource updates.
40pub const RESOURCES_UNSUBSCRIBE: &str = "resources/unsubscribe";
41
42/// List available prompts.
43pub const PROMPTS_LIST: &str = "prompts/list";
44/// Get a specific prompt with arguments.
45pub const PROMPTS_GET: &str = "prompts/get";
46
47/// List running tasks.
48pub const TASKS_LIST: &str = "tasks/list";
49/// Get status of a specific task.
50pub const TASKS_GET: &str = "tasks/get";
51/// Cancel a running task.
52pub const TASKS_CANCEL: &str = "tasks/cancel";
53/// Retrieve a terminal task's payload (blocks until terminal, per spec).
54pub const TASKS_RESULT: &str = "tasks/result";
55
56/// List the roots the client exposes.
57pub const ROOTS_LIST: &str = "roots/list";
58
59/// Request the client to sample from a language model.
60pub const SAMPLING_CREATE_MESSAGE: &str = "sampling/createMessage";
61
62/// Request completion suggestions.
63pub const COMPLETION_COMPLETE: &str = "completion/complete";
64
65/// Set the logging level.
66pub const LOGGING_SET_LEVEL: &str = "logging/setLevel";
67
68/// Create an elicitation request.
69pub const ELICITATION_CREATE: &str = "elicitation/create";
70
71// ---------------------------------------------------------------------------
72// Notification methods (11 in 2025-11-25)
73// ---------------------------------------------------------------------------
74
75/// Spec-defined notification method names.
76pub mod notifications {
77    /// Sent by client after successful initialization.
78    pub const INITIALIZED: &str = "notifications/initialized";
79    /// Sent when a request is cancelled.
80    pub const CANCELLED: &str = "notifications/cancelled";
81    /// Sent to report progress on a long-running operation.
82    pub const PROGRESS: &str = "notifications/progress";
83    /// Sent to deliver a log message.
84    pub const MESSAGE: &str = "notifications/message";
85    /// Sent when a resource's content has changed.
86    pub const RESOURCES_UPDATED: &str = "notifications/resources/updated";
87    /// Sent when the list of available resources has changed.
88    pub const RESOURCES_LIST_CHANGED: &str = "notifications/resources/list_changed";
89    /// Sent when the list of available tools has changed.
90    pub const TOOLS_LIST_CHANGED: &str = "notifications/tools/list_changed";
91    /// Sent when the list of available prompts has changed.
92    pub const PROMPTS_LIST_CHANGED: &str = "notifications/prompts/list_changed";
93    /// Sent by the client when its list of roots has changed.
94    pub const ROOTS_LIST_CHANGED: &str = "notifications/roots/list_changed";
95    /// Sent when a URL-mode elicitation's out-of-band interaction has completed.
96    pub const ELICITATION_COMPLETE: &str = "notifications/elicitation/complete";
97    /// Sent by a task receiver when a task changes status. Optional per spec:
98    /// the requesting peer must not rely on receiving it.
99    pub const TASK_STATUS: &str = "notifications/tasks/status";
100}