-
Notifications
You must be signed in to change notification settings - Fork 0
Add MCP server integration tests #5
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,235 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| package com.dark.tool_neuron.integration | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import com.dark.tool_neuron.models.table_schema.McpServer | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.dark.tool_neuron.models.table_schema.McpTransportType | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.dark.tool_neuron.service.McpToolInfo | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.dark.tool_neuron.service.McpToolMapper | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.json.JSONArray | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.json.JSONObject | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.Assert.* | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.Test | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Unit tests for MCP server-related functionality. | ||||||||||||||||||||||||||||||||||||||||||||||||
| * These tests validate McpToolMapper functionality, JSON parsing, | ||||||||||||||||||||||||||||||||||||||||||||||||
| * and configuration objects without connecting to real MCP servers. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| class McpServerTest { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Helper function to parse SSE response format. | ||||||||||||||||||||||||||||||||||||||||||||||||
| // This is a simplified version for tests that extracts JSON from single-event SSE responses. | ||||||||||||||||||||||||||||||||||||||||||||||||
| // The production code in McpClientService.parseSseResponse() handles multiple events and validates JSON. | ||||||||||||||||||||||||||||||||||||||||||||||||
| private fun parseSseData(sseResponse: String): String { | ||||||||||||||||||||||||||||||||||||||||||||||||
| val dataLine = sseResponse.lines().find { it.startsWith("data:") } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ?: return sseResponse | ||||||||||||||||||||||||||||||||||||||||||||||||
| return dataLine.removePrefix("data:").trim() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Test that McpServer can be created with the correct configuration | ||||||||||||||||||||||||||||||||||||||||||||||||
| * for connecting to Zapier's MCP endpoint. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||
| fun createZapierMcpServerConfiguration() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| val zapierUrl = "https://mcp.zapier.com/api/v1/connect?token=example-token" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| val server = McpServer( | ||||||||||||||||||||||||||||||||||||||||||||||||
| id = McpServer.generateId(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| name = "Zapier MCP", | ||||||||||||||||||||||||||||||||||||||||||||||||
| url = zapierUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||
| transportType = McpTransportType.SSE, | ||||||||||||||||||||||||||||||||||||||||||||||||
| apiKey = null, // Token is in URL | ||||||||||||||||||||||||||||||||||||||||||||||||
| description = "Zapier MCP integration for Google Docs tools" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(server.id) | ||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals("Zapier MCP", server.name) | ||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(zapierUrl, server.url) | ||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(McpTransportType.SSE, server.transportType) | ||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(server.isEnabled) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+51
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | |
| * Test that McpServer can be created with the correct configuration | |
| * for connecting to Zapier's MCP endpoint. | |
| */ | |
| @Test | |
| fun createZapierMcpServerConfiguration() { | |
| val zapierUrl = "https://mcp.zapier.com/api/v1/connect?token=example-token" | |
| val server = McpServer( | |
| id = McpServer.generateId(), | |
| name = "Zapier MCP", | |
| url = zapierUrl, | |
| transportType = McpTransportType.SSE, | |
| apiKey = null, // Token is in URL | |
| description = "Zapier MCP integration for Google Docs tools" | |
| ) | |
| assertNotNull(server.id) | |
| assertEquals("Zapier MCP", server.name) | |
| assertEquals(zapierUrl, server.url) | |
| assertEquals(McpTransportType.SSE, server.transportType) | |
| assertTrue(server.isEnabled) | |
| } |
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.
The URL
https://mcp.zapier.com/api/v1/connectis used in multiple tests (createZapierMcpServerConfiguration,mapZapierToolsToLlmFormat,identifyZapierTransportType). It would be beneficial to extract it into acompanion objectconstant to avoid repetition and improve maintainability. For example:You can then use this constant throughout the test class, appending the token where necessary.