Skip to main content
Glama
route.ts1.4 kB
export const runtime = "nodejs"; export const dynamic = "force-dynamic"; import path from "path"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; declare global { // eslint-disable-next-line no-var var __mcpClient: Client | undefined; } async function getClient(): Promise<Client> { if (globalThis.__mcpClient) return globalThis.__mcpClient; const projectRoot = path.resolve(process.cwd(), ".."); const transport = new StdioClientTransport({ command: "node", args: ["dist/index.js"], cwd: projectRoot, env: process.env as Record<string, string>, }); const client = new Client({ name: "line-bot-ui-next", version: "0.1.0" }); await client.connect(transport); globalThis.__mcpClient = client; return client; } export async function POST(req: Request) { try { const client = await getClient(); const { name, args } = (await req.json()) as { name: string; args?: any }; const result = await client.callTool({ name, arguments: args || {} }); return new Response(JSON.stringify(result), { headers: { "Content-Type": "application/json" }, }); } catch (e: any) { return new Response(JSON.stringify({ error: e?.message || String(e) }), { status: 500, headers: { "Content-Type": "application/json" }, }); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tndfame/mcp_management'

If you have feedback or need assistance with the MCP directory API, please join our Discord server