generateDispatchRepositoryTool generates an MCP tool definition for a specific dispatch-repository tool. The tool will be named after the tool key (normalized to underscores) and accept the tool's declared inputs as parameters.
(toolKey string, toolConfig *DispatchRepositoryToolConfig)
| 127 | // The tool will be named after the tool key (normalized to underscores) and accept |
| 128 | // the tool's declared inputs as parameters. |
| 129 | func generateDispatchRepositoryTool(toolKey string, toolConfig *DispatchRepositoryToolConfig) map[string]any { |
| 130 | dispatchRepositoryLog.Printf("Generating dispatch-repository tool: key=%s", toolKey) |
| 131 | |
| 132 | // Normalize tool key to use underscores |
| 133 | toolName := stringutil.NormalizeSafeOutputIdentifier(toolKey) |
| 134 | |
| 135 | description := toolConfig.Description |
| 136 | if description == "" { |
| 137 | description = "Dispatch a repository_dispatch event" |
| 138 | if toolConfig.EventType != "" { |
| 139 | description += " with event_type: " + toolConfig.EventType |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if toolConfig.Workflow != "" { |
| 144 | description += " (targets workflow: " + toolConfig.Workflow + ")" |
| 145 | } |
| 146 | |
| 147 | // Build input schema from the tool's inputs definition |
| 148 | properties, required := buildInputSchema(toolConfig.Inputs, func(inputName string) string { |
| 149 | return "Input parameter '" + inputName + "'" |
| 150 | }) |
| 151 | |
| 152 | inputSchema := map[string]any{ |
| 153 | "type": "object", |
| 154 | "properties": properties, |
| 155 | "additionalProperties": false, |
| 156 | } |
| 157 | |
| 158 | if len(required) > 0 { |
| 159 | inputSchema["required"] = required |
| 160 | } |
| 161 | |
| 162 | tool := map[string]any{ |
| 163 | "name": toolName, |
| 164 | "description": description, |
| 165 | "_dispatch_repository_tool": toolKey, // Internal metadata for handler routing |
| 166 | "inputSchema": inputSchema, |
| 167 | } |
| 168 | |
| 169 | dispatchRepositoryLog.Printf("Generated dispatch-repository tool: name=%s, properties=%d", toolName, len(properties)) |
| 170 | return tool |
| 171 | } |