Skip to content

Commit 91ab6cc

Browse files
committed
updating tools
1 parent 9ba4d9f commit 91ab6cc

File tree

5 files changed

+541
-289
lines changed

5 files changed

+541
-289
lines changed

.github/copilot-instructions.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ When someone asks to run validation on their library, ask them what supported en
1313

1414
Initialize and validate a TypeSpec client library for Azure SDK for Python. Please:
1515

16-
1. If the typespec mcp tool is available use that for generating or initializing. Otherwise please follow the instructions below to generate an SDK from TypeSpec.
16+
1. If the typespec mcp tool is available use that for generating or initializing. If asked to update changes from local spec repo, lets find the path to that local azure-rest-api-specs repo for our tools. Otherwise please follow the instructions below to generate an SDK from TypeSpec.
1717
- Ensure that node, python, and the required dependencies are installed in your environment (@azure-tools/typespec-client-generator-cli)
1818
- If provided a url to a tspconfig.yaml ensure it has the most recent commit hash of the tspconfig.yaml file instead of a branch name like `main`. If the url does not have a commit hash, use the GitHub API to get the most recent commit hash of the tspconfig.yaml file. If you are unable to do this, ask the user to provide the correct url. `curl -s "https://api.github.com/repos/Azure/azure-rest-api-specs/commits?path=,path to tspconfig.yaml>&per_page=1"` helpful.
1919
- If prompted to initialize the SDK from a url or a local repo use the command `npx @azure-tools/typespec-client-generator-cli init --tsp-config [URL or local azure-rest-api-specs path to tspconfig.yaml]`. The tsp-client init command runs sync and generate under the hood, so generation is complete after the init concludes. If the tspconfig.yaml value is a path to a local file, you can mention that the user will have to populate the values in tsp-location.yaml themselves.
2020
- If prompted to update the SDK use the command `npx @azure-tools/typespec-client-generator-cli update`.
2121
- If prompted to generate the SDK use the command `npx @azure-tools/typespec-client-generator-cli generate`.
2222
- If prompted to sync the SDK use the command `npx @azure-tools/typespec-client-generator-cli sync`.
2323
- If prompted to sync with local code use the command `npx @azure-tools/typespec-client-generator-cli sync --local-spec-repo [path to local azure-rest-api-specs repo]`.
24-
- If syncing from a local repo, do not grab a commit hash and do not manually create directories. The command will create the directories for you.
24+
- If syncing from a local repo, do not grab a commit hash.
25+
- Do not manually create directories. The command will create the directories for you.
2526
- If asked to sync or generate `package-name` we need to find the path to the package's tsp-location.yaml in the azure-sdk-for-python repo and run the command in the same directory.
2627

2728
2. After generation is complete, validate the output by:
@@ -33,6 +34,13 @@ Initialize and validate a TypeSpec client library for Azure SDK for Python. Plea
3334

3435
3. If any errors or warnings are found, after running all validation checks provide guidance on fixing them following Azure SDK best practices.
3536

37+
4. After the above steps, let's use the GitHub mcp tool to create a pull request with the changes. The pull request should include:
38+
- A title that describes the changes made.
39+
- A description that includes the following:
40+
- A summary of the changes made.
41+
- A list of any issues or warnings found during validation and how they were fixed.
42+
- Any additional notes or comments about the changes made.
43+
3644
Please use Python 3.9 for compatibility, and refer to the Azure SDK design guidelines (https://azure.github.io/azure-sdk/python_design.html) for any implementation decisions.
3745

3846

.vscode/mcp.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
"run",
2929
"main.py"
3030
]
31+
},
32+
"github": {
33+
"command": "docker",
34+
"args": [
35+
"run",
36+
"-i",
37+
"--rm",
38+
"-e",
39+
"GITHUB_PERSONAL_ACCESS_TOKEN",
40+
"ghcr.io/github/github-mcp-server"
41+
],
42+
"env": {
43+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:gh_token}"
3144
}
32-
}
33-
}
45+
}
46+
}
47+
}

