@@ -8,12 +8,17 @@ import org.slf4j.LoggerFactory
88import org.slf4j.bridge.SLF4JBridgeHandler
99
1010/* *
11- * Start sse-server mcp on port 3001 .
11+ * Main entry point for the MCP GitHub Code Analysis Server application .
1212 *
13- * @param args
14- * - "--stdio": Runs an MCP server using standard input/output.
15- * - "--sse-server-ktor <port>": Runs an SSE MCP server using Ktor plugin (default if no argument is provided).
16- * - "--sse-server <port>": Runs an SSE MCP server with a plain configuration.
13+ * This application provides a server that analyzes GitHub repositories using the Model Context Protocol (MCP). It can
14+ * operate in different modes: standard I/O mode or Server-Sent Events (SSE) mode using either plain configuration or
15+ * Ktor plugin.
16+ *
17+ * @param args Command-line arguments to determine server behavior:
18+ * - "--stdio": Runs an MCP server using standard input/output.
19+ * - "--sse-server-ktor <port>": Runs an SSE MCP server using Ktor plugin (default if no args provided).
20+ * - "--sse-server <port>": Runs an SSE MCP server with plain configuration. If no port is specified, the value from
21+ * environment variable SERVER_PORT or default 3001 is used.
1722 */
1823fun main (args : Array <String >) {
1924 SLF4JBridgeHandler .removeHandlersForRootLogger()
@@ -26,16 +31,33 @@ fun main(args: Array<String>) {
2631 .onFailure { error -> logger.error(" Application failed: ${error.message} " , error) }
2732}
2833
29- /* * Data class representing application command settings */
34+ /* *
35+ * Data class representing application command settings.
36+ *
37+ * @property type The type of server to start (STDIO, SSE_KTOR, SSE_PLAIN).
38+ * @property port The port number on which the server will listen (for SSE modes only).
39+ */
3040data class AppCommand (val type : CommandType , val port : Int )
3141
32- /* * Enum representing possible commands */
42+ /* *
43+ * Enum representing the application command type.
44+ *
45+ * STDIO - Standard input/output mode for the MCP server SSE_KTOR - Server-Sent Events mode using the Ktor plugin
46+ * SSE_PLAIN - Server-Sent Events mode using plain configuration UNKNOWN - Unknown or unsupported command
47+ */
3348enum class CommandType {
3449 STDIO ,
3550 SSE_KTOR ,
3651 SSE_PLAIN ,
3752 UNKNOWN ;
3853
54+ /* *
55+ * Converts a command-line argument to the corresponding CommandType.
56+ *
57+ * @param arg The command-line argument string.
58+ * @return The CommandType corresponding to the argument, or SSE_KTOR if null, or UNKNOWN if the argument is not
59+ * recognized.
60+ */
3961 companion object {
4062 fun fromArg (arg : String? ): CommandType =
4163 when (arg) {
@@ -48,7 +70,15 @@ enum class CommandType {
4870 }
4971}
5072
51- /* * Runs the application with a functional approach */
73+ /* *
74+ * Runs the application by parsing arguments, ensuring necessary directories exist, and executing the appropriate server
75+ * command.
76+ *
77+ * @param args Command-line arguments to determine server behavior.
78+ * @return Result wrapping Unit, with success if the application runs successfully, or failure with the exception if an
79+ * error occurs.
80+ * @throws IOException If required directories cannot be created.
81+ */
5282fun runApplication (args : Array <String >): Result <Unit > = runCatching {
5383 val logger = LoggerFactory .getLogger(" Main" )
5484
@@ -64,14 +94,26 @@ fun runApplication(args: Array<String>): Result<Unit> = runCatching {
6494 executeCommand(command, Server ())
6595}
6696
67- /* * Parse command line arguments into a structured command */
97+ /* *
98+ * Parses command-line arguments into an [AppCommand] object.
99+ *
100+ * @param args The command-line arguments array.
101+ * @param defaultPort The default port to use if not specified in arguments.
102+ * @return An AppCommand object containing the parsed command type and port.
103+ */
68104fun parseArgs (args : Array <String >, defaultPort : Int ): AppCommand {
69105 val commandType = CommandType .fromArg(args.firstOrNull())
70106 val port = args.getOrNull(1 )?.toIntOrNull() ? : defaultPort
71107 return AppCommand (commandType, port)
72108}
73109
74- /* * Ensures both application directories are properly created with clear error handling */
110+ /* *
111+ * Ensures that all required application directories exist, creating them if necessary.
112+ *
113+ * @param config The application configuration containing directory paths.
114+ * @return A list of Results, each containing a Pair of the Path and a Boolean indicating whether the directory was
115+ * newly created (true) or already existed (false).
116+ */
75117fun ensureApplicationDirectories (config : AppConfig ): List <Result <Pair <Path , Boolean >>> {
76118 val logger = LoggerFactory .getLogger(" Main" )
77119
@@ -89,7 +131,15 @@ fun ensureApplicationDirectories(config: AppConfig): List<Result<Pair<Path, Bool
89131 return listOf (cloneDirResult, logsDirResult)
90132}
91133
92- /* * Creates a directory with its full path, handling all parent directories */
134+ /* *
135+ * Creates a directory and all parent directories if they don't exist.
136+ *
137+ * @param path The Path to the directory to create.
138+ * @return Result containing a Pair of the Path and a Boolean indicating whether the directory was newly created (true)
139+ * or already existed (false).
140+ * @throws IOException If the path exists but is not a directory, creation fails, or the directory doesn't exist after
141+ * attempted creation.
142+ */
93143fun createDirectoryWithFullPath (path : Path ): Result <Pair <Path , Boolean >> = runCatching {
94144 val logger: Logger = LoggerFactory .getLogger(" Main" )
95145
@@ -106,7 +156,13 @@ fun createDirectoryWithFullPath(path: Path): Result<Pair<Path, Boolean>> = runCa
106156 path to true
107157}
108158
109- /* * Executes the appropriate server command */
159+ /* *
160+ * Executes the appropriate server command based on the provided AppCommand.
161+ *
162+ * @param command The AppCommand specifying the type of server to start and its port.
163+ * @param server The Server instance to use for execution.
164+ * @throws IllegalArgumentException If the command type is UNKNOWN.
165+ */
110166fun executeCommand (command : AppCommand , server : Server ) {
111167 val logger = LoggerFactory .getLogger(" Main" )
112168
0 commit comments