#!/usr/bin/env node import { createRequire } from "node:module"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { registerTilerTool } from "./tools/tiler.js"; import { registerPrompts } from "./prompts/index.js"; import { registerResources } from "./resources/index.js"; const require = createRequire(import.meta.url); const { version } = require("../package.json") as { version: string }; const args = process.argv.slice(2); if (args.includes("--version") || args.includes("-v")) { console.log(version); process.exit(0); } if (args.includes("--help") || args.includes("-h")) { console.log(`image-tiler-mcp-server v${version} MCP server that splits large images into optimally-sized tiles for LLM vision. Runs on stdio transport — designed to be launched by an MCP client. Usage: image-tiler-mcp-server Start the MCP server (stdio) image-tiler-mcp-server --version Print version and exit image-tiler-mcp-server --help Print this help and exit More info: https://github.com/keiver/image-tiler-mcp-server`); process.exit(0); } const server = new McpServer({ name: "image-tiler-mcp-server", version, }); registerTilerTool(server); registerPrompts(server); registerResources(server); async function runStdio(): Promise { const transport = new StdioServerTransport(); await server.connect(transport); console.error("image-tiler-mcp-server running on stdio"); } async function shutdown(): Promise { await server.close(); process.exit(0); } process.on("SIGINT", shutdown); process.on("SIGTERM", shutdown); process.on("uncaughtException", (error: Error) => { console.error("Uncaught exception:", error); shutdown().catch(() => process.exit(1)); }); process.on("unhandledRejection", (reason: unknown) => { console.error("Unhandled rejection:", reason); shutdown().catch(() => process.exit(1)); }); runStdio().catch((error: unknown) => { console.error("Server error:", error); process.exit(1); });