Skip to content
Merged
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
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2026, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.mcp.prompts

import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addSuggestConceptsPrompt
import de.fraunhofer.aisec.cpg.mcp.utils.withClient
import io.modelcontextprotocol.kotlin.sdk.types.GetPromptRequest
import io.modelcontextprotocol.kotlin.sdk.types.GetPromptRequestParams
import io.modelcontextprotocol.kotlin.sdk.types.TextContent
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class CpgSuggestConceptsPromptTest {
@Test
fun suggestConceptsNoDescription() =
withClient(registerPrompts = { addSuggestConceptsPrompt() }) { client ->
val result =
client.getPrompt(
GetPromptRequest(GetPromptRequestParams(name = "suggest_concepts"))
)

assertNotNull(result)
val text = (result.messages.firstOrNull()?.content as? TextContent)?.text
assertNotNull(text, "Prompt message should have text content")
assertFalse(
"## Additional Context" in text,
"Result should not contain 'Additional Context' when no description is given",
)
}

@Test
fun suggestConceptsWithDescription() =
withClient(registerPrompts = { addSuggestConceptsPrompt() }) { client ->
val result =
client.getPrompt(
GetPromptRequest(
GetPromptRequestParams(
name = "suggest_concepts",
arguments =
mapOf("description" to "We have some additional context here."),
)
)
)

assertNotNull(result)
val text = (result.messages.firstOrNull()?.content as? TextContent)?.text
assertNotNull(text, "Prompt message should have text content")
assertTrue(
"## Additional Context" in text,
"Result should contain 'Additional Context' when description is provided",
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ import kotlinx.coroutines.withTimeout
* server and client.
*/
@OptIn(ExperimentalMcpApi::class)
fun withClient(registerTools: Server.() -> Unit = {}, test: suspend (Client) -> Unit) =
fun withClient(
registerTools: Server.() -> Unit = {},
registerPrompts: Server.() -> Unit = {},
test: suspend (Client) -> Unit,
): Unit =
runBlocking(Dispatchers.Default) {
val serverReady = CompletableDeferred<Unit>()

Expand All @@ -65,6 +69,7 @@ fun withClient(registerTools: Server.() -> Unit = {}, test: suspend (Client) ->

server.onConnect { serverReady.complete(Unit) }
server.registerTools()
server.registerPrompts()

val (clientTransport, serverTransport) = ChannelTransport.createLinkedPair()
val client = Client(Implementation(name = "test-client", version = "1.0.0"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ package de.fraunhofer.aisec.cpg.mcp.mcpserver
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addCpgAnalyzeTool
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addCpgApplyConceptsTool
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addCpgDataflowTool
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addCpgLlmAnalyzeTool
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addCpgTranslate
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addListPasses
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addRunPass
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.addSuggestConceptsPrompt
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.getAllArgs
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.getArgByIndexOrName
import de.fraunhofer.aisec.cpg.mcp.mcpserver.tools.listAvailableConcepts
Expand All @@ -48,11 +48,11 @@ import io.modelcontextprotocol.kotlin.sdk.types.ServerCapabilities

fun configureServer(
configure: Server.() -> Server = {
// TOOLS
this.addCpgTranslate()
this.addListPasses()
this.addRunPass()
this.addCpgAnalyzeTool()
this.addCpgLlmAnalyzeTool()
this.addCpgApplyConceptsTool()
this.addCpgDataflowTool()
this.listFunctions()
Expand All @@ -64,6 +64,8 @@ fun configureServer(
this.getAllArgs()
this.getArgByIndexOrName()
this.listConceptsAndOperations()
// PROMPTS
this.addSuggestConceptsPrompt()
this
}
): Server {
Expand Down
Loading
Loading