Skip to main content
Glama

create_resource_template

Generate template code for new MCP resources by specifying resource name, URI pattern, description, and output directory. Simplifies resource creation within the MCP Maker server framework.

Instructions

Generates template code for a new MCP resource

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
output_dirYes
resource_nameYes
resource_uri_patternYes

Implementation Reference

  • The main handler function that validates input, generates the resource file path, checks for existence, compiles a Handlebars template with derived variables, writes the file, and returns success/error details.
    export async function createResourceTemplate(
      options: ResourceTemplateOptions
    ): Promise<{ success: boolean; message: string; filePath?: string }> {
      try {
        // Validate options
        const validatedOptions = resourceTemplateSchema.parse(options);
    
        // Use the provided output directory (now required and absolute)
        const baseDir = validatedOptions.output_dir;
    
        // Ensure the resources directory exists
        const resourcesDir = path.join(baseDir, "src", "resources");
        await ensureDir(resourcesDir);
    
        // Generate the file path for the new resource
        const resourceFilename = `${validatedOptions.resource_name.replace(
          /-/g,
          "_"
        )}.ts`;
        const resourceFilePath = path.join(resourcesDir, resourceFilename);
    
        // Check if the file already exists
        const fileExists = await pathExists(resourceFilePath);
        if (fileExists) {
          return {
            success: false,
            message: `A resource with the name "${validatedOptions.resource_name}" already exists at ${resourceFilePath}`,
          };
        }
    
        // Generate the resource content using the template
        const resourceContent = await compileTemplate(
          getTemplatePath("resource.hbs"),
          {
            ...validatedOptions,
            // Additional template variables
            resource_camel_case: validatedOptions.resource_name
              .replace(/-/g, "_")
              .replace(/_([a-z])/g, (_, char) => char.toUpperCase()),
            resource_pascal_case: validatedOptions.resource_name
              .replace(/-/g, "_")
              .split("_")
              .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
              .join(""),
          }
        );
    
        // Write the resource file
        await writeFile(resourceFilePath, resourceContent);
    
        console.log(
          chalk.green(
            `Resource template generated successfully at: ${resourceFilePath}`
          )
        );
    
        return {
          success: true,
          message: `Resource template generated successfully at: ${resourceFilePath}`,
          filePath: resourceFilePath,
        };
      } catch (error: any) {
        console.error(chalk.red("Error creating resource template:"), error);
        return {
          success: false,
          message: `Error creating resource template: ${
            error.message || String(error)
          }`,
        };
      }
    }
  • Zod validation schema for tool inputs, enforcing snake_case for resource_name and absolute path for output_dir.
    export const resourceTemplateSchema = z.object({
      resource_name: z
        .string()
        .min(1)
        .refine((val) => /^[a-z0-9_-]+$/.test(val), {
          message:
            "Resource name must be in snake_case (lowercase with underscores)",
        }),
      resource_uri_pattern: z.string().min(1),
      description: z.string().min(1),
      output_dir: z.string().refine((val) => path.isAbsolute(val), {
        message: "output_dir must be an absolute path",
      }),
    });
  • src/server.ts:79-94 (registration)
    MCP server tool registration, including tool name, description, Zod input schema, and wrapper async handler that delegates to createResourceTemplate.
    server.tool(
      "create_resource_template",
      "Generates template code for a new MCP resource",
      {
        resource_name: z.string().min(1),
        resource_uri_pattern: z.string().min(1),
        description: z.string().min(1),
        output_dir: z.string(),
      },
      async (params: ResourceTemplateOptions) => {
        const result = await createResourceTemplate(params);
        return {
          content: [{ type: "text", text: result.message }],
        };
      }
    );
  • TypeScript interface defining the shape of options passed to the createResourceTemplate handler.
    export interface ResourceTemplateOptions {
      resource_name: string;
      resource_uri_pattern: string;
      description: string;
      /**
       * Absolute path to the directory where the resource should be generated
       */
      output_dir: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Generates' implies a write operation that creates files, it doesn't disclose important behavioral aspects: whether it overwrites existing files, what permissions are needed, what format the output takes, or whether it's idempotent. The description provides minimal behavioral context beyond the basic action.

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 - a single sentence that gets straight to the point with zero wasted words. It's front-loaded with the core action and doesn't include any unnecessary elaboration. For a tool that generates code templates, this level of brevity is appropriate if supplemented by good parameter documentation.

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?

For a tool with 4 required parameters, 0% schema description coverage, no annotations, and no output schema, the description is severely inadequate. It doesn't explain what the tool actually produces, what the parameters mean, or how the generated template should be used. The description leaves too many unanswered questions for effective tool invocation.

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

Parameters2/5

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

With 0% schema description coverage for all 4 required parameters, the description provides absolutely no information about what each parameter means or how they should be used. The description doesn't mention any of the parameters (resource_name, resource_uri_pattern, description, output_dir), leaving the agent with no semantic understanding of what values to provide.

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 clearly states the tool's purpose with a specific verb ('Generates') and resource ('template code for a new MCP resource'). It distinguishes from siblings like 'create_prompt_template' and 'create_tool_template' by specifying it's for resources, not prompts or tools. However, it doesn't fully differentiate from 'generate_mcp_boilerplate' which might serve a similar purpose.

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. With siblings like 'create_prompt_template', 'create_tool_template', and 'generate_mcp_boilerplate' that likely serve related template generation purposes, there's no indication of when this specific resource template tool is appropriate versus those other options.

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

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/CaptainCrouton89/mcp-maker'

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