Skip to content

Used multiple chunks of WHO(not properly fomatted) to provide context to AI system #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

patel-tanu
Copy link

@patel-tanu patel-tanu commented May 5, 2025

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@e5l
Copy link
Contributor

e5l commented May 6, 2025

Hey @patel-tanu, thanks for the PR. The idea looks good, but it needs to be polished a bit before merging 🙂

@e5l e5l requested review from Copilot and e5l and removed request for e5l May 8, 2025 06:51
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR provides additional WHO guideline resources in text format to supply context for nutritional interventions in the MCP system while also extending the MCP server/client code to load and expose these resource files.

  • Added multiple WHO guideline resource files covering nutritional interventions, zinc, vitamin A, and calcium supplements.
  • Enhanced MCPWeatherServer and MCPClient to dynamically load and incorporate these resources into server capabilities and context messages.

Reviewed Changes

Copilot reviewed 9 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
resources/who_guidelines_nutritional_interventions_anc.txt Added detailed WHO guidelines on nutritional interventions for pregnant women.
resources/who_ANC_Guideline_Zinc_supplements.txt Introduced WHO zinc supplement guidelines resource file.
resources/who_ANC_Guideline_Vitamin_A_Supplements.txt Included WHO vitamin A supplement guidelines as a new resource.
resources/who_ANC_Guideline_Calcium_supplements.txt Added a new resource with calcium supplement guidelines.
McpWeatherServer.kt Updated server capabilities to include resource subscriptions and added code for loading resource files.
MCPClient.kt Enhanced client code to read loaded resources and prepend them to conversation messages.
build.gradle.kts Minor dependency spacing update.
Files not reviewed (6)
  • .idea/artifacts/kotlin_sdk_jvm_0_4_0.xml: Language not supported
  • .idea/codeStyles/Project.xml: Language not supported
  • .idea/codeStyles/codeStyleConfig.xml: Language not supported
  • .idea/gradle.xml: Language not supported
  • .idea/kotlinc.xml: Language not supported
  • .idea/misc.xml: Language not supported

Comment on lines +122 to +127
// Triple("file:///C:/Users/tanu0/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/context-files/Iron_folic_acid_supplements_who_guidelines.txt", "Iron folic acid supplement by who for pregnant women", "C:\\Users\\tanu0\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\context-files\\Iron_folic_acid_supplements_who_guidelines.txt"),
// Triple("file:///C:/Users/tanu0/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/context-files/nutritional_intervention_who_guidelines.txt", "nutritional intervention guidelines by WHO", "C:\\Users\\tanu0\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\context-files\\nutritional_intervention_who_guidelines.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Calcium_supplements.txt", "who ANC Guideline Calcium supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Calcium_supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Zinc_supplements.txt", "who ANC Guideline Zinc supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Zinc_supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Vitamin_A_Supplements.txt", "who ANC Guideline Vitamin A Supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Vitamin_A_Supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_guidelines_nutritional_interventions_anc.txt", "who guidelines nutritional interventions anc", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_guidelines_nutritional_interventions_anc.txt")
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using relative or configurable file paths instead of hard-coded absolute paths for resource files to improve cross-platform compatibility and maintainability.

Suggested change
// Triple("file:///C:/Users/tanu0/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/context-files/Iron_folic_acid_supplements_who_guidelines.txt", "Iron folic acid supplement by who for pregnant women", "C:\\Users\\tanu0\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\context-files\\Iron_folic_acid_supplements_who_guidelines.txt"),
// Triple("file:///C:/Users/tanu0/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/context-files/nutritional_intervention_who_guidelines.txt", "nutritional intervention guidelines by WHO", "C:\\Users\\tanu0\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\context-files\\nutritional_intervention_who_guidelines.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Calcium_supplements.txt", "who ANC Guideline Calcium supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Calcium_supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Zinc_supplements.txt", "who ANC Guideline Zinc supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Zinc_supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Vitamin_A_Supplements.txt", "who ANC Guideline Vitamin A Supplements", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_ANC_Guideline_Vitamin_A_Supplements.txt"),
Triple("file:///C:/Users/developer/Downloads/kotlin-sdk/samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_guidelines_nutritional_interventions_anc.txt", "who guidelines nutritional interventions anc", "C:\\Users\\developer\\Downloads\\kotlin-sdk\\samples\\weather-stdio-server\\src\\main\\kotlin\\io\\modelcontextprotocol\\sample\\server\\resources\\who_guidelines_nutritional_interventions_anc.txt")
Triple(
"file://${Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Calcium_supplements.txt").toUri()}",
"who ANC Guideline Calcium supplements",
Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Calcium_supplements.txt").toString()
),
Triple(
"file://${Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Zinc_supplements.txt").toUri()}",
"who ANC Guideline Zinc supplements",
Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Zinc_supplements.txt").toString()
),
Triple(
"file://${Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Vitamin_A_Supplements.txt").toUri()}",
"who ANC Guideline Vitamin A Supplements",
Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_ANC_Guideline_Vitamin_A_Supplements.txt").toString()
),
Triple(
"file://${Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_guidelines_nutritional_interventions_anc.txt").toUri()}",
"who guidelines nutritional interventions anc",
Paths.get("src/main/kotlin/io/modelcontextprotocol/sample/server/resources/who_guidelines_nutritional_interventions_anc.txt").toString()
)

