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