tambahan
This commit is contained in:
@@ -1,22 +1,26 @@
|
|||||||
import Elysia from "elysia";
|
import Elysia from "elysia";
|
||||||
import { t } from "elysia";
|
import { t } from "elysia";
|
||||||
|
|
||||||
|
export const MCPRoute = new Elysia({
|
||||||
const MCPRoute = new Elysia({
|
prefix: "/mcp-server",
|
||||||
prefix: "mcp",
|
tags: ["mcp-server"],
|
||||||
tags: ["mcp"],
|
|
||||||
})
|
})
|
||||||
.post("/tools/hello", ({ body }) => {
|
.post("/mcp", ({ body }) => {
|
||||||
const { id, method, params } = body;
|
const { id, method, params } = body;
|
||||||
|
|
||||||
|
// ==== TOOLS EXECUTION ====
|
||||||
if (method === "tools/sayHello") {
|
if (method === "tools/sayHello") {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
result: { message: `Hello from Bun, ${params?.name}` },
|
result: {
|
||||||
|
message: `Hello from MCP Server`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==== LIST ALL TOOLS ====
|
||||||
if (method === "tools/list") {
|
if (method === "tools/list") {
|
||||||
return {
|
return {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
@@ -24,29 +28,40 @@ const MCPRoute = new Elysia({
|
|||||||
result: [
|
result: [
|
||||||
{
|
{
|
||||||
name: "sayHello",
|
name: "sayHello",
|
||||||
description: "Greets a user",
|
description: "Greets a user with a name",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
name: { type: "string" },
|
||||||
|
},
|
||||||
|
required: ["name"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==== IF METHOD NOT FOUND ====
|
||||||
return {
|
return {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
error: { code: -32601, message: "Method not found" },
|
error: {
|
||||||
|
code: -32601,
|
||||||
|
message: `Method '${method}' not found`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}, {
|
}, {
|
||||||
|
// ✅ Body JSON-RPC 2.0 schema (params & id bisa optional)
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
|
jsonrpc: t.Optional(t.String()),
|
||||||
method: t.String(),
|
method: t.String(),
|
||||||
params: t.Object({
|
params: t.Optional(t.Record(t.String(), t.Any())),
|
||||||
name: t.String(),
|
id: t.Optional(t.Union([t.String(), t.Number()])),
|
||||||
}),
|
|
||||||
id: t.Number(),
|
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "hello",
|
summary: "MCP Server Endpoint",
|
||||||
description: "hello world",
|
description: "Handle MCP JSON-RPC requests for tools and discovery.",
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export default MCPRoute
|
export default MCPRoute;
|
||||||
|
|||||||
Reference in New Issue
Block a user