Copilot uses AI. Check for mistakes.

val messages = mutableListOf(

// / Prepend resources as SYSTEM message if they are loaded
if (resourceContents.isNotEmpty()) {
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] For clarity of role semantics, consider using MessageParam.Role.SYSTEM instead of ASSISTANT when prepending reference resources as context to the conversation.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@devcrocod devcrocod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pay attention to the comments

Comment on lines +27 to +30

private val anthropic = AnthropicOkHttpClient.builder()
.apiKey(System.getenv("ANTHROPIC_API_KEY") )
.build()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these changes necessary? AnthropicOkHttpClient.fromEnv() looks for ANTHROPIC_API_KEY in the environment variables by default

mcp.connect(transport)

// Request the list of available tools from the server
// List tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, it’s better to keep detailed comments in the example. For new users, a comment like List tools doesn’t provide any additional information

Comment on lines +158 to +208
// val assistantReply = response.content().firstOrNull()?.text()?.getOrNull()?.text()


// val finalText = mutableListOf<String>()
// response.content().forEach { content ->
// when {
// // Append text outputs from the response
// content.isText() -> finalText.add(content.text().getOrNull()?.text() ?: "")
//
// // If the response indicates a tool use, process it further
// content.isToolUse() -> {
// val toolName = content.toolUse().get().name()
// val toolArgs =
// content.toolUse().get()._input().convert(object : TypeReference<Map<String, JsonValue>>() {})
//
// // Call the tool with provided arguments
// val result = mcp.callTool(
// name = toolName,
// arguments = toolArgs ?: emptyMap()
// )
// finalText.add("[Calling tool $toolName with args $toolArgs]")
//
// // Add the tool result message to the conversation
// messages.add(
// MessageParam.builder()
// .role(MessageParam.Role.USER)
// .content(
// """
// "type": "tool_result",
// "tool_name": $toolName,
// "result": ${result?.content?.joinToString("\n") { (it as TextContent).text ?: "" }}
// """.trimIndent()
// )
// .build()
// )
//
// // Retrieve an updated response after tool execution
// val aiResponse = anthropic.messages().create(
// messageParamsBuilder
// .messages(messages)
// .build()
// )
//
// // Append the updated response to final text
// finalText.add(aiResponse.content().first().text().getOrNull()?.text() ?: "")
// }
// }
// }
//
// return finalText.joinToString("\n", prefix = "", postfix = "")
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment in the code explaining what this part does and why it is commented out

Comment on lines +15 to +41

//fun main(args: Array<String>) = runBlocking {
// if (args.isEmpty()) {
// println("Please provide the path to the MCP server script as a command-line argument.")
// return@runBlocking
// }
//
// val serverScriptPath = args[0]
// MCPClient().use { client ->
// try {
// client.connectToServer(serverScriptPath)
// client.chatLoop()
// } catch (e: Exception) {
// println("Error: ${e.message}")
// e.printStackTrace()
// }
// }
//}


//fun main() = runBlocking {
// val client = MCPClient()
// client.connectToServer(System.getenv("SERVER_PATH")!!)
// client.chatLoop()
//}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave only one main function and remove all the commented-out code

@@ -110,6 +118,35 @@ fun `run mcp server`() {
CallToolResult(content = forecast.map { TextContent(it) })
}

val files = listOf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these files have to do with the MCP weather server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants