hyperlane_plugin_mcp/enum.rs
1use super::*;
2
3/// Errors returned by MCP tool, resource, prompt, or protocol handlers.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum McpError {
6 /// Invalid or missing parameters (`-32602`).
7 InvalidParams(String),
8 /// Requested tool, resource, or prompt was not found (`-32601`).
9 NotFound(String),
10 /// Internal execution failure (`-32603`).
11 Internal(String),
12}
13
14/// Outcome returned by [`crate::McpRegistry::handle_json_bytes`] for HTTP transport translation.
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub enum McpDispatchOutcome {
17 /// JSON response payload plus optional newly assigned `Mcp-Session-Id`.
18 Response {
19 /// Serialized JSON-RPC response bytes.
20 body: Vec<u8>,
21 /// Newly minted session id when answering `initialize`.
22 new_session_id: Option<String>,
23 },
24 /// Notification accepted with HTTP `202 Accepted` and no body.
25 Accepted,
26 /// Caller supplied an unknown or expired `Mcp-Session-Id` (`404 Not Found`).
27 UnknownSession,
28 /// Active session table reached `max_sessions` (`503 Service Unavailable`).
29 SessionLimitReached,
30}
31
32/// Zero-allocation JSON-RPC 2.0 correlation identifier decoded without `serde_json::Value` allocations.
33pub(crate) enum McpRpcId<'a> {
34 /// JSON `null`.
35 Null,
36 /// Unsigned 64-bit integer id.
37 U64(u64),
38 /// Signed 64-bit integer id.
39 I64(i64),
40 /// Borrowed or unescaped string id.
41 Str(Cow<'a, str>),
42 /// Fallback JSON value for uncommon id types (floats, booleans).
43 Other(Value),
44}
45
46/// Zero-allocation JSON-RPC 2.0 envelope field discriminator.
47pub(crate) enum McpRpcField {
48 /// `"jsonrpc"` version field.
49 JsonRpc,
50 /// `"method"` field.
51 Method,
52 /// `"id"` correlation field.
53 Id,
54 /// `"params"` payload field.
55 Params,
56 /// Unknown top-level field skipped via `IgnoredAny`.
57 Ignore,
58}
59
60/// Zero-allocation field discriminator for `tools/call` and `prompts/get` params.
61pub(crate) enum McpNamedParamsField {
62 /// `"name"` field.
63 Name,
64 /// `"arguments"` field.
65 Arguments,
66 /// Unknown params field skipped via `IgnoredAny`.
67 Ignore,
68}
69
70/// Zero-allocation field discriminator for `resources/read` params.
71pub(crate) enum McpUriParamsField {
72 /// `"uri"` field.
73 Uri,
74 /// Unknown params field skipped via `IgnoredAny`.
75 Ignore,
76}
77
78/// Parsed MCP `params` representation avoiding intermediate `serde_json::Map` trees on known methods.
79pub(crate) enum McpParsedParams<'a> {
80 /// No params supplied or skipped via `IgnoredAny`.
81 None,
82 /// Non-object params value (produces `-32602 Invalid params` when an object is required).
83 Invalid,
84 /// Directly decoded `tools/call` or `prompts/get` parameters.
85 Named {
86 /// Tool or prompt name borrowed from the raw request when unescaped.
87 name: Option<Cow<'a, str>>,
88 /// Optional arguments JSON value.
89 arguments: Option<Value>,
90 },
91 /// Directly decoded `resources/read` parameters.
92 Uri {
93 /// Resource URI string.
94 uri: Option<String>,
95 },
96 /// Fallback raw `Value` used only when `"params"` appeared before `"method"` in JSON key order.
97 Raw(Value),
98}