Node.js + TypeScript MCP 서버 구현: - 5개 도구: inspect_page, inspect_site, get_inspection, get_issues, get_history - 듀얼 트랜스포트: stdio (Claude Desktop) + Streamable HTTP (Docker/원격) - i18n 지원 (영어/한국어) - Docker 통합 (port 3100) + Nginx /mcp 프록시 - Smithery 레지스트리 배포 설정 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
import express from "express";
|
|
import { createServer } from "./server.js";
|
|
const TRANSPORT = process.env.TRANSPORT || "stdio";
|
|
const API_URL = process.env.API_URL || "http://localhost:8011";
|
|
const PORT = parseInt(process.env.PORT || "3100", 10);
|
|
const LANGUAGE = (process.env.LANGUAGE || "en");
|
|
async function main() {
|
|
const server = createServer(API_URL, LANGUAGE);
|
|
if (TRANSPORT === "http") {
|
|
await startHttp(server, PORT);
|
|
}
|
|
else {
|
|
await startStdio(server);
|
|
}
|
|
}
|
|
async function startStdio(server) {
|
|
const transport = new StdioServerTransport();
|
|
await server.connect(transport);
|
|
console.error(`[web-inspector-mcp] stdio mode, API: ${API_URL}`);
|
|
}
|
|
async function startHttp(server, port) {
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.post("/mcp", async (req, res) => {
|
|
const transport = new StreamableHTTPServerTransport({
|
|
sessionIdGenerator: undefined,
|
|
});
|
|
res.on("close", () => {
|
|
transport.close();
|
|
});
|
|
await server.connect(transport);
|
|
await transport.handleRequest(req, res, req.body);
|
|
});
|
|
app.get("/mcp", async (req, res) => {
|
|
res.writeHead(405).end(JSON.stringify({ error: "Use POST for MCP requests" }));
|
|
});
|
|
app.delete("/mcp", async (req, res) => {
|
|
res.writeHead(405).end(JSON.stringify({ error: "Session management not supported" }));
|
|
});
|
|
// Health check
|
|
app.get("/health", (_req, res) => {
|
|
res.json({ status: "ok", transport: "http", api_url: API_URL });
|
|
});
|
|
app.listen(port, () => {
|
|
console.error(`[web-inspector-mcp] HTTP mode on port ${port}, API: ${API_URL}`);
|
|
});
|
|
}
|
|
main().catch((err) => {
|
|
console.error("Fatal error:", err);
|
|
process.exit(1);
|
|
});
|
|
//# sourceMappingURL=index.js.map
|