mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-27 02:27:45 +00:00
3c6d2ecd6b
Adds a new issue_read method that fetches an issue and its comments and renders them as a single Markdown document, instead of a JSON array. Formatting logic lives in a pure, unit-tested helper (formatDiscussionMarkdown) covering comment rendering, empty comment lists, and attachment-inlined bodies. Existing get/get_comments/ get_labels methods are unchanged. Co-Authored-By: Codet <codet@commitgo.dev> (GPT-5-Codex)
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package to
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
|
"gitea.com/gitea/gitea-mcp/pkg/log"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/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.CallToolResult{
|
|
Content: []mcp.Content{&mcp.TextContent{Text: string(resultBytes)}},
|
|
}, nil
|
|
}
|
|
|
|
// RawTextResult returns text as-is, without JSON-encoding it. Use it for
|
|
// content that is already meant to be read directly, such as Markdown.
|
|
func RawTextResult(text string) (*mcp.CallToolResult, error) {
|
|
if flag.Debug {
|
|
log.Debugf("Text Result: %s", text)
|
|
}
|
|
return &mcp.CallToolResult{
|
|
Content: []mcp.Content{&mcp.TextContent{Text: text}},
|
|
}, nil
|
|
}
|
|
|
|
func ErrorResult(err error) (*mcp.CallToolResult, error) {
|
|
log.Errorf("%s", err.Error())
|
|
var result mcp.CallToolResult
|
|
result.SetError(err)
|
|
return &result, nil
|
|
}
|