tools.js•1.93 kB
import { getAllTools, getToolByName } from '../tools/index.js';
import { logger } from '../utils/logger.js';
export function setupToolsRoutes(app) {
// GET /tools - List all tools (summary only for performance)
app.get("/tools", async (req, res) => {
try {
const tools = getAllTools();
// Return lightweight summary
const summary = tools.map(tool => ({
name: tool.name,
description: tool.description
}));
res.json({
success: true,
tools: summary,
totalCount: tools.length
});
} catch (error) {
logger.error(`List tools error:`, error.message);
res.status(500).json({ success: false, error: error.message });
}
});
// GET /tools/:toolName - Get specific tool details
app.get("/tools/:toolName", async (req, res) => {
try {
const { toolName } = req.params;
const tool = getToolByName(toolName);
if (!tool) {
return res.status(404).json({
success: false,
error: `Tool '${toolName}' not found`
});
}
res.json({
success: true,
tool
});
} catch (error) {
logger.error(`Get tool error:`, error.message);
res.status(500).json({ success: false, error: error.message });
}
});
// GET /tools/:toolName/schema - Get only the schema
app.get("/tools/:toolName/schema", async (req, res) => {
try {
const { toolName } = req.params;
const tool = getToolByName(toolName);
if (!tool) {
return res.status(404).json({
success: false,
error: `Tool '${toolName}' not found`
});
}
res.json({
success: true,
schema: tool.inputSchema
});
} catch (error) {
logger.error(`Get tool schema error:`, error.message);
res.status(500).json({ success: false, error: error.message });
}
});
}