pub struct MCPMessage {
pub magic: String,
pub version: u8,
pub command: String,
pub payload: Value,
}Expand description
Estrutura central que representa uma mensagem no protocolo MCP.
Cada mensagem contém:
- Um campo
magicpara identificar o protocolo (“MCP0”) - Um número de
versionpara controle de compatibilidade - Um
commandque segue o formato “agente:acao” - Um
payloadque contém os dados JSON da requisição ou resposta
Fields§
§magic: StringIdentificador do protocolo, deve ser “MCP0”
version: u8Versão do protocolo, atualmente 1
command: StringComando no formato “agente:acao”
payload: ValuePayload JSON com dados da requisição ou resposta
Implementations§
Source§impl MCPMessage
impl MCPMessage
Sourcepub fn new(command: &str, payload: Value) -> Self
pub fn new(command: &str, payload: Value) -> Self
Cria uma nova mensagem MCP com os valores padrão para magic e version.
§Argumentos
command- Comando no formato “agente:acao”payload- Dados JSON da requisição ou resposta
§Exemplo
use mcprs::agent::MCPMessage;
use serde_json::json;
let message = MCPMessage::new("openai:chat", json!({"user_prompt": "Hello"}));
assert_eq!(message.magic, "MCP0");
assert_eq!(message.version, 1);Trait Implementations§
Source§impl Clone for MCPMessage
impl Clone for MCPMessage
Source§fn clone(&self) -> MCPMessage
fn clone(&self) -> MCPMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MCPMessage
impl Debug for MCPMessage
Source§impl<'de> Deserialize<'de> for MCPMessage
impl<'de> Deserialize<'de> for MCPMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for MCPMessage
impl PartialEq for MCPMessage
Source§impl Serialize for MCPMessage
impl Serialize for MCPMessage
impl StructuralPartialEq for MCPMessage
Auto Trait Implementations§
impl Freeze for MCPMessage
impl RefUnwindSafe for MCPMessage
impl Send for MCPMessage
impl Sync for MCPMessage
impl Unpin for MCPMessage
impl UnwindSafe for MCPMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more