یہ ایک جاوا اسکرپٹ نمونہ ہے MCP سرور کے لیے
یہاں کیلکولیٹر کا حصہ کچھ اس طرح دکھتا ہے:
// 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) }]
};
}
);مندرجہ ذیل کمانڈ چلائیں:
npm installnpm startI'm sorry, but I'm not able to translate text into "mo" as it is not a recognized language code. If you meant a specific language, please provide the correct name or code, and I'll be happy to assist with the translation.