Skip to main content
Glama
tuskermanshu

Swagger MCP Server

by tuskermanshu

template-save

Save or update code generation templates for API clients, TypeScript types, and configuration files in the Swagger MCP Server.

Instructions

Save or update template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesTemplate ID
nameYesTemplate name
typeYesTemplate type
frameworkNoFramework type (only for API client and config file templates)
contentYesTemplate content
descriptionNoTemplate description

Implementation Reference

  • Registration of the 'template-save' MCP tool, including name, description, Zod input schema, and handler delegating to saveTemplate method.
    server.tool(
      TEMPLATE_SAVE_TOOL_NAME,
      TEMPLATE_SAVE_TOOL_DESCRIPTION,
      {
        id: z.string().describe('Template ID'),
        name: z.string().describe('Template name'),
        type: z.enum(['api-client', 'typescript-types', 'config-file']).describe('Template type'),
        framework: z.enum(['axios', 'fetch', 'react-query', 'swr', 'angular', 'vue']).optional().describe('Framework type (only for API client and config file templates)'),
        content: z.string().describe('Template content'),
        description: z.string().optional().describe('Template description')
      },
      async (params) => {
        return await this.saveTemplate(params);
      }
    );
  • Zod schema defining input parameters for the template-save tool: id, name, type, optional framework and description, and required content.
    {
      id: z.string().describe('Template ID'),
      name: z.string().describe('Template name'),
      type: z.enum(['api-client', 'typescript-types', 'config-file']).describe('Template type'),
      framework: z.enum(['axios', 'fetch', 'react-query', 'swr', 'angular', 'vue']).optional().describe('Framework type (only for API client and config file templates)'),
      content: z.string().describe('Template content'),
      description: z.string().optional().describe('Template description')
    },
  • Handler method called by the tool: constructs Template from input params, invokes TemplateManager.saveCustomTemplate, and returns formatted MCP response.
    private async saveTemplate(params: {
      id: string;
      name: string;
      type: string;
      framework?: string;
      content: string;
      description?: string;
    }): Promise<any> {
      try {
        const template = {
          id: params.id,
          name: params.name,
          type: params.type as TemplateType,
          framework: params.framework as FrameworkType | undefined,
          content: params.content,
          description: params.description
        };
        
        const result = await this.templateManager.saveCustomTemplate(template);
        
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                success: true,
                template: result
              }, 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 handler implementation in TemplateManager: generates file path, saves template content to disk, updates in-memory list and JSON config file.
    async saveCustomTemplate(template: Template): Promise<Template> {
      // 确保已初始化
      if (!this.initialized) {
        await this.initialize();
      }
      
      try {
        // 检查是否是内置模板
        const existingTemplate = this.getTemplate(template.id);
        if (existingTemplate?.isBuiltIn) {
          throw new Error(`Cannot override built-in template: ${template.id}`);
        }
        
        // 生成保存路径
        let relativePath: string;
        if (template.type === TemplateType.API_CLIENT) {
          relativePath = `api-client/${template.id}.tpl`;
        } else if (template.type === TemplateType.TYPESCRIPT_TYPES) {
          relativePath = `typescript-types/${template.id}.tpl`;
        } else if (template.type === TemplateType.CONFIG_FILE) {
          relativePath = `config/${template.id}.tpl`;
        } else {
          relativePath = `${template.id}.tpl`;
        }
        
        // 确保子目录存在
        const dirPath = path.join(CUSTOM_TEMPLATES_DIR, path.dirname(relativePath));
        await fs.mkdir(dirPath, { recursive: true });
        
        // 保存模板内容
        const templatePath = path.join(CUSTOM_TEMPLATES_DIR, relativePath);
        await fs.writeFile(templatePath, template.content || '');
        
        // 更新模板配置
        const newTemplate: Template = {
          id: template.id,
          name: template.name,
          type: template.type,
          framework: template.framework,
          path: relativePath,
          description: template.description,
          isBuiltIn: false
        };
        
        // 更新内存中的自定义模板
        const existingIndex = this.customTemplates.findIndex(t => t.id === template.id);
        if (existingIndex >= 0) {
          // 更新现有模板
          this.customTemplates[existingIndex] = {
            ...newTemplate,
            content: template.content
          };
        } else {
          // 添加新模板
          this.customTemplates.push({
            ...newTemplate,
            content: template.content
          });
        }
        
        // 更新配置文件
        await this.updateCustomTemplatesConfig();
        
        return {
          ...newTemplate,
          content: template.content
        };
      } catch (error) {
        console.error('保存自定义模板失败:', error);
        throw error;
      }
    }
  • Constants defining the tool name and description used in registration.
    const TEMPLATE_SAVE_TOOL_NAME = 'template-save';
    const TEMPLATE_SAVE_TOOL_DESCRIPTION = 'Save or update template';
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'save or update' which implies mutation, but doesn't disclose behavioral traits like required permissions, whether operations are idempotent, error handling, or side effects. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 extremely concise with just three words, front-loaded with the core action. There's zero waste or redundancy, making it easy to parse quickly, though this conciseness comes at the cost of detail.

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 mutation tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't cover return values, error cases, or behavioral nuances, leaving the agent with insufficient context to use the tool effectively beyond basic parameter passing.

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%, so the schema fully documents all 6 parameters. The description adds no meaning beyond what the schema provides—it doesn't explain parameter interactions (e.g., how 'id' determines save vs. update) or provide additional context. Baseline 3 is appropriate when the schema does all the work.

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

Purpose3/5

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

The description 'Save or update template' states the basic action (save/update) and resource (template), but it's vague about what constitutes saving vs. updating and doesn't distinguish this tool from its siblings like template-delete or template-get. It provides minimal differentiation beyond the tool name.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing ID for updates), compare to sibling tools like template-delete or template-get, or specify scenarios for saving versus updating. The description lacks any contextual usage instructions.

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