tambahan
This commit is contained in:
@@ -1,88 +1,106 @@
|
|||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
|
||||||
export const MCPRoute = new Elysia({
|
export const MCPRoute = new Elysia({
|
||||||
prefix: "/mcp-server",
|
prefix: "/mcp-server",
|
||||||
tags: ["mcp-server"],
|
tags: ["mcp-server"],
|
||||||
})
|
})
|
||||||
.post("/mcp", ({ body, set }) => {
|
.post("/mcp", ({ body, set }) => {
|
||||||
const { id, method, params } = body as any;
|
const { id, method, params } = body as any;
|
||||||
|
|
||||||
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
||||||
set.headers["Transfer-Encoding"] = "chunked";
|
set.headers["Transfer-Encoding"] = "chunked";
|
||||||
set.headers["Connection"] = "keep-alive";
|
set.headers["Connection"] = "keep-alive";
|
||||||
|
|
||||||
// ✅ Streaming Response
|
// ✅ Streaming Response
|
||||||
const stream = new ReadableStream({
|
const stream = new ReadableStream({
|
||||||
async start(controller) {
|
async start(controller) {
|
||||||
// tools/list
|
// tools/list
|
||||||
if (method === "tools/list") {
|
if (method === "tools/list") {
|
||||||
controller.enqueue(
|
controller.enqueue(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
result: [
|
result: [
|
||||||
{
|
{
|
||||||
name: "sayHello",
|
name: "sayHello",
|
||||||
description: "Greets user",
|
description: "Greets user",
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: { name: { type: "string" } },
|
properties: { name: { type: "string" } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}) + "\n"
|
}) + "\n"
|
||||||
);
|
);
|
||||||
// ❌ Jangan tutup langsung, beri delay agar n8n sempat membaca
|
// ❌ Jangan tutup langsung, beri delay agar n8n sempat membaca
|
||||||
await Bun.sleep(200);
|
await Bun.sleep(200);
|
||||||
controller.close();
|
controller.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tools/sayHello → streaming progress
|
// tools/sayHello → streaming progress
|
||||||
if (method === "tools/sayHello") {
|
if (method === "tools/sayHello") {
|
||||||
controller.enqueue(
|
controller.enqueue(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
result: { status: "Processing..." },
|
result: { status: "Processing..." },
|
||||||
}) + "\n"
|
}) + "\n"
|
||||||
);
|
);
|
||||||
await Bun.sleep(500);
|
await Bun.sleep(500);
|
||||||
|
|
||||||
controller.enqueue(
|
controller.enqueue(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
result: { message: `Hello ${params?.name || "User"}` },
|
result: { message: `Hello ${params?.name || "User"}` },
|
||||||
}) + "\n"
|
}) + "\n"
|
||||||
);
|
);
|
||||||
await Bun.sleep(200);
|
await Bun.sleep(200);
|
||||||
|
|
||||||
controller.close();
|
controller.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method tidak dikenal
|
if (method === "mcp/version") {
|
||||||
controller.enqueue(
|
controller.enqueue(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
error: { code: -32601, message: `Method ${method} not found` },
|
result: {
|
||||||
}) + "\n"
|
protocol: "2024-11-05", // versi MCP baru
|
||||||
);
|
capabilities: {
|
||||||
await Bun.sleep(200);
|
"tools/list": true,
|
||||||
controller.close();
|
"tools/call": true,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
}) + "\n"
|
||||||
|
);
|
||||||
|
controller.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(stream);
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
jsonrpc: t.Optional(t.String()),
|
||||||
|
method: t.String(),
|
||||||
|
params: t.Optional(t.Record(t.String(), t.Any())),
|
||||||
|
id: t.Optional(t.Union([t.String(), t.Number()])),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Response(stream);
|
|
||||||
}, {
|
|
||||||
body: t.Object({
|
|
||||||
jsonrpc: t.Optional(t.String()),
|
|
||||||
method: t.String(),
|
|
||||||
params: t.Optional(t.Record(t.String(), t.Any())),
|
|
||||||
id: t.Optional(t.Union([t.String(), t.Number()])),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default MCPRoute;
|
export default MCPRoute;
|
||||||
|
|||||||
16
x.sh
16
x.sh
@@ -1,13 +1,3 @@
|
|||||||
TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJob3N0Iiwic3ViIjoiY21neXI4MjR3MDAwMHBkemhwdjIxZGFzZCIsInBheWxvYWQiOiJ7XCJuYW1lXCI6XCJwZXJjb2JhYW5cIixcImRlc2NyaXB0aW9uXCI6XCJ1bnR1ayBwZXJjb2JhYW5cIixcImV4cGlyZWRBdFwiOlwiMjAzMS0xMC0yMFwifSIsImV4cCI6MTk1MDIyMDgwMCwiaWF0IjoxNzYwOTQyNTcwfQ.X4Y4MJ4aIohT65oJjHCaf2d6e8afnroXu3Hz-jH0WGM
|
curl -N -X POST https://cld-dkr-prod-jenna-mcp.wibudev.com/mcp-server/mcp \
|
||||||
curl https://cld-dkr-prod-jenna-mcp.wibudev.com/mcp-server/mcp \
|
-H "Content-Type: application/json" \
|
||||||
--request POST \
|
-d '{"id":1,"method":"tools/list"}'
|
||||||
--header 'Content-Type: application/json' \
|
|
||||||
--header 'Authorization: Bearer $TOKEN' \
|
|
||||||
--data '{
|
|
||||||
"jsonrpc": "",
|
|
||||||
"method": "",
|
|
||||||
"params": {
|
|
||||||
"^(.*)$": null
|
|
||||||
},
|
|
||||||
"id": ""
|
|
||||||
}'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user