-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: main
Are you sure you want to change the base?
Used multiple chunks of WHO(not properly fomatted) to provide context to AI system #98
Conversation
Hey @patel-tanu, thanks for the PR. The idea looks good, but it needs to be polished a bit before merging 🙂 |
There was a problem hiding this 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
// 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") |
There was a problem hiding this comment.
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.
// 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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
|
||
private val anthropic = AnthropicOkHttpClient.builder() | ||
.apiKey(System.getenv("ANTHROPIC_API_KEY") ) | ||
.build() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
// 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 = "") | ||
// } |
There was a problem hiding this comment.
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
|
||
//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() | ||
//} | ||
|
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
Motivation and Context
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context