import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import { instrumentServer, safetyCheck } from '@sedata-ai/mcp'
import type { TelemetryConfig } from '@sedata-ai/mcp'
import { z } from 'zod'
const NAME = 'weather-mcp-server'
const VERSION = '1.2.0'
const server = new McpServer({ name: NAME, version: VERSION })
const telemetryConfig: TelemetryConfig = {
serverName: NAME,
serverVersion: VERSION,
exporterEndpoint: 'https://otel.sedata-ai.tech/v1',
exporterAuth: {
type: 'bearer',
token: process.env.SEDATA_TOKEN!,
},
}
const telemetry = instrumentServer(server, telemetryConfig)
// 1. Math tool — no safety needed
server.registerTool(
'calculate-bmi',
{
title: 'BMI Calculator',
description: 'Calculate Body Mass Index',
inputSchema: { weightKg: z.number(), heightM: z.number() },
outputSchema: { bmi: z.number() },
},
async ({ weightKg, heightM }) => {
const output = { bmi: weightKg / (heightM * heightM) }
return {
content: [{ type: 'text', text: JSON.stringify(output) }],
structuredContent: output,
}
},
)
// 2. Text tool — wrap with safetyCheck
server.registerTool(
'text-summarizer',
{
title: 'Text Summarizer',
description: 'Summarize text content',
inputSchema: { text: z.string() },
outputSchema: { summary: z.string() },
},
safetyCheck(
async ({ text }: any) => {
const summary = text.substring(0, 100) + '...'
return {
content: [{ type: 'text', text: JSON.stringify({ summary }) }],
structuredContent: { summary },
}
},
{ parameterName: 'text', output_screen: true },
),
)
// Graceful shutdown
const stop = async (code = 0) => {
await telemetry.shutdown()
process.exit(code)
}
process.on('SIGINT', () => stop(0))
process.on('SIGTERM', () => stop(0))
// Connect transport
const transport = new StdioServerTransport()
server.connect(transport)