77 lines
1.6 KiB
Markdown
77 lines
1.6 KiB
Markdown
# Örnek
|
||
|
||
Bu, bir MCP Sunucusu için JavaScript örneğidir
|
||
|
||
Hesaplayıcı kısmı şöyle görünüyor:
|
||
|
||
```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) }]
|
||
};
|
||
}
|
||
);
|
||
```
|
||
|
||
## Kurulum
|
||
|
||
Aşağıdaki komutu çalıştırın:
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
## Çalıştırma
|
||
|
||
```bash
|
||
npm start
|
||
```
|
||
|
||
**Feragatname**:
|
||
Bu belge, AI çeviri servisi [Co-op Translator](https://github.com/Azure/co-op-translator) kullanılarak çevrilmiştir. Doğruluk için çaba göstersek de, otomatik çevirilerin hatalar veya yanlışlıklar içerebileceğini lütfen unutmayınız. Orijinal belge, kendi dilinde yetkili kaynak olarak kabul edilmelidir. Kritik bilgiler için profesyonel insan çevirisi önerilir. Bu çevirinin kullanımı sonucu ortaya çıkabilecek yanlış anlamalar veya yorum hatalarından sorumlu değiliz. |