Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static Command CreateCommand(
CommandExecutor commandExecutor,
AuthenticationService authService,
GraphApiService graphApiService,
IProcessService processService)
IProcessService processService,
IServerService serverService)
{
var developCommand = new Command("develop", "Manage MCP tool servers for agent development");

Expand Down Expand Up @@ -54,7 +55,7 @@ public static Command CreateCommand(
developCommand.AddCommand(AddPermissionsSubcommand.CreateCommand(logger, configService, graphApiService));

// Start Mock Tooling Server subcommand
developCommand.AddCommand(MockToolingServerSubcommand.CreateCommand(logger, processService));
developCommand.AddCommand(MockToolingServerSubcommand.CreateCommand(logger, processService, serverService));

return developCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Agents.A365.DevTools.Cli.Services;
using Microsoft.Extensions.Logging;
using System.CommandLine;
using Microsoft.Agents.A365.DevTools.MockToolingServer;

namespace Microsoft.Agents.A365.DevTools.Cli.Commands.DevelopSubcommands;

Expand All @@ -18,13 +17,15 @@ internal static class MockToolingServerSubcommand
/// </summary>
/// <param name="logger">Logger for progress reporting</param>
/// <param name="processService">Process service for starting processes</param>
/// <param name="serverService">Server service for managing the server</param>
/// <returns>
/// A <see cref="Command"/> object representing the 'start-mock-tooling-server'
/// subcommand, used to start the Mock Tooling Server for local development and testing.
/// </returns>
public static Command CreateCommand(
ILogger logger,
IProcessService processService)
IProcessService processService,
IServerService serverService)
{
var command = new Command("start-mock-tooling-server", "Start the Mock Tooling Server for local development and testing");
command.AddAlias("mts");
Expand Down Expand Up @@ -54,7 +55,7 @@ public static Command CreateCommand(
command.AddOption(backgroundOption);

command.SetHandler(async (port, verbose, dryRun, background) => {
await HandleStartServer(port, verbose, dryRun, background, logger, processService);
await HandleStartServer(port, verbose, dryRun, background, logger, processService, serverService);
}, portOption, verboseOption, dryRunOption, backgroundOption);

return command;
Expand All @@ -69,7 +70,15 @@ public static Command CreateCommand(
/// <param name="background">Run the server in the background (opens new terminal to run server)</param>
/// <param name="logger">Logger for progress reporting</param>
/// <param name="processService">Process service for starting processes</param>
public static async Task HandleStartServer(int? port, bool verbose, bool dryRun, bool background, ILogger logger, IProcessService processService)
/// <param name="serverService">Server service for managing the server</param>
public static async Task HandleStartServer(
int? port,
bool verbose,
bool dryRun,
bool background,
ILogger logger,
IProcessService processService,
IServerService serverService)
{
var serverPort = port ?? 5309;
if (serverPort < 1 || serverPort > 65535)
Expand Down Expand Up @@ -114,7 +123,7 @@ public static async Task HandleStartServer(int? port, bool verbose, bool dryRun,
new[] { "--urls", $"http://localhost:{serverPort}" };

// This will run in foreground and block the current terminal until the server is stopped
await Server.Start(args);
await serverService.StartAsync(args);
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.Agents.A365.DevTools.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ static async Task<int> Main(string[] args)
var platformDetector = serviceProvider.GetRequiredService<PlatformDetector>();
var processService = serviceProvider.GetRequiredService<IProcessService>();
var clientAppValidator = serviceProvider.GetRequiredService<IClientAppValidator>();
var serverService = serviceProvider.GetRequiredService<IServerService>();

// Add commands
rootCommand.AddCommand(DevelopCommand.CreateCommand(developLogger, configService, executor, authService, graphApiService, processService));
rootCommand.AddCommand(DevelopCommand.CreateCommand(developLogger, configService, executor, authService, graphApiService, processService, serverService));
rootCommand.AddCommand(DevelopMcpCommand.CreateCommand(developLogger, toolingService));
rootCommand.AddCommand(SetupCommand.CreateCommand(setupLogger, configService, executor,
deploymentService, botConfigurator, azureValidator, webAppCreator, platformDetector, graphApiService, clientAppValidator));
Expand Down Expand Up @@ -214,6 +215,9 @@ private static void ConfigureServices(IServiceCollection services, LogLevel mini
// Register ProcessService for cross-platform process launching
services.AddSingleton<IProcessService, ProcessService>();

// Register ServerService for starting servers
services.AddSingleton<IServerService, MockToolingServerService>();

// Register Azure CLI service and Configuration Wizard
services.AddSingleton<IAzureCliService, AzureCliService>();
services.AddSingleton<IConfigurationWizardService, ConfigurationWizardService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Agents.A365.DevTools.Cli.Services;

/// <summary>
/// Interface for server operations
/// </summary>
public interface IServerService
{
/// <summary>
/// Entry point for starting servers programmatically from other applications.
/// </summary>
/// <param name="args">Command-line arguments to pass to the server</param>
/// <returns>Task representing the running server</returns>
Task StartAsync(string[] args);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Agents.A365.DevTools.Cli.Services;

using Microsoft.Agents.A365.DevTools.MockToolingServer;

/// <summary>
/// An IServerService implementation for running the MockToolingServer
/// </summary>
public class MockToolingServerService : IServerService
{
/// <inheritdoc/>
public async Task StartAsync(string[] args)
{
await Server.Start(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DevelopCommandTests
private readonly AuthenticationService _mockAuthService;
private readonly GraphApiService _mockGraphApiService;
private readonly IProcessService _mockProcessService;
private readonly IServerService _mockServerService;

public DevelopCommandTests()
{
Expand All @@ -35,13 +36,21 @@ public DevelopCommandTests()
_mockGraphApiService = Substitute.ForPartsOf<GraphApiService>(mockGraphApiLogger, _mockCommandExecutor);

_mockProcessService = Substitute.For<IProcessService>();
_mockServerService = Substitute.For<IServerService>();
}

[Fact]
public void CreateCommand_ReturnsCommandWithCorrectName()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

// Assert
Assert.Equal("develop", command.Name);
Expand All @@ -52,7 +61,14 @@ public void CreateCommand_ReturnsCommandWithCorrectName()
public void CreateCommand_HasSevenSubcommands()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

// Assert
Assert.Equal(7, command.Subcommands.Count);
Expand All @@ -71,7 +87,15 @@ public void CreateCommand_HasSevenSubcommands()
public void ListAvailableSubcommand_HasCorrectOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "list-available");

// Assert
Expand All @@ -85,7 +109,15 @@ public void ListAvailableSubcommand_HasCorrectOptions()
public void ListConfiguredSubcommand_HasCorrectOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "list-configured");

// Assert
Expand All @@ -98,7 +130,15 @@ public void ListConfiguredSubcommand_HasCorrectOptions()
public void AddMcpServersSubcommand_HasCorrectArgumentsAndOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "add-mcp-servers");

// Assert
Expand All @@ -115,7 +155,15 @@ public void AddMcpServersSubcommand_HasCorrectArgumentsAndOptions()
public void RemoveMcpServersSubcommand_HasCorrectArgumentsAndOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "remove-mcp-servers");

// Assert
Expand All @@ -132,7 +180,15 @@ public void RemoveMcpServersSubcommand_HasCorrectArgumentsAndOptions()
public void GetTokenSubcommand_HasCorrectOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "get-token");

// Assert
Expand All @@ -150,7 +206,15 @@ public void GetTokenSubcommand_HasCorrectOptions()
public void AddPermissionsSubcommand_HasCorrectOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "add-permissions");

// Assert
Expand All @@ -167,7 +231,15 @@ public void AddPermissionsSubcommand_HasCorrectOptions()
public void StartMockToolingServerSubcommand_HasCorrectOptions()
{
// Act
var command = DevelopCommand.CreateCommand(_mockLogger, _mockConfigService, _mockCommandExecutor, _mockAuthService, _mockGraphApiService, _mockProcessService);
var command = DevelopCommand.CreateCommand(
_mockLogger,
_mockConfigService,
_mockCommandExecutor,
_mockAuthService,
_mockGraphApiService,
_mockProcessService,
_mockServerService);

var subcommand = command.Subcommands.First(sc => sc.Name == "start-mock-tooling-server");

// Assert
Expand Down
Loading