MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / from_str

Method from_str

crates/opencode-mcp/src/protocol.rs:64–72  ·  view source on GitHub ↗

Try to parse a raw JSON string as either a Response or a Notification. Responses have an `id` field; notifications have a `method` field but no `id`.

(s: &str)

Source from the content-addressed store, hash-verified

62 /// Try to parse a raw JSON string as either a Response or a Notification.
63 /// Responses have an `id` field; notifications have a `method` field but no `id`.
64 pub fn from_str(s: &str) -> Result<Self, serde_json::Error> {
65 // Try response first (has `id`)
66 if let Ok(resp) = serde_json::from_str::<JsonRpcResponse>(s) {
67 return Ok(JsonRpcMessage::Response(resp));
68 }
69 // Fall back to notification (has `method`, no `id`)
70 let notif = serde_json::from_str::<JsonRpcNotification>(s)?;
71 Ok(JsonRpcMessage::Notification(notif))
72 }
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]

Callers

nothing calls this directly

Calls 1

ResponseEnum · 0.85

Tested by

no test coverage detected