import { createMCPServer } from "./server/mcp.js";
import { createCMSApp } from "./cms/server/api.js";
import { serve } from "@hono/node-server";
import dotenv from "dotenv";
dotenv.config();
const isSSE = process.argv.includes("--sse");
const PORT = parseInt(process.env.PORT || "3000");
// 初始化 MCP 服务器
const mcp = createMCPServer();
// 初始化 CMS 应用
const cmsApp = createCMSApp();
if (isSSE) {
// --- 远程模式 (SSE) ---
// 运行 CMS (在 PORT + 1)
const cmsPort = PORT + 1;
serve({
fetch: cmsApp.fetch,
port: cmsPort,
}, (info) => {
console.error(`[CMS] 内容管理后台运行在 http://localhost:${info.port}`);
});
// 运行 MCP SSE (在 PORT)
mcp.start({
transportType: "httpStream",
httpStream: {
endpoint: "/sse",
port: PORT,
},
});
console.error(`[MCP] 远程服务 (SSE/HTTP Stream) 运行在 http://localhost:${PORT}/sse`);
} else {
// --- 本地模式 (STDIO) ---
// 在 stdio 模式下,我们将 CMS 运行在 3001 端口
const cmsPort = 3001;
serve({
fetch: cmsApp.fetch,
port: cmsPort,
}, (info) => {
console.error(`[CMS] 内容管理后台运行在 http://localhost:${info.port}`);
});
// 启动 MCP stdio
mcp.start({ transportType: "stdio" });
}