-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Check AI models access to MCP servers and fix any issues #3
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,68 @@ | ||
| package com.dark.tool_neuron.service | ||
|
|
||
| import com.dark.tool_neuron.models.table_schema.McpServer | ||
| import org.json.JSONArray | ||
| import org.json.JSONObject | ||
|
|
||
| data class McpToolReference( | ||
| val server: McpServer, | ||
| val toolName: String | ||
| ) | ||
|
|
||
| data class McpToolMapping( | ||
| val toolsJson: String, | ||
| val toolRegistry: Map<String, McpToolReference> | ||
| ) | ||
|
|
||
| object McpToolMapper { | ||
| fun sanitizeIdentifier(value: String): String { | ||
| return value.lowercase() | ||
| .replace(Regex("[^a-z0-9]+"), "_") | ||
| .trim('_') | ||
| } | ||
|
|
||
| fun buildMapping(serverTools: Map<McpServer, List<McpToolInfo>>): McpToolMapping { | ||
| val toolsArray = JSONArray() | ||
| val registry = mutableMapOf<String, McpToolReference>() | ||
|
|
||
| serverTools.forEach { (server, tools) -> | ||
| val serverPrefix = sanitizeIdentifier(server.name).ifBlank { "mcp" } | ||
| tools.forEach { tool -> | ||
| val toolSlug = sanitizeIdentifier(tool.name).ifBlank { "tool" } | ||
| val toolId = "${serverPrefix}_${toolSlug}" | ||
| toolsArray.put(buildToolDefinition(toolId, tool)) | ||
| registry[toolId] = McpToolReference(server, tool.name) | ||
| } | ||
| } | ||
|
|
||
| return McpToolMapping( | ||
| toolsJson = toolsArray.toString(), | ||
| toolRegistry = registry | ||
| ) | ||
| } | ||
|
Comment on lines
+24
to
+42
|
||
|
|
||
| private fun buildToolDefinition(toolId: String, tool: McpToolInfo): JSONObject { | ||
| val function = JSONObject().apply { | ||
| put("name", toolId) | ||
| tool.description?.takeIf { it.isNotBlank() }?.let { put("description", it) } | ||
| put("parameters", buildParameters(tool.inputSchema)) | ||
| } | ||
|
|
||
| return JSONObject().apply { | ||
| put("type", "function") | ||
| put("function", function) | ||
| } | ||
| } | ||
|
|
||
| private fun buildParameters(inputSchema: String?): JSONObject { | ||
| val parsedSchema = inputSchema?.takeIf { it.isNotBlank() }?.let { | ||
| runCatching { JSONObject(it) }.getOrNull() | ||
| } | ||
|
|
||
| return (parsedSchema ?: JSONObject()).apply { | ||
| if (!has("type")) { | ||
| put("type", "object") | ||
| } | ||
| } | ||
| } | ||
| } | ||
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 ChatViewModelFactory changes in AppContainer appear to be unused since ChatViewModel is obtained via Hilt's hiltViewModel() in MainActivity (line 99). The factory pattern here is redundant when using @hiltviewmodel. Consider removing these factory-related changes to avoid confusion about which dependency injection mechanism is being used.