forked from microsoft/mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectGetCommand.cs
More file actions
98 lines (82 loc) · 3.43 KB
/
ProjectGetCommand.cs
File metadata and controls
98 lines (82 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Net;
using Azure.Mcp.Tools.Functions.Options;
using Azure.Mcp.Tools.Functions.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;
namespace Azure.Mcp.Tools.Functions.Commands.Project;
public sealed class ProjectGetCommand(ILogger<ProjectGetCommand> logger) : BaseCommand<ProjectGetOptions>
{
private readonly ILogger<ProjectGetCommand> _logger = logger;
public override string Id => "b2c3d4e5-f6a7-8901-bcde-f12345678901";
public override string Name => "get";
public override string Description =>
"Get project scaffolding information for a new Azure Functions app. " +
"Use for getting project structure, setup instructions, and file list for initializing serverless projects. " +
"Returns project structure overview and setup instructions that agents use to create files. " +
"Use after functions language list and before functions template get.";
public override string Title => "Get Project Template";
public override ToolMetadata Metadata => new()
{
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = true,
LocalRequired = false,
Secret = false
};
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(FunctionsOptionDefinitions.Language);
command.Validators.Add(commandResult =>
{
var language = commandResult.GetValueWithoutDefault(FunctionsOptionDefinitions.Language);
if (string.IsNullOrWhiteSpace(language))
{
commandResult.AddError("The --language parameter is required.");
}
else if (!FunctionsOptionDefinitions.SupportedLanguages.Contains(language))
{
commandResult.AddError($"Invalid language '{language}'. Supported languages: {string.Join(", ", FunctionsOptionDefinitions.SupportedLanguages)}.");
}
});
}
protected override ProjectGetOptions BindOptions(ParseResult parseResult)
{
return new ProjectGetOptions
{
Language = parseResult.GetValueOrDefault<string>(FunctionsOptionDefinitions.Language.Name)
};
}
public override async Task<CommandResponse> ExecuteAsync(
CommandContext context,
ParseResult parseResult,
CancellationToken cancellationToken)
{
if (!Validate(parseResult.CommandResult, context.Response).IsValid)
{
return context.Response;
}
var options = BindOptions(parseResult);
try
{
var service = context.GetService<IFunctionsService>();
var result = await service.GetProjectTemplateAsync(options.Language!, cancellationToken);
context.Response.Status = HttpStatusCode.OK;
context.Response.Results = ResponseResult.Create(
[result],
FunctionsJsonContext.Default.ListProjectTemplateResult);
context.Response.Message = string.Empty;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error retrieving project template for Language: {Language}", options.Language);
HandleException(context, ex);
}
return context.Response;
}
}