import { Tool, ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { ToolRegistration } from "../core/types.js";
import { registerOpenWeather } from "../apis/weather/openweather.js";
import { registerGoogleMaps } from "../apis/maps/google.js";
import { registerNewsApi } from "../apis/news/newsapi.js";
import { registerGitHub } from "../apis/github/github.js";
import { registerNotion } from "../apis/notion/notion.js";
import { registerTrello } from "../apis/trello/trello.js";
import { registerSpotify } from "../apis/spotify/spotify.js";
import { registerTwilio } from "../apis/twilio/twilio.js";
import { registerUnsplash } from "../apis/unsplash/unsplash.js";
import { registerCoinGecko } from "../apis/crypto/coingecko.js";
export type Registered = {
tools: Tool[];
handlers: Record<string, (args: Record<string, unknown>) => Promise<unknown>>;
};
export function registerAllTools(server: Server): Registered {
const registrations: ToolRegistration[] = [
registerOpenWeather(),
registerGoogleMaps(),
registerNewsApi(),
registerGitHub(),
registerNotion(),
registerTrello(),
registerSpotify(),
registerTwilio(),
registerUnsplash(),
registerCoinGecko(),
];
const tools = registrations.flatMap((r) => r.tools as Tool[]);
const handlers: Record<string, (args: Record<string, unknown>) => Promise<unknown>> = {};
for (const r of registrations) {
Object.assign(handlers, r.handlers);
}
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const name = request.params.name;
const handler = handlers[name];
if (!handler) throw new Error(`Unknown tool: ${name}`);
const result = await handler((request.params.arguments as Record<string, unknown>) || {});
return { content: [{ type: "json", json: result }] as any };
});
return { tools, handlers };
}