tambahan
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
|
||||
export const MCPRoute = new Elysia({
|
||||
prefix: "/mcp-server", // ✅ Sesuaikan dengan endpoint n8n
|
||||
prefix: "/mcp-server",
|
||||
tags: ["mcp-server"],
|
||||
})
|
||||
.post("/mcp", ({ body, set }) => {
|
||||
const { id, method, params } = body as any;
|
||||
|
||||
set.headers["Content-Type"] = "application/json";
|
||||
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
||||
set.headers["Transfer-Encoding"] = "chunked";
|
||||
set.headers["Connection"] = "keep-alive";
|
||||
|
||||
// ✅ Streaming Response
|
||||
const stream = new ReadableStream({
|
||||
async start(controller) {
|
||||
// tools.list → kirim daftar tools
|
||||
// tools/list
|
||||
if (method === "tools/list") {
|
||||
controller.enqueue(
|
||||
JSON.stringify({
|
||||
@@ -31,40 +32,46 @@ export const MCPRoute = new Elysia({
|
||||
],
|
||||
}) + "\n"
|
||||
);
|
||||
// ❌ Jangan tutup langsung, beri delay agar n8n sempat membaca
|
||||
await Bun.sleep(200);
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// tools.sayHello → streaming bertahap
|
||||
else if (method === "tools/sayHello") {
|
||||
// tools/sayHello → streaming progress
|
||||
if (method === "tools/sayHello") {
|
||||
controller.enqueue(
|
||||
JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: { message: "Processing..." },
|
||||
result: { status: "Processing..." },
|
||||
}) + "\n"
|
||||
);
|
||||
await Bun.sleep(500);
|
||||
|
||||
controller.enqueue(
|
||||
JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: { message: `Hello ${params?.name || ""}` },
|
||||
result: { message: `Hello ${params?.name || "User"}` },
|
||||
}) + "\n"
|
||||
);
|
||||
await Bun.sleep(200);
|
||||
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Method tidak ditemukan
|
||||
else {
|
||||
controller.enqueue(
|
||||
JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: { code: -32601, message: `Method ${method} not found` },
|
||||
}) + "\n"
|
||||
);
|
||||
controller.close();
|
||||
}
|
||||
// Method tidak dikenal
|
||||
controller.enqueue(
|
||||
JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: { code: -32601, message: `Method ${method} not found` },
|
||||
}) + "\n"
|
||||
);
|
||||
await Bun.sleep(200);
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
2
x.sh
2
x.sh
@@ -1,5 +1,5 @@
|
||||
TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJob3N0Iiwic3ViIjoiY21neXI4MjR3MDAwMHBkemhwdjIxZGFzZCIsInBheWxvYWQiOiJ7XCJuYW1lXCI6XCJwZXJjb2JhYW5cIixcImRlc2NyaXB0aW9uXCI6XCJ1bnR1ayBwZXJjb2JhYW5cIixcImV4cGlyZWRBdFwiOlwiMjAzMS0xMC0yMFwifSIsImV4cCI6MTk1MDIyMDgwMCwiaWF0IjoxNzYwOTQyNTcwfQ.X4Y4MJ4aIohT65oJjHCaf2d6e8afnroXu3Hz-jH0WGM
|
||||
curl https://cld-dkr-prod-jenna-mcp.wibudev.com/api/mcp-server/mcp \
|
||||
curl https://cld-dkr-prod-jenna-mcp.wibudev.com/mcp-server/mcp \
|
||||
--request POST \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'Authorization: Bearer $TOKEN' \
|
||||
|
||||
Reference in New Issue
Block a user