convertMCPToolToOpenAI
(mcpTool mcp.Tool)
| 682 | |
| 683 | // convertMCPToolToOpenAI |
| 684 | func (c *AIController) convertMCPToolToOpenAI(mcpTool mcp.Tool) openai.Tool { |
| 685 | properties := make(map[string]any) |
| 686 | required := make([]string, 0) |
| 687 | |
| 688 | maps.Copy(properties, mcpTool.InputSchema.Properties) |
| 689 | |
| 690 | required = append(required, mcpTool.InputSchema.Required...) |
| 691 | |
| 692 | parameters := map[string]any{ |
| 693 | "type": "object", |
| 694 | "properties": properties, |
| 695 | } |
| 696 | |
| 697 | if len(required) > 0 { |
| 698 | parameters["required"] = required |
| 699 | } |
| 700 | |
| 701 | return openai.Tool{ |
| 702 | Type: openai.ToolTypeFunction, |
| 703 | Function: &openai.FunctionDefinition{ |
| 704 | Name: mcpTool.Name, |
| 705 | Description: mcpTool.Description, |
| 706 | Parameters: parameters, |
| 707 | }, |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // callMCPTool |
| 712 | func (c *AIController) callMCPTool(ctx context.Context, toolName string, arguments map[string]any) (string, error) { |