Skip to content

Commit b61e6b6

Browse files
committed
feat: server tests
1 parent fd3a467 commit b61e6b6

File tree

3 files changed

+165
-169
lines changed

3 files changed

+165
-169
lines changed

src/main/kotlin/mcp/code/analysis/server/Server.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import io.ktor.util.collections.*
1212
import io.modelcontextprotocol.kotlin.sdk.*
1313
import io.modelcontextprotocol.kotlin.sdk.server.*
1414
import io.modelcontextprotocol.kotlin.sdk.server.Server as SdkServer
15-
import kotlin.text.get
1615
import kotlinx.coroutines.Job
1716
import kotlinx.coroutines.delay
1817
import kotlinx.coroutines.launch
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory
3130
* Server for analyzing GitHub repositories using the Model Context Protocol (MCP). Provides functionalities for
3231
* analyzing GitHub repositories and checking analysis status.
3332
*/
34-
open class Server(
33+
class Server(
3534
private val repositoryAnalysisService: RepositoryAnalysisService = RepositoryAnalysisService(),
3635
private val logger: Logger = LoggerFactory.getLogger(Server::class.java),
3736
private val implementation: Implementation =
@@ -70,7 +69,7 @@ open class Server(
7069
*
7170
* @param port The port number on which the SSE MCP server will listen for client connections.
7271
*/
73-
open fun runSseMcpServerWithPlainConfiguration(port: Int): Unit = runBlocking {
72+
fun runSseMcpServerWithPlainConfiguration(port: Int): Unit = runBlocking {
7473
val servers = ConcurrentMap<String, SdkServer>()
7574
logger.info("Starting SSE server on port $port.")
7675
logger.info("Use inspector to connect to the http://localhost:$port/sse")
@@ -132,7 +131,7 @@ open class Server(
132131
*
133132
* @param port The port number on which the SSE MCP server will listen for client connections.
134133
*/
135-
open fun runSseMcpServerUsingKtorPlugin(port: Int): Unit = runBlocking {
134+
fun runSseMcpServerUsingKtorPlugin(port: Int): Unit = runBlocking {
136135
logger.debug("Starting SSE server on port $port")
137136
logger.debug("Use inspector to connect to http://localhost:$port/sse")
138137

@@ -149,7 +148,7 @@ open class Server(
149148
*
150149
* @return The configured MCP server instance.
151150
*/
152-
open fun configureServer(): SdkServer {
151+
fun configureServer(): SdkServer {
153152
val server = SdkServer(implementation, serverOptions)
154153

155154
server.addTool(

src/main/kotlin/mcp/code/analysis/service/ModelContextService.kt

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ data class ModelContextService(
8787
* @return A structured prompt for the model
8888
*/
8989
fun buildInsightsPrompt(codeSnippets: List<String>, readme: String) =
90-
"""|You are analyzing a software codebase that includes a README file and source code files. Your task is to extract a structured summary of the codebases architecture, components, and relationships.
90+
"""|You are analyzing a software codebase that includes a README file and source code files. Your task is to extract a structured, file-by-file analysis of the codebase's architecture, components, and interconnections.
9191
|
92-
|Use the information provided below.
92+
|Use only the information provided below.
9393
|
9494
|----------------------
9595
|README Content:
@@ -104,14 +104,14 @@ data class ModelContextService(
104104
|${codeSnippets.joinToString("\n\n")}
105105
|----------------------
106106
|
107-
|For each file:
108-
|- File name and language
109-
|- Main classes, functions, or data structures
110-
|- Purpose of the file (based on comments, function names, etc.)
111-
|- Key public interfaces (functions, methods, classes)
112-
|- If applicable, how this file connects to other parts of the codebase (e.g. imports, API usage, function calls)
107+
|For each file, extract the following:
108+
|- File path and programming language
109+
|- Main classes, functions, or data structures defined
110+
|- Purpose of the file (what it does and why it exists)
111+
|- Key public interfaces (classes, methods, functions)
112+
|- Dependencies and relationships (e.g., imports, API usage, method calls across files)
113113
|
114-
|Use this format:
114+
|Output using this format:
115115
|
116116
|### File: path/to/file.ext (Language: X)
117117
|- **Purpose**: ...
@@ -120,8 +120,11 @@ data class ModelContextService(
120120
|- **Relationships**:
121121
| - ...
122122
|
123-
|Repeat this for all files. Avoid speculation. Be concise and grounded in the content above.
124-
|"""
123+
|Important:
124+
|- Be specific and factual; avoid speculation.
125+
|- Use information from comments, function names, or obvious patterns.
126+
|- Summarize concisely; no fluff.
127+
"""
125128
.trimMargin()
126129

127130
/**
@@ -131,40 +134,40 @@ data class ModelContextService(
131134
* @return A structured prompt for the model
132135
*/
133136
fun buildSummaryPrompt(insights: String): String =
134-
"""|You are writing a high-level but technically accurate summary of a software codebase for a developer unfamiliar with the project.
137+
"""|You are writing a high-level, technically accurate summary of a software codebase. The reader is a developer unfamiliar with the project, so your explanation should clarify the purpose, structure, and important technical details.
135138
|
136-
|Use the extracted structural analysis below to build the summary.
139+
|Use the structured analysis below to guide your summary.
137140
|
138141
|----------------------
139-
|
140142
|Structural Analysis:
141143
|
142144
|${parseInsights(insights)}
143145
|----------------------
144146
|
145-
|You must include:
147+
|Include the following in your output:
146148
|
147-
|1. **Main Purpose** – what the software does, who might use it.
148-
|2. **Architecture Overview** – main components and how they interact.
149-
|3. **Technologies and Languages** – what languages, frameworks, or tools are used.
150-
|4. **Key Workflows** – example flow of data, processing, or control (e.g., "HTTP request -> router -> controller -> database").
151-
|5. **Strengths and Weaknesses** – any observed complexity, tight coupling, lack of documentation, or reusable design patterns.
149+
|1. **Main Purpose** – What the software does, the problem it solves, and who uses it.
150+
|2. **Architecture Overview** – Key components or layers and how they interact. Describe patterns if evident (e.g., microservices, event-driven, layered architecture).
151+
|3. **Technologies and Languages** – List the programming language(s), major frameworks/libraries, and any notable tools.
152+
|4. **Key Workflows** – Show how data or control flows through the system. Prefer concrete examples (e.g., "Kafka -> Consumer -> Metrics tracker -> Monitoring system").
153+
|5. **Strengths and Weaknesses** – Mention any strengths (modularity, patterns, scalability) and issues (tight coupling, complexity, missing docs).
152154
|
153-
|Where helpful, include:
154-
|- Short code snippets or function/method names (language-agnostic).
155-
|- Architecture patterns if detected (e.g., MVC, pub/sub, monolith, microservice).
155+
|Also consider:
156+
|- Noteworthy classes, functions, or modules
157+
|- Signs of testability, extensibility, or maintainability
158+
|- Use of design patterns (Builder, Observer, etc.)
156159
|
157-
|Format the output using Markdown. Be concise and insightful.
158-
"""
160+
|Write the output in well-structured **Markdown**. Be concise, insightful, and avoid guessing.
161+
|"""
159162
.trimMargin()
160163

161164
private suspend fun sendRequest(url: String, request: ChatRequest): HttpResponse {
162165
return httpClient.post(url) {
163166
contentType(ContentType.Application.Json)
164167
setBody(request)
165168
timeout {
166-
requestTimeoutMillis = 10.minutes.inWholeMilliseconds
167-
socketTimeoutMillis = 10.minutes.inWholeMilliseconds
169+
requestTimeoutMillis = 60.minutes.inWholeMilliseconds
170+
socketTimeoutMillis = 60.minutes.inWholeMilliseconds
168171
connectTimeoutMillis = 120_000
169172
}
170173
}

0 commit comments

Comments
 (0)