Spaces:
Sleeping
Sleeping
Backup Agent commited on
Commit ·
51e4479
1
Parent(s): 02c5caa
Add /api/mcp/call endpoint
Browse files
index.js
CHANGED
|
@@ -267,6 +267,32 @@ app.post("/api/mcp/register", express.json(), async (req, res) => {
|
|
| 267 |
}
|
| 268 |
});
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
app.post("/api/research", express.json(), async (req, res) => {
|
| 271 |
const { query } = req.body;
|
| 272 |
console.log(`[Library] Received research request for: '${query}'`);
|
|
|
|
| 267 |
}
|
| 268 |
});
|
| 269 |
|
| 270 |
+
app.post("/api/mcp/call", express.json(), async (req, res) => {
|
| 271 |
+
const { serverName, toolName, arguments: toolArgs } = req.body;
|
| 272 |
+
if (!serverName || !toolName) {
|
| 273 |
+
return res.status(400).json({ error: "Missing serverName or toolName payload." });
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
try {
|
| 277 |
+
// Ensure active servers are connected
|
| 278 |
+
await loadAndConnectServers();
|
| 279 |
+
|
| 280 |
+
const entry = activeClients.get(serverName);
|
| 281 |
+
if (!entry) {
|
| 282 |
+
return res.status(404).json({ error: `MCP server '${serverName}' is not active or connected.` });
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
const result = await entry.client.callTool({
|
| 286 |
+
name: toolName,
|
| 287 |
+
arguments: toolArgs || {}
|
| 288 |
+
});
|
| 289 |
+
return res.json(result);
|
| 290 |
+
} catch (e) {
|
| 291 |
+
return res.status(500).json({ error: e.message });
|
| 292 |
+
}
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
|
| 296 |
app.post("/api/research", express.json(), async (req, res) => {
|
| 297 |
const { query } = req.body;
|
| 298 |
console.log(`[Library] Received research request for: '${query}'`);
|