This commit is contained in:
bipproduction
2025-10-27 02:37:51 +08:00
parent b8c1956f40
commit e33e7a2a87

View File

@@ -1,42 +1,48 @@
import { Elysia } from "elysia";
const tools = [
{
name: "pengajuan-pembuatan-ktp",
value: "pengajuan-pembuatan-ktp",
description: "untuk melakukan pengajuan pembuatan ktp\nmembutuhkan :\n- jenis\n- name\n- deskripsi",
inputSchema: {
type: "object",
properties: { JSON: {} },
required: ["JSON"],
additionalProperties: true,
$schema: "http://json-schema.org/draft-07/schema#"
}
},
{
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#"
}
}
];
const MCPRoute = new Elysia()
.post("/mcp", async ({ body, set }) => {
set.headers["Content-Type"] = "application/json; charset=utf-8";
.get("/mcp", ({ set }) => {
set.headers["Content-Type"] = "application/json; charset=utf-8";
return {
jsonrpc: "2.0",
id: null,
result: {
protocol: "2024-11-05",
capabilities: {
"tools/list": true,
"tools/call": true,
},
status: "MCP Server Ready",
},
};
})
.post("/mcp", async ({ body, set }) => {
set.headers["Content-Type"] = "application/json; charset=utf-8";
const { methodName } = body as { methodName: string };
const { id, method, params } = body as { id: string; method: string; params: any };
if (methodName === "getTools") {
return { data: tools }; // ✅ sesuai format yang n8n minta
}
if (method === "getTools") {
return {
jsonrpc: "2.0",
id,
result: {
tools: [
{ name: "sayHello", description: "Returns a greeting" },
{ name: "getTime", description: "Current server time" },
],
},
};
}
return { error: "Unsupported method" };
});
// Default jika method salah
return {
jsonrpc: "2.0",
id,
error: {
code: -32601,
message: `Method ${method} not found`,
},
};
});
export default MCPRoute;