Skip to main content
Glama

buildReload_tool

Execute npm run build and reload tools to update MCP server tools without restarting the server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function implementing the tool: runs 'npm run build' in project root, reloads tools, handles success/error responses.
    export default async function (request: any) {
      try {
        //  执行编译命令
        const buildOutput = execSync('npm run build', {
          cwd: PROJECT_ROOT,  // 使用计算出的项目根目录
          encoding: 'utf-8',
          stdio: 'pipe',
          timeout: 300000  // 5分钟超时
        });
    
        // 阶段 2: 重新加载工具
        const handlers = await loadTools(true);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                build: {
                  success: true,
                  output: buildOutput,
                  directory: PROJECT_ROOT  // 返回实际使用的目录
                },
                reload: {
                  success: !!handlers,
                  tools: Object.keys(handlers).length
                }
              }, null, 2)
            }
          ]
        };
    
      } catch (error) {
        const errorInfo = {
          message: error instanceof Error ? error.message : String(error),
          stack: error instanceof Error ? error.stack : undefined,
          directory: PROJECT_ROOT,  // 包含目录信息
          system: {
            platform: process.platform,
            versions: process.versions
          }
        };
    
        // 如果是执行命令错误,添加额外信息
        if (error instanceof Error && 'code' in error) {
          Object.assign(errorInfo, {
            exitCode: error.code,
            stdout: (error as any).stdout,
            stderr: (error as any).stderr
          });
        }
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              error: "BuildReload_FAILED",
              details: errorInfo
            }, null, 2)
          }],
          isError: true
        };
      }
    }
  • Input schema for the tool: no parameters required.
    export const schema = {
      name: "buildReload_tool",
      description: "Execute 'npm run build' and reload tools",
      type: "object",
      properties: {},
      required: []
    };
  • Dynamic loading and registration of all tools (including buildReload_tool) from src/tools directory by importing schema, handler (default), and destroy functions.
    for (const file of toolFiles) {
      const toolPath = path.join(toolsDir, file);
      try {
        // 如果是重新加载,清除模块缓存
        if (reload) clearModuleCache(toolPath);
    
        // 导入模块,重新加载时添加时间戳防止缓存
        const importPath = 'file://' + toolPath + (reload ? `?update=${Date.now()}` : '');
        const { default: tool, schema, destroy } = await import(importPath);
        const toolName = path.parse(toolPath).name;
    
        // 注册工具
        tools.push({
          name: toolName,
          description: tool.description,
          inputSchema: schema,
          destroy: destroy
        });
    
        // 注册处理函数
        handlers[toolName] = async (request: ToolRequest) => { return await tool(request); };
      } catch (error) {
        console.error(`Failed to ${reload ? 'reload' : 'load'} tool ${file}:`, error);
      }
    }
  • Tool cleanup function called during unload/reload.
    export async function destroy() {
      // Release resources, stop timers, disconnect, etc.
      console.log("Destroy buildReload_tool");
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/xiaoguomeiyitian/ToolBox'

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