tambahan
This commit is contained in:
@@ -2,16 +2,21 @@ import { Elysia } from "elysia";
|
||||
|
||||
export const MCPRoute = new Elysia()
|
||||
.get("/mcp/:sessionId", async ({ params, set }) => {
|
||||
set.headers["Content-Type"] = "text/event-stream; charset=utf-8";
|
||||
set.headers["Cache-Control"] = "no-cache";
|
||||
set.headers["Connection"] = "keep-alive";
|
||||
set.headers["Access-Control-Allow-Origin"] = "*";
|
||||
// Atur header SSE
|
||||
set.headers = {
|
||||
"Content-Type": "text/event-stream; charset=utf-8",
|
||||
"Cache-Control": "no-cache",
|
||||
Connection: "keep-alive",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
};
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
let interval: NodeJS.Timeout;
|
||||
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
// kirim pesan handshake awal
|
||||
// kirim handshake awal
|
||||
const initial = {
|
||||
jsonrpc: "2.0",
|
||||
id: null,
|
||||
@@ -27,13 +32,18 @@ export const MCPRoute = new Elysia()
|
||||
|
||||
controller.enqueue(encoder.encode(`data: ${JSON.stringify(initial)}\n\n`));
|
||||
|
||||
// jaga stream tetap hidup setiap 10 detik
|
||||
const interval = setInterval(() => {
|
||||
controller.enqueue(encoder.encode(`: ping\n\n`)); // komentar SSE
|
||||
// jaga stream tetap hidup
|
||||
interval = setInterval(() => {
|
||||
controller.enqueue(encoder.encode(`: ping ${Date.now()}\n\n`));
|
||||
}, 10000);
|
||||
|
||||
// ketika stream ditutup
|
||||
controller.enqueue(encoder.encode(`: stream ready\n\n`));
|
||||
// kirim ready event
|
||||
controller.enqueue(encoder.encode(`event: ready\ndata: "stream ready"\n\n`));
|
||||
},
|
||||
|
||||
cancel() {
|
||||
clearInterval(interval);
|
||||
console.log(`SSE connection ${params.sessionId} closed by client`);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -52,7 +62,8 @@ export const MCPRoute = new Elysia()
|
||||
tools: [
|
||||
{
|
||||
name: "pengajuan-pembuatan-ktp",
|
||||
description: "untuk melakukan pengajuan pembuatan ktp\nmembutuhkan :\n- jenis\n- name\n- deskripsi",
|
||||
description:
|
||||
"untuk melakukan pengajuan pembuatan ktp\nmembutuhkan :\n- jenis\n- name\n- deskripsi",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
|
||||
Reference in New Issue
Block a user