Skip to content

Commit 2bfa1e3

Browse files
tadeleshtadelesh
andauthored
Add tools for agents (#24962)
* Initial MCP server for Go SDK tool * update mod * update * add mcp config * move tools from mcp to generator tools, remove useless go version config and update the readme template * revert mcp * remove useless part * fix * changelog * review update --------- Co-authored-by: tadelesh <[email protected]>
1 parent 85eeccc commit 2bfa1e3

File tree

16 files changed

+1740
-70
lines changed

16 files changed

+1740
-70
lines changed

eng/tools/generator/CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Release History
22

3-
## 0.2.0 (2025-07-23)
3+
## 0.2.0 (UNRELEASED)
4+
5+
### Features Added
6+
7+
- Add `environment` command to check and validate environment prerequisites for Azure Go SDK generation.
8+
- Add `generate` command to generate Azure Go SDK packages from TypeSpec specifications.
9+
10+
### Breaking Changes
11+
12+
- Remove `go-version` flag from all commands. It is useless since the code generator could handle it.
13+
14+
### Bugs Fixed
15+
416
- Refined dependency upgrade logic to explicitly upgrade `azcore` and `azidentity` dependencies instead of using generic `go get -u ./... toolchain@none`
517

618
## 0.1.0 (2025-07-21)

eng/tools/generator/README.md

Lines changed: 234 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This is a command line tool for generating new releases and managing automation
66

77
The generator tool provides several commands to support the Azure SDK for Go development lifecycle:
88

9+
- **Environment**: Check and validate development environment prerequisites
10+
- **Generate**: Generate individual SDK packages from TypeSpec specifications
911
- **Issue Management**: Parse GitHub release request issues into configuration
1012
- **Release Generation**: Generate new SDK releases from TypeSpec or Swagger specifications
1113
- **Automation**: Process batch SDK generation for CI/CD pipelines
@@ -16,6 +18,114 @@ The generator tool provides several commands to support the Azure SDK for Go dev
1618

1719
This CLI tool provides the following commands:
1820

21+
### The `environment` command
22+
23+
The `environment` command checks and validates environment prerequisites for Azure Go SDK generation. It verifies the installation and versions of required tools and can automatically install missing TypeSpec tools.
24+
25+
**Usage:**
26+
```bash
27+
generator environment [flags]
28+
```
29+
30+
**Flags:**
31+
- `--auto-install`: Automatically install missing TypeSpec tools (default: true)
32+
- `-o, --output`: Output format, either "text" or "json" (default: "text")
33+
34+
**What it checks:**
35+
- **Go**: Minimum version 1.23
36+
- **Node.js**: Minimum version 20.0.0
37+
- **TypeSpec compiler**: `@typespec/compiler` package
38+
- **TypeSpec client generator CLI**: `@azure-tools/typespec-client-generator-cli` package
39+
- **GitHub CLI**: Installation and authentication status
40+
41+
**Examples:**
42+
```bash
43+
# Check environment with auto-install (default)
44+
generator environment
45+
46+
# Check environment without auto-installing missing tools
47+
generator environment --auto-install=false
48+
49+
# Get results in JSON format
50+
generator environment --output json
51+
52+
# Get help
53+
generator environment --help
54+
```
55+
56+
**Sample Output:**
57+
```
58+
All environment checks are satisfied! ✓
59+
60+
✓ Go: Go version 1.24 is installed ✓
61+
✓ Node.js: Node.js version 22.17.1 is installed ✓
62+
✓ TypeSpec Compiler: TypeSpec compiler is installed ✓
63+
✓ TypeSpec Client Generator CLI: TypeSpec client generator CLI is installed ✓
64+
✓ GitHub CLI: GitHub CLI 2.40.1 is installed ✓
65+
✓ GitHub CLI Authentication: GitHub CLI is authenticated ✓
66+
67+
✓ Automatically installed: TypeSpec compiler, TypeSpec client generator CLI
68+
```
69+
70+
### The `generate` command
71+
72+
The `generate` command generates Azure Go SDK packages from TypeSpec specifications. It can work with either a direct path to a TypeSpec configuration file or a GitHub PR link.
73+
74+
**Usage:**
75+
```bash
76+
generator generate <sdk-repo-path> <spec-repo-path> [flags]
77+
```
78+
79+
**Arguments:**
80+
- `sdk-repo-path`: Path to the local Azure SDK for Go repository
81+
- `spec-repo-path`: Path to the local Azure REST API Specs repository
82+
83+
**Flags:**
84+
- `--tsp-config`: Direct path to tspconfig.yaml file (relative to spec repo root)
85+
- `--github-pr`: GitHub PR link to extract TypeSpec configuration from
86+
- `--debug`: Enable debug output
87+
- `-o, --output`: Output format, either "text" or "json" (default: "text")
88+
89+
**Note:** You must provide exactly one of `--tsp-config` or `--github-pr`.
90+
91+
**Examples:**
92+
```bash
93+
# Generate from direct TypeSpec config path
94+
generator generate /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
95+
--tsp-config specification/cognitiveservices/OpenAI.Inference/tspconfig.yaml
96+
97+
# Generate from GitHub PR
98+
generator generate /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
99+
--github-pr https://github.com/Azure/azure-rest-api-specs/pull/12345
100+
101+
# Generate with debug output and JSON format
102+
generator generate /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
103+
--tsp-config specification/service/namespace/tspconfig.yaml \
104+
--debug --output json
105+
```
106+
107+
**What it does:**
108+
1. Validates the provided repository paths
109+
2. Resolves the TypeSpec configuration (checking out PR branch if needed using GitHub CLI)
110+
3. Generates the Go SDK using the TypeSpec-Go emitter
111+
4. Reports generation results including package info, version, and breaking changes
112+
113+
**Sample Output:**
114+
```
115+
✓ SDK generation completed successfully!
116+
117+
Package Name: armcognitiveservices
118+
Package Path: /path/to/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices
119+
Spec Folder: /path/to/azure-rest-api-specs/specification/cognitiveservices/OpenAI.Inference
120+
Version: 1.0.0
121+
Generation Type: mgmt
122+
✓ Has Breaking Changes: No
123+
124+
Changelog:
125+
### Features Added
126+
- New client `armcognitiveservices.ClientFactory` which is a client factory used to create any client in this module
127+
```
128+
19129
### The `issue` command
20130

21131
The `issue` command fetches release request issues from `github.com/Azure/sdk-release-request/issues` and parses them into configuration that other commands consume. The configuration outputs to stdout.
@@ -64,17 +174,23 @@ The command outputs a JSON configuration:
64174

65175
### The `automation-v2` command
66176

67-
The `automation-v2` command processes batch SDK generation for automation pipelines. This command is designed to run in the root directory of azure-sdk-for-go.
177+
The `automation-v2` command processes batch SDK generation for automation pipelines. This command is designed to run in the root directory of azure-sdk-for-go and handles multiple SDK generations in a single execution.
68178

69179
**Usage:**
70180
```bash
71-
generator automation-v2 <generate input filepath> <generate output filepath> [goVersion]
181+
generator automation-v2 <generate input filepath> <generate output filepath>
72182
```
73183

74184
**Arguments:**
75185
- `generate input filepath`: Path to the generation input JSON file
76186
- `generate output filepath`: Path where generation output JSON will be written
77-
- `goVersion`: Go version to use (default: "1.18")
187+
188+
**What it does:**
189+
1. Reads the input configuration file containing specification details
190+
2. Processes multiple TypeSpec projects and README files
191+
3. Generates SDKs for all specified services
192+
4. Writes comprehensive output including generation results and errors
193+
5. Handles batch operations for CI/CD automation pipelines
78194

79195
**Input Format:**
80196
The input file should contain:
@@ -90,9 +206,35 @@ The input file should contain:
90206
}
91207
```
92208

209+
**Output Format:**
210+
The command generates a JSON output file with generation results:
211+
```json
212+
{
213+
"packages": [
214+
{
215+
"packageName": "armservice",
216+
"path": "sdk/resourcemanager/service/armservice",
217+
"readmeMd": "specification/service/resource-manager/readme.md",
218+
"changelog": "### Features Added\n- Initial release",
219+
"breaking": false
220+
}
221+
],
222+
"errors": []
223+
}
224+
```
225+
226+
**Examples:**
227+
```bash
228+
# Process automation input file
229+
generator automation-v2 ./input.json ./output.json
230+
231+
# Typical CI/CD usage
232+
generator automation-v2 /tmp/generation-input.json /tmp/generation-output.json
233+
```
234+
93235
### The `release-v2` command
94236

95-
The `release-v2` command generates individual SDK releases for specific resource providers.
237+
The `release-v2` command generates individual SDK releases for specific resource providers. It creates new SDK packages or updates existing ones with new API versions.
96238

97239
**Usage:**
98240
```bash
@@ -115,61 +257,121 @@ generator release-v2 <azure-sdk-for-go directory> <azure-rest-api-specs director
115257
- `--skip-create-branch`: Skip creating release branch
116258
- `--skip-generate-example`: Skip generating examples
117259
- `--package-config`: Additional package configuration
118-
- `--go-version`: Go version (default: "1.18")
119260
- `-t, --token`: Personal access token for GitHub operations
120261
- `--tsp-config`: Path to TypeSpec tspconfig.yaml
121262
- `--tsp-option`: TypeSpec-go emit options (format: option1=value1;option2=value2)
122263
- `--tsp-client-option`: tsp-client options (e.g., --save-inputs, --debug)
123264

