Skip to main content
Glama
zqushair
by zqushair
tools.ts6.57 kB
import express, { Request, Response } from 'express'; import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import logger from '../utils/logger.js'; const router = express.Router(); /** * @swagger * /tools: * get: * summary: Get a list of available MCP tools * description: Returns a list of all available MCP tools with their descriptions and input schemas * tags: [Tools] * security: * - ApiKeyAuth: [] * responses: * 200: * description: A list of tools * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * data: * type: array * items: * type: object * properties: * name: * type: string * example: get_conversations * description: * type: string * example: Get a list of conversations from Frontapp * inputSchema: * type: object * 401: * description: Unauthorized * 500: * description: Server error */ router.get('/', async (req: Request, res: Response) => { try { req.logger?.info('Getting list of tools'); // In a real implementation, you would get this from the MCP server // For now, we'll return a placeholder const tools = [ { name: 'get_conversations', description: 'Get a list of conversations from Frontapp', inputSchema: { type: 'object', properties: { status: { type: 'string', enum: ['open', 'archived'], description: 'Filter conversations by status', }, limit: { type: 'number', description: 'Maximum number of conversations to return', }, }, }, }, { name: 'send_message', description: 'Send a message to a conversation', inputSchema: { type: 'object', properties: { conversation_id: { type: 'string', description: 'ID of the conversation', }, body: { type: 'string', description: 'Message body', }, tags: { type: 'array', items: { type: 'string', }, description: 'Tags to apply to the message', }, }, required: ['conversation_id', 'body'], }, }, ]; return res.status(200).json({ status: 'success', data: tools, }); } catch (error) { req.logger?.error('Error getting tools', { error }); return res.status(500).json({ status: 'error', message: 'Failed to get tools', }); } }); /** * @swagger * /tools/{name}: * post: * summary: Execute an MCP tool * description: Execute a specific MCP tool with the provided arguments * tags: [Tools] * security: * - ApiKeyAuth: [] * parameters: * - in: path * name: name * required: true * schema: * type: string * description: The name of the tool to execute * requestBody: * required: true * content: * application/json: * schema: * type: object * properties: * arguments: * type: object * description: Tool-specific arguments * responses: * 200: * description: Tool execution result * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * data: * type: object * 400: * description: Invalid request * 401: * description: Unauthorized * 404: * description: Tool not found * 500: * description: Server error */ router.post('/:name', async (req: Request, res: Response) => { try { const { name } = req.params; const { arguments: args } = req.body; req.logger?.info('Executing tool', { name, args }); // In a real implementation, you would execute the tool using the MCP server // For now, we'll return a placeholder if (name === 'get_conversations') { return res.status(200).json({ status: 'success', data: { conversations: [ { id: 'cnv_123', subject: 'Example conversation', status: 'open', assignee: { id: 'usr_456', name: 'John Doe', }, tags: ['support', 'priority'], }, ], }, }); } else if (name === 'send_message') { if (!args.conversation_id || !args.body) { return res.status(400).json({ status: 'error', message: 'Missing required arguments: conversation_id and body', }); } return res.status(200).json({ status: 'success', data: { message: { id: 'msg_789', conversation_id: args.conversation_id, body: args.body, author: { id: 'usr_456', name: 'John Doe', }, created_at: new Date().toISOString(), }, }, }); } else { return res.status(404).json({ status: 'error', message: `Tool not found: ${name}`, }); } } catch (error) { req.logger?.error('Error executing tool', { error, params: req.params }); return res.status(500).json({ status: 'error', message: 'Failed to execute tool', }); } }); /** * Initialize the tools router with the MCP server * @param mcpServer The MCP server instance * @returns The Express router */ export function initToolsRouter(mcpServer: Server): express.Router { // In a real implementation, you would use the MCP server to handle tool requests // For now, we'll just return the router return router; } export default router;

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/zqushair/Frontapp-MCP'

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