import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
export function registerTools(server: McpServer) {
// Example Tool 1: Add two numbers
server.registerTool(
'add',
{
title: 'Addition Tool',
description: 'Add two numbers together',
inputSchema: {
a: z.number().describe('First number'),
b: z.number().describe('Second number'),
},
},
async ({ a, b }) => {
try {
const result = a + b;
return {
content: [
{
type: 'text' as const,
text: `Result: ${result}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
// Example Tool 2: Echo text
server.registerTool(
'echo',
{
title: 'Echo Tool',
description: 'Echo back the provided text',
inputSchema: {
message: z.string().describe('Message to echo'),
},
},
async ({ message }) => {
return {
content: [
{
type: 'text' as const,
text: message,
},
],
};
}
);
// Example Tool 3: Get current timestamp
server.registerTool(
'timestamp',
{
title: 'Timestamp Tool',
description: 'Get the current timestamp',
inputSchema: {},
},
async () => {
const now = new Date();
return {
content: [
{
type: 'text' as const,
text: JSON.stringify({
iso: now.toISOString(),
unix: Math.floor(now.getTime() / 1000),
local: now.toLocaleString(),
}, null, 2),
},
],
};
}
);
}