Skip to main content
Glama

gitea_mcp_upgrade

Upgrade the Gitea MCP server to the latest version by downloading and installing from the most recent release, with optional auto-confirmation.

Instructions

Upgrade Gitea MCP tool to the latest version. Downloads and installs from the latest release.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
auto_confirmNoAuto confirm the upgrade without prompting (default: false)

Implementation Reference

  • The handler function for the 'gitea_mcp_upgrade' tool. It checks current version, optionally elicits confirmation, downloads and executes an upgrade script from a remote URL, and returns success/error response.
      async (args) => {
        logger.debug({ args }, 'gitea_mcp_upgrade called');
    
        try {
          const fs = await import('fs');
          const path = await import('path');
          const { execSync } = await import('child_process');
    
          // 读取当前版本
          const packageJsonPath = path.join(process.cwd(), 'package.json');
          let currentVersion = '1.2.0'; // 默认版本
    
          if (fs.existsSync(packageJsonPath)) {
            const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
            currentVersion = packageJson.version;
          }
    
          // 如果没有自动确认,使用 elicitation 询问用户
          if (!args.auto_confirm) {
            const result = await ctx.server.server.elicitInput({
              message: `当前版本: v${currentVersion}\n\n是否要升级到最新版本?\n\n升级过程将:\n1. 下载最新版本的发布包\n2. 安装到 ~/.gitea-mcp 目录\n3. 自动安装依赖\n\n注意:升级过程中需要保证网络连接稳定。`,
              requestedSchema: {
                type: 'object',
                properties: {
                  confirm: {
                    type: 'boolean',
                    title: '确认升级',
                    description: '是否继续升级?',
                    default: false,
                  },
                },
                required: ['confirm'],
              },
            });
    
            if (result.action !== 'accept' || !result.content?.confirm) {
              return {
                content: [
                  {
                    type: 'text',
                    text: 'Upgrade cancelled by user',
                  },
                ],
              };
            }
          }
    
          // 执行升级
          const installScriptUrl =
            'https://gitea.ktyun.cc/Kysion/entai-gitea-mcp/raw/branch/main/install-quick.sh';
    
          logger.info('Downloading and executing upgrade script...');
    
          // 下载并执行安装脚本
          const command = `bash -c "$(curl -fsSL ${installScriptUrl})"`;
    
          const output = execSync(command, {
            encoding: 'utf-8',
            stdio: 'pipe',
            maxBuffer: 10 * 1024 * 1024, // 10MB buffer
          });
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(
                  {
                    success: true,
                    message: 'Upgrade completed successfully',
                    currentVersion: `v${currentVersion}`,
                    output: output.substring(0, 1000), // 限制输出长度
                    note: 'Please restart your MCP client to use the new version',
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          logger.error({ error: errorMessage }, 'Failed to upgrade MCP tool');
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(
                  {
                    success: false,
                    error: errorMessage,
                    message: 'Upgrade failed',
                    fallback: 'You can manually upgrade by running: bash <(curl -fsSL https://gitea.ktyun.cc/Kysion/entai-gitea-mcp/raw/branch/main/install-quick.sh)',
                  },
                  null,
                  2
                ),
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Input schema for the 'gitea_mcp_upgrade' tool, defining optional 'auto_confirm' boolean parameter.
    {
      title: '升级 MCP 工具',
      description:
        'Upgrade Gitea MCP tool to the latest version. Downloads and installs from the latest release.',
      inputSchema: z.object({
        auto_confirm: z
          .boolean()
          .optional()
          .describe('Auto confirm the upgrade without prompting (default: false)'),
      }),
    },
  • src/index.ts:358-476 (registration)
    Registration of the 'gitea_mcp_upgrade' tool using mcpServer.registerTool, including name, schema, and inline handler within registerInitTools function.
      // gitea_mcp_upgrade - MCP 工具升级
      mcpServer.registerTool(
        'gitea_mcp_upgrade',
        {
          title: '升级 MCP 工具',
          description:
            'Upgrade Gitea MCP tool to the latest version. Downloads and installs from the latest release.',
          inputSchema: z.object({
            auto_confirm: z
              .boolean()
              .optional()
              .describe('Auto confirm the upgrade without prompting (default: false)'),
          }),
        },
        async (args) => {
          logger.debug({ args }, 'gitea_mcp_upgrade called');
    
          try {
            const fs = await import('fs');
            const path = await import('path');
            const { execSync } = await import('child_process');
    
            // 读取当前版本
            const packageJsonPath = path.join(process.cwd(), 'package.json');
            let currentVersion = '1.2.0'; // 默认版本
    
            if (fs.existsSync(packageJsonPath)) {
              const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
              currentVersion = packageJson.version;
            }
    
            // 如果没有自动确认,使用 elicitation 询问用户
            if (!args.auto_confirm) {
              const result = await ctx.server.server.elicitInput({
                message: `当前版本: v${currentVersion}\n\n是否要升级到最新版本?\n\n升级过程将:\n1. 下载最新版本的发布包\n2. 安装到 ~/.gitea-mcp 目录\n3. 自动安装依赖\n\n注意:升级过程中需要保证网络连接稳定。`,
                requestedSchema: {
                  type: 'object',
                  properties: {
                    confirm: {
                      type: 'boolean',
                      title: '确认升级',
                      description: '是否继续升级?',
                      default: false,
                    },
                  },
                  required: ['confirm'],
                },
              });
    
              if (result.action !== 'accept' || !result.content?.confirm) {
                return {
                  content: [
                    {
                      type: 'text',
                      text: 'Upgrade cancelled by user',
                    },
                  ],
                };
              }
            }
    
            // 执行升级
            const installScriptUrl =
              'https://gitea.ktyun.cc/Kysion/entai-gitea-mcp/raw/branch/main/install-quick.sh';
    
            logger.info('Downloading and executing upgrade script...');
    
            // 下载并执行安装脚本
            const command = `bash -c "$(curl -fsSL ${installScriptUrl})"`;
    
            const output = execSync(command, {
              encoding: 'utf-8',
              stdio: 'pipe',
              maxBuffer: 10 * 1024 * 1024, // 10MB buffer
            });
    
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(
                    {
                      success: true,
                      message: 'Upgrade completed successfully',
                      currentVersion: `v${currentVersion}`,
                      output: output.substring(0, 1000), // 限制输出长度
                      note: 'Please restart your MCP client to use the new version',
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error: unknown) {
            const errorMessage = error instanceof Error ? error.message : String(error);
            logger.error({ error: errorMessage }, 'Failed to upgrade MCP tool');
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(
                    {
                      success: false,
                      error: errorMessage,
                      message: 'Upgrade failed',
                      fallback: 'You can manually upgrade by running: bash <(curl -fsSL https://gitea.ktyun.cc/Kysion/entai-gitea-mcp/raw/branch/main/install-quick.sh)',
                    },
                    null,
                    2
                  ),
                },
              ],
              isError: true,
            };
          }
        }
      );
    }

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/SupenBysz/gitea-mcp-tool'

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