Skip to main content
Glama
tuskermanshu

Swagger MCP Server

by tuskermanshu

template-get

Retrieve specific template content by ID to generate TypeScript types and API client code from Swagger/OpenAPI documents.

Instructions

Get specific template content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesTemplate ID

Implementation Reference

  • The main handler function for the 'template-get' tool. It fetches the template by ID using TemplateManager and returns a standardized JSON response with success/error status.
    private async getTemplate(params: { id: string }): Promise<any> {
      try {
        const template = this.templateManager.getTemplate(params.id);
        
        if (!template) {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  success: false,
                  error: `Template not found with ID: ${params.id}`
                }, null, 2)
              }
            ]
          };
        }
        
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                success: true,
                template
              }, 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-get' tool with the MCP server, including name, description, input schema, and handler reference.
    // 注册获取单个模板工具
    server.tool(
      TEMPLATE_GET_TOOL_NAME,
      TEMPLATE_GET_TOOL_DESCRIPTION,
      {
        id: z.string().describe('Template ID'),
      },
      async (params) => {
        return await this.getTemplate(params);
      }
    );
  • Zod input schema defining the required 'id' parameter as a string.
    {
      id: z.string().describe('Template ID'),
    },
  • Constants defining the tool name and description used in registration.
    const TEMPLATE_GET_TOOL_NAME = 'template-get';
    const TEMPLATE_GET_TOOL_DESCRIPTION = 'Get specific template content';
  • Underlying helper method in TemplateManager that finds and returns a template by ID from loaded templates.
    getTemplate(id: string): Template | undefined {
      return this.getAllTemplates().find(template => template.id === id);
    }

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