265+
**What it does:**
266+
1. Creates or updates SDK packages for specified resource providers
267+
2. Generates Go client code from TypeSpec or Swagger specifications
268+
3. Creates appropriate changelogs and documentation
269+
4. Handles versioning and breaking change detection
270+
5. Optionally creates release branches for the changes
271+
272+
**Examples:**
273+
```bash
274+
# Generate release for a specific RP
275+
generator release-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs network
276+
277+
# Generate with custom version and TypeSpec config
278+
generator release-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs network \
279+
--version-number v2.0.0 \
280+
--tsp-config specification/network/tspconfig.yaml
281+
282+
# Generate from release request config file
283+
generator release-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs config.json
284+
285+
# Skip branch creation and examples
286+
generator release-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs compute \
287+
--skip-create-branch --skip-generate-example
288+
```
289+
124290
### The `refresh-v2` command
125291

126-
The `refresh-v2` command regenerates all existing SDK packages.
292+
The `refresh-v2` command regenerates all existing SDK packages using the latest specifications. This is useful for bulk updates across multiple packages.
127293

128294
**Usage:**
129295
```bash
130-
generator refresh-v2 <azure-sdk-for-go directory> <azure-rest-api-specs directory>
296+
generator refresh-v2 <azure-sdk-for-go directory> <azure-rest-api-specs directory> [flags]
131297
```
132298

