tambahan
This commit is contained in:
@@ -1,86 +1,40 @@
|
|||||||
import { Elysia } from "elysia";
|
import { Elysia } from "elysia";
|
||||||
|
|
||||||
export const MCPRoute = new Elysia({
|
const tools = [
|
||||||
prefix: "/mcp",
|
|
||||||
tags: ["mcp"],
|
|
||||||
})
|
|
||||||
// ✅ GET /mcp → Harus balikan format MCP metadata + tools (tanpa stream)
|
|
||||||
.get("/", ({ set }) => {
|
|
||||||
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
|
||||||
|
|
||||||
return {
|
|
||||||
protocol: "2024-11-05",
|
|
||||||
capabilities: {
|
|
||||||
"tools/list": true,
|
|
||||||
"tools/call": true,
|
|
||||||
},
|
|
||||||
tools: [
|
|
||||||
{
|
{
|
||||||
name: "sayHello",
|
name: "pengajuan-pembuatan-ktp",
|
||||||
description: "Greets a user and returns a message",
|
value: "pengajuan-pembuatan-ktp",
|
||||||
|
description: "untuk melakukan pengajuan pembuatan ktp\nmembutuhkan :\n- jenis\n- name\n- deskripsi",
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: { JSON: {} },
|
||||||
name: { type: "string", description: "Name of the person" },
|
required: ["JSON"],
|
||||||
},
|
additionalProperties: true,
|
||||||
required: ["name"],
|
$schema: "http://json-schema.org/draft-07/schema#"
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
})
|
|
||||||
|
|
||||||
// ✅ GET /mcp/tools/list → Untuk eksplisit list tool
|
|
||||||
.get("/tools/list", ({ set }) => {
|
|
||||||
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
|
||||||
return {
|
|
||||||
tools: [
|
|
||||||
{
|
|
||||||
name: "sayHello",
|
|
||||||
description: "Greets a user",
|
|
||||||
inputSchema: {
|
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
name: { type: "string" },
|
|
||||||
},
|
|
||||||
required: ["name"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
})
|
|
||||||
|
|
||||||
// ✅ GET /mcp/tools/call?name=sayHello&name=Malik → streaming output
|
|
||||||
.get("/tools/call", ({ set, query }) => {
|
|
||||||
const toolName = query.name ?? "";
|
|
||||||
const user = query.user ?? "User";
|
|
||||||
|
|
||||||
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
|
||||||
set.headers["Cache-Control"] = "no-cache";
|
|
||||||
set.headers["Connection"] = "keep-alive";
|
|
||||||
set.headers["Transfer-Encoding"] = "chunked";
|
|
||||||
|
|
||||||
const stream = new ReadableStream({
|
|
||||||
async start(controller) {
|
|
||||||
controller.enqueue(":\n\n"); // Heartbeat
|
|
||||||
|
|
||||||
if (toolName === "sayHello") {
|
|
||||||
controller.enqueue(JSON.stringify({ status: "processing" }) + "\n");
|
|
||||||
await Bun.sleep(500);
|
|
||||||
controller.enqueue(
|
|
||||||
JSON.stringify({ result: `Hello ${user}! 👋` }) + "\n"
|
|
||||||
);
|
|
||||||
controller.close();
|
|
||||||
} else {
|
|
||||||
controller.enqueue(
|
|
||||||
JSON.stringify({ error: `Unknown tool: ${toolName}` }) + "\n"
|
|
||||||
);
|
|
||||||
controller.close();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
name: "list-layanan-desa-darmasaba",
|
||||||
|
value: "list-layanan-desa-darmasaba",
|
||||||
|
description: "mendapatkan list layanan desa darmasaba",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {},
|
||||||
|
additionalProperties: true,
|
||||||
|
$schema: "http://json-schema.org/draft-07/schema#"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return new Response(stream);
|
export const MCPRoute = new Elysia({ prefix: "/mcp" })
|
||||||
});
|
.post("/", async ({ body, set }) => {
|
||||||
|
set.headers["Content-Type"] = "application/json; charset=utf-8";
|
||||||
|
|
||||||
export default MCPRoute;
|
const { methodName } = body as { methodName: string };
|
||||||
|
|
||||||
|
if (methodName === "getTools") {
|
||||||
|
return { data: tools }; // ✅ sesuai format yang n8n minta
|
||||||
|
}
|
||||||
|
|
||||||
|
return { error: "Unsupported method" };
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user