-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ai): Improve tool metadata handling
- Loading branch information
1 parent
d1cf816
commit 3981a66
Showing
5 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 31 additions & 4 deletions
35
arconia-ai/arconia-ai-mcp/src/main/java/io/arconia/ai/mcp/tools/McpToolCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,45 @@ | ||
package io.arconia.ai.mcp.tools; | ||
|
||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import org.springframework.ai.mcp.client.McpSyncClient; | ||
import org.springframework.ai.mcp.spec.McpSchema; | ||
import org.springframework.ai.mcp.spring.McpFunctionCallback; | ||
import org.springframework.ai.model.ModelOptionsUtils; | ||
|
||
import io.arconia.ai.core.tools.ToolCallback; | ||
import io.arconia.ai.core.tools.json.JsonParser; | ||
import io.arconia.ai.core.tools.metadata.DefaultToolMetadata; | ||
import io.arconia.ai.core.tools.metadata.ToolMetadata; | ||
|
||
/** | ||
* A {@link ToolCallback} for handling calls to MCP tools. | ||
*/ | ||
public class McpToolCallback extends McpFunctionCallback implements ToolCallback { | ||
public class McpToolCallback implements ToolCallback { | ||
|
||
private final ToolMetadata toolMetadata; | ||
private final McpSyncClient mcpClient; | ||
|
||
public McpToolCallback(McpSchema.Tool tool, McpSyncClient mcpClient) { | ||
this.toolMetadata = DefaultToolMetadata.builder() | ||
.name(tool.name()) | ||
.description(tool.description()) | ||
.inputTypeSchema(JsonParser.toJson(tool.inputSchema())) | ||
.build(); | ||
this.mcpClient = mcpClient; | ||
} | ||
|
||
@Override | ||
public ToolMetadata getToolMetadata() { | ||
return this.toolMetadata; | ||
} | ||
|
||
public McpToolCallback(McpSyncClient mcpClient, McpSchema.Tool tool) { | ||
super(mcpClient, tool); | ||
@Override | ||
public String call(String toolInput) { | ||
Map<String, Object> arguments = JsonParser.fromJson(toolInput, new TypeReference<>() {}); | ||
McpSchema.CallToolResult response = this.mcpClient.callTool(new McpSchema.CallToolRequest(this.getName(), arguments)); | ||
return ModelOptionsUtils.toJsonString(response.content()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters