import { serve } from '@hono/node-server' import { Hono } from 'hono' import worker from './index.js' const app = new Hono() // Health check app.get('/health', (c) => c.text('OK')) // API Docs - Simple HTML page listing endpoints app.get('/api-docs', (c) => { return c.html(` Jina MCP Server API Docs

Jina MCP Server API Documentation

This server implements the Model Context Protocol (MCP) for Jina AI tools.

GET /

Returns server information and available tools in YAML format.

GET/POST /v1

MCP Protocol Endpoint. Handles JSON-RPC messages.

GET /sse

Server-Sent Events endpoint for MCP.

GET /health

Health check endpoint. Returns "OK".

Tools Available

`) }) // Forward everything else to the worker app.all('*', async (c) => { const env = { JINA_API_KEY: process.env.JINA_API_KEY, VITE_GHOST_API_KEY: process.env.VITE_GHOST_API_KEY, API_BASE_URL: process.env.API_BASE_URL || 'https://api.jina.ai' }; const ctx = { waitUntil: (promise: Promise) => { // In a real worker, this keeps the worker alive. // In Node, we just let it run in background but catch errors. promise.catch(console.error); }, passThroughOnException: () => {}, props: {} }; // Mock CF object const request = c.req.raw as any; // Create a dummy CF object const cf = { timezone: 'UTC', country: 'US', city: 'Unknown', region: 'Unknown', regionCode: 'Unknown', continent: 'NA', postalCode: '00000', metroCode: '0', latitude: '0', longitude: '0', isEUCountry: '0', asn: 0, asOrganization: 'Unknown', colo: 'Unknown', httpProtocol: 'HTTP/1.1', tlsVersion: 'TLSv1.3' }; // Monkey-patch cf onto request if not present if (!request.cf) { Object.defineProperty(request, 'cf', { value: cf }); } return await worker.fetch(request, env as any, ctx); }) const port = 7860 console.log(`Server is running on port ${port}`) serve({ fetch: app.fetch, port })