feat(tools): repo_get

This commit is contained in:
Mathias Bergqvist
2026-05-04 22:08:24 +02:00
parent 33ad02d369
commit f10cc9ac4b
3 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
package tools
import (
"context"
"encoding/json"
"gitea.d-ma.be/mathias/gitea-mcp/internal/allowlist"
"gitea.d-ma.be/mathias/gitea-mcp/internal/gitea"
"gitea.d-ma.be/mathias/gitea-mcp/internal/registry"
)
type RepoGet struct {
c *gitea.Client
a *allowlist.Allowlist
}
func NewRepoGet(c *gitea.Client, a *allowlist.Allowlist) *RepoGet { return &RepoGet{c: c, a: a} }
func (t *RepoGet) Descriptor() registry.ToolDescriptor {
return registry.ToolDescriptor{
Name: "repo_get",
Description: "Get a repo's metadata.",
InputSchema: json.RawMessage(`{
"type":"object",
"properties":{"owner":{"type":"string"},"name":{"type":"string"}},
"required":["owner","name"]
}`),
}
}
type repoGetArgs struct {
Owner string `json:"owner"`
Name string `json:"name"`
}
func (t *RepoGet) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
var args repoGetArgs
if err := parseArgs(raw, &args); err != nil {
return nil, err
}
if err := t.a.Check(args.Owner); err != nil {
return nil, err
}
r, err := t.c.GetRepo(ctx, args.Owner, args.Name)
if err != nil {
return nil, err
}
return textOK(r)
}