299+
**Arguments:**
300+
- `azure-sdk-for-go directory`: Path to azure-sdk-for-go repository
301+
- `azure-rest-api-specs directory`: Path to azure-rest-api-specs repository
302+
133303
**Flags:**
134304
- `--version-number`: Specify version number for refresh
135305
- `--sdk-repo`: SDK repository URL
136306
- `--spec-repo`: Spec repository URL
137307
- `--release-date`: Release date for changelog
138308
- `--skip-create-branch`: Skip creating release branch
139309
- `--skip-generate-example`: Skip generating examples
140-
- `--go-version`: Go version (default: "1.18")
141310
- `--rps`: Comma-separated list of RPs to refresh (default: all)
142311
- `--update-spec-version`: Whether to update commit ID (default: true)
143312

144-
### The `template` command
313+
**What it does:**
314+
1. Discovers all existing SDK packages in the repository
315+
2. Regenerates each package using current specifications
316+
3. Updates version numbers and changelogs as needed
317+
4. Handles batch processing of multiple resource providers
318+
5. Optionally creates release branches for all changes
319+
320+
**Examples:**
321+
```bash
322+
# Refresh all existing packages
323+
generator refresh-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs
324+
325+
# Refresh specific resource providers only
326+
generator refresh-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
327+
--rps network,compute,storage
328+
329+
# Refresh without creating branches or examples
330+
generator refresh-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
331+
--skip-create-branch --skip-generate-example
332+
333+
# Refresh with custom version and release date
334+
generator refresh-v2 /path/to/azure-sdk-for-go /path/to/azure-rest-api-specs \
335+
--version-number v1.1.0 --release-date 2024-01-15
336+
```
145337

146-
The `template` command generates package templates and scaffolding for new SDK packages.
338+
### The `template` command
147339

148-
## TypeSpec Support
340+
The `template` command generates package templates and scaffolding for new SDK packages. It creates the necessary directory structure and boilerplate code to onboard new services to the Azure SDK for Go.
149341

150-
The generator supports both traditional Swagger/OpenAPI specifications and modern TypeSpec definitions:
342+
**Usage:**
343+
```bash
344+
generator template <service-name> [flags]
345+
```
151346

152-
### TypeSpec Generation
153-
- Uses `@azure-tools/typespec-client-generator-cli` (tsp-client) v0.21.0
154-
- Requires `tspconfig.yaml` with `@azure-tools/typespec-go` emitter configured
155-
- Supports both data-plane and management-plane TypeSpec projects
347+
**Arguments:**
348+
- `service-name`: Name of the service to create a template for
156349

157-
### Swagger Generation
158-
- Uses AutoRest with Go extensions
159-
- Processes `readme.go.md` configuration files
160-
- Supports management-plane SDK generation
350+
**Flags:**
351+
- `--output-dir`: Output directory for the generated template (default: current directory)
352+
- `--package-name`: Custom package name (default: derived from service name)
353+
- `--namespace`: Namespace for the service (default: arm + service name)
354+
- `--data-plane`: Generate data plane template instead of management plane
355+
- `--force`: Overwrite existing files if they exist
356+
357+
**What it does:**
358+
1. Creates the standard Azure SDK for Go package directory structure
359+
2. Generates boilerplate Go files with proper package structure
360+
3. Creates example files and test scaffolding
361+
4. Sets up proper module configuration and dependencies
362+
5. Includes standard documentation templates
363+
364+
**Examples:**
365+
```bash
366+
# Generate a management plane template for a new service
367+
generator template myservice
161368

162-
## Prerequisites
369+
# Generate a data plane template
370+
generator template myservice --data-plane
163371

164-
For full functionality, ensure you have:
372+
# Generate template with custom package name and output directory
373+
generator template myservice --package-name armmyservice --output-dir ./sdk/resourcemanager/myservice
165374

166-
1. **Go 1.23 or later**
167-
2. **Node.js 20 or later**
168-
3. **Generator tool**: Install with:
169-
```bash
170-
go install github.com/Azure/azure-sdk-for-go/eng/tools/generator@latest
171-
```
172-
4. **tsp-client**: Install with:
173-
```bash
174-
npm install -g @azure-tools/[email protected]
175-
```
375+
# Force overwrite existing files
376+
generator template myservice --force
377+
```

0 commit comments

Comments
 (0)