tambahannnya
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { Elysia } from "elysia";
|
import { Elysia } from "elysia";
|
||||||
import { getMcpTools } from "../lib/mcp_tool_convert";
|
import { getMcpTools } from "../lib/mcp_tool_convert";
|
||||||
import _ from "lodash";
|
|
||||||
|
|
||||||
var tools = [] as any[];
|
var tools = [] as any[];
|
||||||
const OPENAPI_URL = process.env.BUN_PUBLIC_BASE_URL + "/docs/json";
|
const OPENAPI_URL = process.env.BUN_PUBLIC_BASE_URL+"/docs/json";
|
||||||
const FILTER_TAG = "test";
|
const FILTER_TAG = "test";
|
||||||
|
|
||||||
if (!process.env.BUN_PUBLIC_BASE_URL) {
|
if (!process.env.BUN_PUBLIC_BASE_URL) {
|
||||||
@@ -119,16 +118,16 @@ async function handleMCPRequestAsync(
|
|||||||
const baseUrl =
|
const baseUrl =
|
||||||
process.env.BUN_PUBLIC_BASE_URL || "http://localhost:3000";
|
process.env.BUN_PUBLIC_BASE_URL || "http://localhost:3000";
|
||||||
const result = await executeTool(tool, params?.arguments || {}, baseUrl);
|
const result = await executeTool(tool, params?.arguments || {}, baseUrl);
|
||||||
const data = result.data.data;
|
|
||||||
const isObject = _.isObject(data);
|
|
||||||
return {
|
return {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
id,
|
id,
|
||||||
result: {
|
result: {
|
||||||
content: [
|
content: [
|
||||||
isObject
|
{
|
||||||
? { type: "json", data: data }
|
type: "text",
|
||||||
: { type: "text", text: String(data) },
|
text: JSON.stringify(result, null, 2),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -195,7 +194,7 @@ export const MCPRoute = new Elysia({
|
|||||||
// Tools list (debug)
|
// Tools list (debug)
|
||||||
.get("/mcp/tools", async ({ set }) => {
|
.get("/mcp/tools", async ({ set }) => {
|
||||||
if (!tools.length) {
|
if (!tools.length) {
|
||||||
|
|
||||||
tools = await getMcpTools(OPENAPI_URL, FILTER_TAG);
|
tools = await getMcpTools(OPENAPI_URL, FILTER_TAG);
|
||||||
}
|
}
|
||||||
set.headers["Access-Control-Allow-Origin"] = "*";
|
set.headers["Access-Control-Allow-Origin"] = "*";
|
||||||
|
|||||||
Reference in New Issue
Block a user