Skip to main content
Glama
tuskermanshu

Swagger MCP Server

by tuskermanshu

template-delete

Remove custom templates from the Swagger MCP Server to manage generated TypeScript types and API client code.

Instructions

Delete custom template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesTemplate ID

Implementation Reference

  • Registers the 'template-delete' tool on the MCP server, specifying the tool name, description, input schema (template ID), and references the handler method.
    // 注册删除模板工具 server.tool( TEMPLATE_DELETE_TOOL_NAME, TEMPLATE_DELETE_TOOL_DESCRIPTION, { id: z.string().describe('Template ID') }, async (params) => { return await this.deleteTemplate(params); } );
  • The main handler logic for the 'template-delete' tool, which calls the template manager's delete method and formats success/error responses as MCP content.
    * 删除模板 */ private async deleteTemplate(params: { id: string }): Promise<any> { try { const success = await this.templateManager.deleteCustomTemplate(params.id); if (!success) { return { content: [ { type: 'text' as const, text: JSON.stringify({ success: false, error: `Failed to delete template with ID: ${params.id}. It may be a built-in template or not exist.` }, null, 2) } ] }; } return { content: [ { type: 'text' as const, text: JSON.stringify({ success: true, message: `Template with ID: ${params.id} has been deleted.` }, null, 2) } ] }; } catch (error) { console.error('[TemplateManagerTool] 删除模板失败:', error); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }, null, 2) } ] }; } }
  • Core helper method in TemplateManager class that performs the actual deletion of a custom template: removes file, updates in-memory list, and saves config.
    /** * 删除自定义模板 */ async deleteCustomTemplate(id: string): Promise<boolean> { // 确保已初始化 if (!this.initialized) { await this.initialize(); } try { // 获取模板 const template = this.getTemplate(id); // 检查是否是内置模板或不存在 if (!template) { return false; } if (template.isBuiltIn) { throw new Error(`Cannot delete built-in template: ${id}`); } // 删除模板文件 const templatePath = path.join(CUSTOM_TEMPLATES_DIR, template.path!); await fs.unlink(templatePath); // 从内存中移除 this.customTemplates = this.customTemplates.filter(t => t.id !== id); // 更新配置文件 await this.updateCustomTemplatesConfig(); return true; } catch (error) { console.error('删除自定义模板失败:', error); return false; } }

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/tuskermanshu/swagger-mcp-server'

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