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;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Delete' implies a destructive mutation, but the description doesn't specify whether deletion is permanent, reversible, requires specific permissions, or what happens on success/failure. This leaves critical behavioral traits undocumented.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient phrase ('Delete custom template') with zero wasted words. It's front-loaded and appropriately sized for a simple operation, earning full marks for conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a destructive mutation tool with no annotations and no output schema, the description is incomplete. It lacks critical context like behavioral traits (permanence, permissions), error handling, or what to expect after deletion. The description alone is insufficient for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'id' documented as 'Template ID' in the schema. The description adds no additional meaning about the parameter beyond what the schema provides, such as format examples or where to obtain the ID. The baseline of 3 is appropriate given the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Delete custom template' clearly states the action (delete) and the resource (custom template), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like template-get or template-list, but the verb 'delete' inherently differentiates it from read operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing template ID), when not to use it, or refer to sibling tools like template-get for verification before deletion.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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