Skip to main content

objectiveai_sdk/client_objectiveai_mcp/server_request/
request.rs

1use indexmap::IndexMap;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5/// One reverse-attach request the API has shipped to the calling
6/// client. The proxy's HTTP method (`POST` for the five JSON-RPC
7/// methods, `DELETE` for session terminate) is implicit in the
8/// [`super::Payload`] variant; the JSON-RPC `{jsonrpc, id, method,
9/// params}` envelope is unwrapped into the typed variant payload.
10///
11/// Which CLI-hosted MCP server the request targets rides as
12/// `mcp_kind` on the envelope. The API parses this off the inbound
13/// URL path (`/objectiveai` → [`super::super::McpKind::ObjectiveAi`];
14/// `/{owner}/{name}/{version}/{mcp}` → [`super::super::McpKind::Other`])
15/// before forwarding.
16///
17/// Wire shape (envelope is `{id, mcp_kind, headers?, type, …variant
18/// fields…}` after the `#[serde(flatten)]` on `payload`):
19///
20/// ```json
21/// {
22///   "id":"…",
23///   "mcp_kind":{"type":"objective_ai"},
24///   "headers":{"Mcp-Session-Id":"…"},
25///   "type":"tools_list",
26///   "cursor":"…"
27/// }
28/// ```
29#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
30#[schemars(rename = "client_objectiveai_mcp.server_request.Request")]
31pub struct Request {
32    /// Server-minted correlation id. Echoed by the matching
33    /// [`super::super::server_response::Response`].
34    pub id: String,
35    /// Verbatim copy of the headers the proxy sent on its HTTP
36    /// request to the API. The CLI conduit reads several custom
37    /// `X-OBJECTIVEAI-*` routing headers + `Mcp-Session-Id` off this
38    /// map; protocol-level headers (Host, Content-Length, …) the API
39    /// already stripped on its way in.
40    #[serde(default, skip_serializing_if = "IndexMap::is_empty")]
41    #[schemars(extend("omitempty" = true))]
42    pub headers: IndexMap<String, String>,
43    /// The typed request variant. The MCP-routed variants carry
44    /// `mcp_kind` inside the variant itself (see [`super::Payload`]);
45    /// non-MCP variants don't.
46    #[serde(flatten)]
47    pub payload: super::Payload,
48}
49
50impl Request {
51    /// Which CLI-hosted MCP server this request targets. `Some` for
52    /// the MCP-routed variants (`Initialize` / `ToolsList` /
53    /// `ToolsCall` / `ResourcesList` / `ResourcesRead` /
54    /// `SessionTerminate`); `None` for non-MCP variants
55    /// (`ReadMessageQueue` / `ClearMessageQueue`) which hit the CLI's
56    /// own local state. Delegates to [`super::Payload::mcp_kind`].
57    pub fn mcp_kind(&self) -> Option<super::super::McpKind> {
58        self.payload.mcp_kind()
59    }
60}