Skip to main content
Glama
tuskermanshu

Swagger MCP Server

by tuskermanshu

template-delete

Remove custom templates by specifying the template ID in the Swagger MCP Server to ensure clean API client code generation.

Instructions

Delete custom template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesTemplate ID

Implementation Reference

  • Handler function that executes the 'template-delete' tool logic. It calls the TemplateManager's deleteCustomTemplate method, handles success/error cases, and returns formatted MCP response.
    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) } ] }; } }
  • Registers the 'template-delete' tool on the MCP server within TemplateManagerTool class, including name, description, Zod input schema, and handler.
    server.tool( TEMPLATE_DELETE_TOOL_NAME, TEMPLATE_DELETE_TOOL_DESCRIPTION, { id: z.string().describe('Template ID') }, async (params) => { return await this.deleteTemplate(params); } );
  • Zod schema definition for the 'template-delete' tool input: requires a string 'id' for the template ID.
    id: z.string().describe('Template ID')
  • Supporting method in TemplateManager that performs the actual deletion: removes template file from disk, filters from customTemplates array, and updates JSON 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; } }
  • src/index.ts:64-64 (registration)
    Top-level registration of TemplateManagerTool on the main MCP server in index.ts, which in turn registers the 'template-delete' tool.
    new TemplateManagerTool().register(server);

Other Tools

Related Tools

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