Skip to main content

objectiveai_sdk/client_objectiveai_mcp/client_request/
payload.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// Tagged union of request shapes the client-app layer can push down
5/// the reverse-attach channel.
6///
7/// Currently a single client → API variant: `McpListChanged`. The CLI's
8/// upstream `mcp::Connection` fired
9/// `notifications/{tools,resources}/list_changed` and the API
10/// re-emits it as an SSE event on the matching per-MCP GET stream —
11/// `/objectiveai` or `/{owner}/{name}/{ver}/{mcp}`, routed by
12/// `X-OBJECTIVEAI-RESPONSE-ID`.
13///
14/// The wire envelope's `id` field always belongs to whichever side
15/// originated the request; the receiver's `client_response::Response`
16/// echoes the same `id`.
17#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
18#[schemars(rename = "client_objectiveai_mcp.client_request.Payload")]
19#[serde(tag = "type", rename_all = "snake_case")]
20pub enum Payload {
21    /// The CLI's upstream `mcp::Connection` for `mcp_kind` fired
22    /// `notifications/<kind>/list_changed`. The API dispatches this
23    /// onto its per-`(response_id, McpKind)` broadcast so the
24    /// matching MCP GET-SSE listener sees a standard MCP
25    /// notification frame.
26    #[schemars(title = "McpListChanged")]
27    McpListChanged(McpListChanged),
28}
29
30/// Payload for [`Payload::McpListChanged`].
31#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
32#[schemars(rename = "client_objectiveai_mcp.client_request.McpListChanged")]
33pub struct McpListChanged {
34    /// Which CLI-hosted MCP server fired the list-changed
35    /// notification. The API uses this to look up the right
36    /// per-MCP SSE broadcast and republish a standard MCP
37    /// notification frame to that upstream's proxy subscriber.
38    pub mcp_kind: super::super::McpKind,
39    /// Which catalog changed.
40    pub kind: McpListChangedKind,
41}
42
43/// Distinguishes `tools/list_changed` from `resources/list_changed`.
44#[derive(
45    Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash,
46)]
47#[schemars(rename = "client_objectiveai_mcp.client_request.McpListChangedKind")]
48#[serde(rename_all = "snake_case")]
49pub enum McpListChangedKind {
50    Tools,
51    Resources,
52}
53
54impl McpListChangedKind {
55    /// JSON-RPC method name MCP uses on the wire for this notification
56    /// kind. Used by the API's GET-SSE handler when it emits the
57    /// translated frame to subscribers.
58    pub fn method(&self) -> &'static str {
59        match self {
60            McpListChangedKind::Tools => "notifications/tools/list_changed",
61            McpListChangedKind::Resources => {
62                "notifications/resources/list_changed"
63            }
64        }
65    }
66}