This commit is contained in:
bipproduction
2025-10-27 02:23:30 +08:00
parent 0ee273cd45
commit 7e3821f7e3

View File

@@ -1,9 +1,9 @@
// src/routes/mcp_route.ts
import { Elysia } from "elysia";
import { Elysia, t } from "elysia";
const MCPRoute = new Elysia({ prefix: "/mcp" })
.post("/", async ({ body, set }) => {
const { id, method } = body as { id: string; method: string };
const { id = "123", method = "getTools" } = body;
// Header wajib untuk MCP
set.status = 200;
@@ -19,7 +19,7 @@ const MCPRoute = new Elysia({ prefix: "/mcp" })
if (method === "getTools") {
const firstChunk = JSON.stringify({
jsonrpc: "2.0",
id,
id: id || "123",
result: {
data: [
{
@@ -42,7 +42,7 @@ const MCPRoute = new Elysia({ prefix: "/mcp" })
} else {
controller.enqueue(encoder.encode(JSON.stringify({
jsonrpc: "2.0",
id,
id: id || "123",
error: { code: -32601, message: "Method not found" }
})));
controller.close();
@@ -51,6 +51,8 @@ const MCPRoute = new Elysia({ prefix: "/mcp" })
});
return stream;
},{
body: t.Any()
});
export default MCPRoute;