This commit is contained in:
27
pkg/to/to.go
Normal file
27
pkg/to/to.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package to
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/log"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
func TextResult(v any) (*mcp.CallToolResult, error) {
|
||||
resultBytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal result err: %v", err)
|
||||
}
|
||||
if flag.Debug {
|
||||
log.Debugf("Text Result: %s", string(resultBytes))
|
||||
}
|
||||
return mcp.NewToolResultText(string(resultBytes)), nil
|
||||
}
|
||||
|
||||
func ErrorResult(err error) (*mcp.CallToolResult, error) {
|
||||
log.Errorf("%s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
Reference in New Issue
Block a user