#!/usr/bin/env node import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; import { fetchWithTimeout } from "./fetcher.js"; const server = new McpServer({ name: "{{PROJECT_NAME}}", version: "{{VERSION}}", }); // ── Example: Fetch and analyze a URL ───────────────────── // This template shows how to build an API-wrapper MCP server. // Pattern extracted from webcheck-mcp (84+ downloads/week). server.tool( "fetch_url", "Fetch a URL and return status, headers, response time, and body preview", { url: z.string().url().describe("URL to fetch"), timeout_ms: z .number() .optional() .default(10000) .describe("Request timeout in milliseconds"), }, async ({ url, timeout_ms }) => { try { const result = await fetchWithTimeout(url, { timeoutMs: timeout_ms }); const analysis = { url, status: result.status, responseTimeMs: result.responseTimeMs, contentLength: result.body.length, contentType: result.headers["content-type"] || "unknown", bodyPreview: result.body.slice(0, 500), }; return { content: [ { type: "text", text: JSON.stringify(analysis, null, 2) }, ], }; } catch (e: any) { return { content: [ { type: "text", text: `Error fetching ${url}: ${e.message}`, }, ], }; } } ); server.tool( "check_status", "Check if a URL is reachable and return HTTP status code", { urls: z .array(z.string().url()) .describe("List of URLs to check"), }, async ({ urls }) => { const results = await Promise.all( urls.map(async (url) => { try { const res = await fetchWithTimeout(url, { timeoutMs: 5000 }); return { url, status: res.status, ok: res.status < 400 }; } catch (e: any) { return { url, status: 0, ok: false, error: e.message }; } }) ); return { content: [ { type: "text", text: JSON.stringify(results, null, 2) }, ], }; } ); // ── Add more tools below ───────────────────────────────── // Tip: Keep tool descriptions concise but specific. // The AI model sees these descriptions to decide which tool to use. // ── Start server ───────────────────────────────────────── async function main() { const transport = new StdioServerTransport(); await server.connect(transport); } main().catch(console.error);