tools/mcp/typespec-story/main.py

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,21 @@ def run_typespec_cli_command(command: str, args: Dict[str, Any], root_dir: Optio
9393
try:
9494
# TODO: maybe if we return and dont wait for output this will work
9595
# Run the command and capture the output
96-
result = subprocess.run(
97-
cli_args,
98-
capture_output=True,
99-
text=True,
100-
cwd=root_dir,
101-
)
96+
if root_dir:
97+
result = subprocess.run(
98+
cli_args,
99+
capture_output=True,
100+
text=True,
101+
cwd=root_dir,
102+
)
103+
else:
104+
result = subprocess.run(
105+
cli_args,
106+
capture_output=True,
107+
text=True,
108+
)
102109
logger.info(f"Command output: {result.stdout}")
103-
110+
104111
return {
105112
"success": True,
106113
"stdout": result.stdout,
@@ -138,8 +145,120 @@ def init_tool(tsp_config_url: str, root_dir: Optional[str] = None) -> Dict[str,
138145
args = {}
139146
args["tsp-config"] = updated_url
140147

148+
# If root_dir is not provided, use the repository root
149+
if root_dir is None:
150+
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
151+
logger.info(f"No root_dir provided, using repository root: {root_dir}")
152+
153+
return run_typespec_cli_command("init", args, root_dir=root_dir)
154+
155+
@mcp.tool("init_local")
156+
def init_local_tool(tsp_config_path: str, root_dir: Optional[str] = None) -> Dict[str, Any]:
157+
"""Initialize a typespec client library directory from a local azure-rest-api-specs repo.
158+
159+
Args:
160+
tsp_config_path: The path to the local tspconfig.yaml file.
161+
root_dir: The root directory where the client library will be generated.
162+
163+
Returns:
164+
A dictionary containing the result of the command.
165+
"""
166+
# Prepare arguments for the CLI command
167+
args = {}
168+
args["tsp-config"] = tsp_config_path
169+
170+
# If root_dir is not provided, use the repository root
171+
if root_dir is None:
172+
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
173+
logger.info(f"No root_dir provided, using repository root: {root_dir}")
174+
141175
return run_typespec_cli_command("init", args, root_dir=root_dir)
142176

177+
@mcp.tool("generate")
178+
def generate_tool(project_dir: Optional[str] = None) -> Dict[str, Any]:
179+
"""Generate a typespec client library given the url.
180+
181+
Args:
182+
project_dir: The directory of the client library to be generated.
183+
184+
Returns:
185+
A dictionary containing the result of the command.
186+
"""
187+
# Prepare arguments for the CLI command
188+
args: Dict[str, Any] = {}
189+
190+
# If project_dir is not provided, use the current directory
191+
if project_dir is None:
192+
logger.info("No project_dir provided, using current directory")
193+
194+
return run_typespec_cli_command("generate", args, root_dir=project_dir)
195+
196+
@mcp.tool("update")
197+
def update_tool(project_dir: Optional[str] = None) -> Dict[str, Any]:
198+
"""Update a typespec client library.
199+
200+
This command looks for a tsp-location.yaml file in the current directory to sync a TypeSpec project
201+
and generate a client library. It calls sync and generate commands internally.
202+
203+
Args:
204+
project_dir: The root directory where the client library will be updated.
205+
206+
Returns:
207+
A dictionary containing the result of the command.
208+
"""
209+
# Prepare arguments for the CLI command
210+
args: Dict[str, Any] = {}
211+
212+
# If project_dir is not provided, use the current directory as this command
213+
# expects to find tsp-location.yaml in the working directory
214+
if project_dir is None:
215+
logger.info("No project_dir provided, using current directory")
216+
217+
return run_typespec_cli_command("update", args, root_dir=project_dir)
218+
219+
@mcp.tool("sync")
220+
def sync_tool(project_dir: Optional[str] = None) -> Dict[str, Any]:
221+
"""Sync a typespec client library from the remote repository.
222+
223+
This command looks for a tsp-location.yaml file to get the project details and sync them to a temporary directory.
224+
225+
Args:
226+
project_dir: The root directory where the client library will be synced.
227+
228+
Returns:
229+
A dictionary containing the result of the command.
230+
"""
231+
# Prepare arguments for the CLI command
232+
args: Dict[str, Any] = {}
233+
234+
# If project_dir is not provided, use the current directory as this command
235+
# expects to find tsp-location.yaml in the working directory
236+
if project_dir is None:
237+
logger.info("No project_dir provided, using current directory")
238+
239+
return run_typespec_cli_command("sync", args, root_dir=project_dir)
240+
241+
@mcp.tool("sync_local")
242+
def sync_local_tool(local_spec_repo: str, project_dir: Optional[str] = None) -> Dict[str, Any]:
243+
"""Sync a typespec client library from a local repository.
244+
245+
Args:
246+
local_spec_repo: The path to the local azure-rest-api-specs repository.
247+
project_dir: The root directory where the client library will be synced.
248+
249+
Returns:
250+
A dictionary containing the result of the command.
251+
"""
252+
# Prepare arguments for the CLI command
253+
args: Dict[str, Any] = {}
254+
args["local-spec-repo"] = local_spec_repo
255+
256+
# If project_dir is not provided, use the current directory
257+
if project_dir is None:
258+
logger.info("No project_dir provided, using current directory")
259+
260+
return run_typespec_cli_command("sync", args, root_dir=project_dir)
261+
143262
# Run the MCP server
144263
if __name__ == "__main__":
145264
# Initialize and run the server

tools/mcp/validation/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ dependencies = [
1616
"bandit>=1.7.0",
1717
"tox<5",
1818
"httpx>=0.28.1",
19+
"azure-core>=1.34.0",
1920
]

0 commit comments

Comments
 (0)