79 lines
1.6 KiB
Markdown
79 lines
1.6 KiB
Markdown
# Pavyzdys
|
|
|
|
Tai yra JavaScript pavyzdys MCP serveriui
|
|
|
|
Štai kaip atrodo skaičiuotuvo dalis:
|
|
|
|
```javascript
|
|
// Define calculator tools for each operation
|
|
server.tool(
|
|
"add",
|
|
{
|
|
a: z.number(),
|
|
b: z.number()
|
|
},
|
|
async ({ a, b }) => ({
|
|
content: [{ type: "text", text: String(a + b) }]
|
|
})
|
|
);
|
|
|
|
server.tool(
|
|
"subtract",
|
|
{
|
|
a: z.number(),
|
|
b: z.number()
|
|
},
|
|
async ({ a, b }) => ({
|
|
content: [{ type: "text", text: String(a - b) }]
|
|
})
|
|
);
|
|
|
|
server.tool(
|
|
"multiply",
|
|
{
|
|
a: z.number(),
|
|
b: z.number()
|
|
},
|
|
async ({ a, b }) => ({
|
|
content: [{ type: "text", text: String(a * b) }]
|
|
})
|
|
);
|
|
|
|
server.tool(
|
|
"divide",
|
|
{
|
|
a: z.number(),
|
|
b: z.number()
|
|
},
|
|
async ({ a, b }) => {
|
|
if (b === 0) {
|
|
return {
|
|
content: [{ type: "text", text: "Error: Cannot divide by zero" }],
|
|
isError: true
|
|
};
|
|
}
|
|
return {
|
|
content: [{ type: "text", text: String(a / b) }]
|
|
};
|
|
}
|
|
);
|
|
```
|
|
|
|
## Įdiegimas
|
|
|
|
Paleiskite šią komandą:
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
## Paleidimas
|
|
|
|
```bash
|
|
npm start
|
|
```
|
|
|
|
---
|
|
|
|
**Atsakomybės apribojimas**:
|
|
Šis dokumentas buvo išverstas naudojant AI vertimo paslaugą [Co-op Translator](https://github.com/Azure/co-op-translator). Nors siekiame tikslumo, prašome atkreipti dėmesį, kad automatiniai vertimai gali turėti klaidų ar netikslumų. Originalus dokumentas jo gimtąja kalba turėtų būti laikomas autoritetingu šaltiniu. Kritinei informacijai rekomenduojama profesionali žmogaus vertimo paslauga. Mes neprisiimame atsakomybės už nesusipratimus ar klaidingus interpretavimus, atsiradusius naudojant šį vertimą. |