- Introduced `image_generate` tool for generating images from text prompts, with options for specifying output file paths and image dimensions. - Updated `image_read` functionality to allow optional provider specification for enhanced image analysis. - Implemented new `GenerateImage` method in the LLM API for seamless integration of image generation capabilities. - Enhanced documentation to include detailed usage examples for both image reading and generation tools. - Updated tests to validate new image generation features and ensure robust functionality across image tools.
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package tools
|
|
|
|
import (
|
|
_ "embed"
|
|
"encoding/json"
|
|
|
|
"github.com/yaoapp/gou/mcp"
|
|
mcpTypes "github.com/yaoapp/gou/mcp/types"
|
|
"github.com/yaoapp/gou/process"
|
|
"github.com/yaoapp/kun/log"
|
|
"github.com/yaoapp/yao/tools/docs"
|
|
"github.com/yaoapp/yao/tools/image"
|
|
"github.com/yaoapp/yao/tools/proc"
|
|
"github.com/yaoapp/yao/tools/webfetch"
|
|
"github.com/yaoapp/yao/tools/websearch"
|
|
)
|
|
|
|
//go:embed mcps/web.json
|
|
var mcpWebDSL []byte
|
|
|
|
//go:embed mcps/process.json
|
|
var mcpProcessDSL []byte
|
|
|
|
//go:embed mcps/doc.json
|
|
var mcpDocDSL []byte
|
|
|
|
//go:embed mcps/image.json
|
|
var mcpImageDSL []byte
|
|
|
|
func init() {
|
|
process.RegisterGroup("tools", map[string]process.Handler{
|
|
"web_search": websearch.Handler,
|
|
"web_fetch": webfetch.Handler,
|
|
"process_call": proc.Handler,
|
|
"process_allowed": proc.AllowedHandler,
|
|
"doc_list": docs.ListHandler,
|
|
"doc_inspect": docs.InspectHandler,
|
|
"doc_validate": docs.ValidateHandler,
|
|
"image_read": image.ReadHandler,
|
|
"image_generate": image.GenerateHandler,
|
|
"image_providers": image.ProvidersHandler,
|
|
})
|
|
|
|
registerMCPServer(mcpWebDSL, "yao-web",
|
|
websearch.SchemaJSON, webfetch.SchemaJSON)
|
|
registerMCPServer(mcpProcessDSL, "yao-process",
|
|
proc.SchemaJSON, proc.AllowedSchemaJSON)
|
|
registerMCPServer(mcpDocDSL, "yao-doc",
|
|
docs.ListSchemaJSON, docs.InspectSchemaJSON, docs.ValidateSchemaJSON)
|
|
registerMCPServer(mcpImageDSL, "yao-image",
|
|
image.ReadSchemaJSON, image.GenerateSchemaJSON, image.ProvidersSchemaJSON)
|
|
}
|
|
|
|
func registerMCPServer(dsl []byte, id string, schemas ...[]byte) {
|
|
mapping := &mcpTypes.MappingData{
|
|
Tools: map[string]*mcpTypes.ToolSchema{},
|
|
Resources: map[string]*mcpTypes.ResourceSchema{},
|
|
Prompts: map[string]*mcpTypes.PromptSchema{},
|
|
}
|
|
for _, raw := range schemas {
|
|
var s mcpTypes.ToolSchema
|
|
if err := json.Unmarshal(raw, &s); err != nil {
|
|
log.Error("[tools] failed to parse schema: %s", err.Error())
|
|
continue
|
|
}
|
|
mapping.Tools[s.Name] = &s
|
|
}
|
|
if _, err := mcp.LoadClientSourceWithType(string(dsl), id, "", mapping); err != nil {
|
|
log.Error("[tools] failed to register MCP server %s: %s", id, err.Error())
|
|
}
|
|
}
|