This commit is contained in:
bipproduction
2025-10-27 02:37:05 +08:00
parent 3cc6f9f3ca
commit b8c1956f40

View File

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