@ryancardin/noaa-tides-currents-mcp-server
Version:
MCP Server that interfaces with NOAA Tides and Currents API using FastMCP
52 lines (51 loc) • 1.88 kB
JavaScript
import { z } from 'zod';
import { StationSchema, UnitsSchema } from '../schemas/common.js';
/**
* Register station-related tools with the MCP server
*/
export function registerStationTools(server, noaaService) {
// Add stations tool
server.addTool({
name: 'get_stations',
description: 'Get list of stations',
parameters: z.object({
type: z.string().optional().describe('Station type (waterlevels, currents, etc.)'),
format: z.enum(['json', 'xml']).optional().describe('Output format (json, xml)'),
units: UnitsSchema,
}),
execute: async (params) => {
try {
const result = await noaaService.getStations(params);
return JSON.stringify(result);
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to get stations: ${error.message}`);
}
throw new Error('Failed to get stations');
}
}
});
// Add station details tool
server.addTool({
name: 'get_station_details',
description: 'Get detailed information about a station',
parameters: z.object({
station: StationSchema,
format: z.enum(['json', 'xml']).optional().describe('Output format (json, xml)'),
units: UnitsSchema,
}),
execute: async (params) => {
try {
const result = await noaaService.getStationDetails(params);
return JSON.stringify(result);
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to get station details: ${error.message}`);
}
throw new Error('Failed to get station details');
}
}
});
}