3.0 KiB
3.0 KiB
സാമ്പിൾ
ഇത് ഒരു MCP സെർവറിനുള്ള Rust സാമ്പിൾ ആണ്
കാൽക്കുലേറ്റർ ഭാഗം ഇങ്ങനെ കാണപ്പെടുന്നു:
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
pub struct CalculatorRequest {
pub a: f64,
pub b: f64,
}
#[tool_router]
impl Calculator {
#[tool(description = "Adds a and b")]
async fn add(
&self,
Parameters(CalculatorRequest { a, b }): Parameters<CalculatorRequest>,
) -> String {
(a + b).to_string()
}
#[tool(description = "Subtracts b from a")]
async fn subtract(
&self,
Parameters(CalculatorRequest { a, b }): Parameters<CalculatorRequest>,
) -> String {
(a - b).to_string()
}
#[tool(description = "Multiply a with b")]
async fn multiply(
&self,
Parameters(CalculatorRequest { a, b }): Parameters<CalculatorRequest>,
) -> String {
(a * b).to_string()
}
#[tool(description = "Divides a by b")]
async fn divide(
&self,
Parameters(CalculatorRequest { a, b }): Parameters<CalculatorRequest>,
) -> String {
if b == 0.0 {
"Error: Division by zero".to_string()
} else {
(a / b).to_string()
}
}
}
ഇൻസ്റ്റാൾ
താഴെ കാണുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക:
cargo build
പ്രവർത്തിപ്പിക്കുക
cargo run
അസൂയാ:
ഈ രേഖ AI വിവർത്തന സേവനം Co-op Translator ഉപയോഗിച്ച് വിവർത്തനം ചെയ്തതാണ്. നാം കൃത്യതയ്ക്ക് ശ്രമിച്ചെങ്കിലും, സ്വയം പ്രവർത്തിക്കുന്ന വിവർത്തനങ്ങളിൽ പിശകുകൾ അല്ലെങ്കിൽ തെറ്റുകൾ ഉണ്ടാകാമെന്ന് ദയവായി ശ്രദ്ധിക്കുക. അതിന്റെ മാതൃഭാഷയിലുള്ള യഥാർത്ഥ രേഖ അധികാരപരമായ ഉറവിടമായി കണക്കാക്കണം. നിർണായക വിവരങ്ങൾക്ക്, പ്രൊഫഷണൽ മനുഷ്യ വിവർത്തനം ശുപാർശ ചെയ്യപ്പെടുന്നു. ഈ വിവർത്തനം ഉപയോഗിക്കുന്നതിൽ നിന്നുണ്ടാകുന്ന ഏതെങ്കിലും തെറ്റിദ്ധാരണകൾക്കോ തെറ്റായ വ്യാഖ്യാനങ്ങൾക്കോ ഞങ്ങൾ ഉത്തരവാദികളല്ല.