Skip to main content
Glama

同步标签系统

gitea_workflow_sync_labels

Synchronize repository labels from workflow configuration to create standardized status, priority, and type labels in Gitea repositories.

Instructions

Sync repository labels based on workflow configuration. Creates status/, priority/, type/* and other labels defined in the config.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerNoRepository owner. Uses context if not provided
repoNoRepository name. Uses context if not provided
dry_runNoPreview changes without applying (default: false)

Implementation Reference

  • Core handler function for 'gitea_workflow_sync_labels' that synchronizes repository labels with the workflow configuration. Loads config if not provided, fetches existing labels, creates new ones, updates colors/descriptions, supports dry-run, and returns sync report.
    /**
     * 同步标签系统
     */
    export async function workflowSyncLabels(
      ctx: WorkflowToolsContext,
      args: {
        owner?: string;
        repo?: string;
        config?: WorkflowConfig;
        dry_run?: boolean;
      }
    ): Promise<{
      success: boolean;
      created: string[];
      updated: string[];
      skipped: string[];
      errors: string[];
    }> {
      logger.debug({ args: { ...args, config: args.config ? '[provided]' : undefined } }, 'Syncing labels');
    
      const { owner, repo } = ctx.contextManager.resolveOwnerRepo(args.owner, args.repo);
      const dryRun = args.dry_run ?? false;
    
      // 获取配置
      let config = args.config;
      if (!config) {
        const loadResult = await workflowLoadConfig(ctx, { owner, repo });
        if (!loadResult.success || !loadResult.config) {
          return {
            success: false,
            created: [],
            updated: [],
            skipped: [],
            errors: [loadResult.error || '无法加载配置'],
          };
        }
        config = loadResult.config;
      }
    
      const created: string[] = [];
      const updated: string[] = [];
      const skipped: string[] = [];
      const errors: string[] = [];
    
      // 获取现有标签
      const existingLabels = await ctx.client.get<Array<{ id: number; name: string; color: string }>>(
        `/repos/${owner}/${repo}/labels`
      );
      const existingLabelMap = new Map(existingLabels.map((l) => [l.name, l]));
    
      // 获取配置中的所有标签
      const configLabels = getAllLabels(config);
    
      for (const { name, config: labelConfig } of configLabels) {
        try {
          const existing = existingLabelMap.get(name);
    
          if (existing) {
            // 检查是否需要更新
            if (existing.color !== labelConfig.color) {
              if (!dryRun) {
                await ctx.client.patch(`/repos/${owner}/${repo}/labels/${existing.id}`, {
                  color: labelConfig.color,
                  description: labelConfig.description,
                });
              }
              updated.push(name);
            } else {
              skipped.push(name);
            }
          } else {
            // 创建新标签
            if (!dryRun) {
              await ctx.client.post(`/repos/${owner}/${repo}/labels`, {
                name,
                color: labelConfig.color,
                description: labelConfig.description,
              });
            }
            created.push(name);
          }
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          errors.push(`标签 ${name}: ${errorMessage}`);
        }
      }
    
      logger.info(
        { owner, repo, created: created.length, updated: updated.length, skipped: skipped.length },
        'Labels synced'
      );
    
      return {
        success: errors.length === 0,
        created,
        updated,
        skipped,
        errors,
      };
    }
  • Registers the 'gitea_workflow_sync_labels' tool with the MCP server, defining title, description, Zod input schema, and a wrapper handler that calls the core workflowSyncLabels function and formats the response.
    mcpServer.registerTool(
      'gitea_workflow_sync_labels',
      {
        title: '同步标签系统',
        description:
          'Sync repository labels based on workflow configuration. Creates status/*, priority/*, type/* and other labels defined in the config.',
        inputSchema: z.object({
          owner: z.string().optional().describe('Repository owner. Uses context if not provided'),
          repo: z.string().optional().describe('Repository name. Uses context if not provided'),
          dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'),
        }),
      },
      async (args) => {
        try {
          const result = await WorkflowTools.workflowSyncLabels(
            { client: ctx.client, contextManager: ctx.contextManager },
            args
          );
          return {
            content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
            isError: !result.success,
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text' as const, text: `Error: ${errorMessage}` }],
            isError: true,
          };
        }
      }
    );
  • Zod input schema for the tool defining parameters: owner, repo (optional), dry_run (optional boolean).
    inputSchema: z.object({
      owner: z.string().optional().describe('Repository owner. Uses context if not provided'),
      repo: z.string().optional().describe('Repository name. Uses context if not provided'),
      dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'),
    }),
  • Imports helper functions like getAllLabels used in the handler to retrieve all labels from config.
    import {
      type WorkflowConfig,
      type ProjectType,
      generateDefaultConfig,
      serializeConfig,
      parseConfig,
      validateConfig,
      getAllLabels,
      getSLAHours,
      getLabelPrefixes,
      buildLabel,
      matchLabel,
      resolveRulePlaceholders,
    } from '../utils/workflow-config.js';
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 'creates' labels, implying a write operation, but doesn't disclose behavioral traits like whether it modifies existing labels, requires specific permissions, handles conflicts, or has side effects. The dry_run parameter in schema hints at preview capability, but the description doesn't elaborate on this behavior.

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

Conciseness4/5

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

Two concise sentences that efficiently state the purpose and scope. The first sentence covers the main action and resource, while the second specifies label categories. No wasted words, though it could be slightly more front-loaded with key details.

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

Completeness3/5

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

Given no annotations and no output schema, the description is moderately complete for a tool that performs label synchronization. It specifies what labels are created but lacks details on behavior, error handling, or output format. For a mutation tool with 3 parameters, it should provide more context about side effects and prerequisites.

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%, providing clear documentation for all three parameters (owner, repo, dry_run). The description adds no parameter-specific information beyond what's in the schema, so it meets the baseline of 3 without compensating or adding extra meaning.

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 verb 'sync' and resource 'repository labels' with specific label categories (status/*, priority/*, type/*) defined by workflow configuration. It distinguishes from most siblings which focus on compliance checks, issues, PRs, or other workflow operations, though it doesn't explicitly differentiate from 'gitea_workflow_sync_board' and 'gitea_workflow_sync_status' which also involve synchronization.

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 explicit guidance on when to use this tool versus alternatives. The description mentions 'based on workflow configuration' but doesn't specify prerequisites, when to run it, or when to choose other sync tools like 'gitea_workflow_sync_board' or 'gitea_workflow_sync_status'. Usage is implied rather than stated.

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

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