This commit is contained in:
bipproduction
2025-10-26 20:52:38 +08:00
parent f1e3d42c22
commit 92ca73006a

View File

@@ -1,22 +1,26 @@
import Elysia from "elysia";
import { t } from "elysia";
const MCPRoute = new Elysia({
prefix: "mcp",
tags: ["mcp"],
export const MCPRoute = new Elysia({
prefix: "/mcp-server",
tags: ["mcp-server"],
})
.post("/tools/hello", ({ body }) => {
.post("/mcp", ({ body }) => {
const { id, method, params } = body;
// ==== TOOLS EXECUTION ====
if (method === "tools/sayHello") {
return {
jsonrpc: "2.0",
id,
result: { message: `Hello from Bun, ${params?.name}` },
result: {
message: `Hello from MCP Server`,
},
};
}
// ==== LIST ALL TOOLS ====
if (method === "tools/list") {
return {
jsonrpc: "2.0",
@@ -24,29 +28,40 @@ const MCPRoute = new Elysia({
result: [
{
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 {
jsonrpc: "2.0",
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({
jsonrpc: t.Optional(t.String()),
method: t.String(),
params: t.Object({
name: t.String(),
}),
id: t.Number(),
params: t.Optional(t.Record(t.String(), t.Any())),
id: t.Optional(t.Union([t.String(), t.Number()])),
}),
detail: {
summary: "hello",
description: "hello world",
}
})
summary: "MCP Server Endpoint",
description: "Handle MCP JSON-RPC requests for tools and discovery.",
},
});
export default MCPRoute
export default MCPRoute;