mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-03-18 19:05:12 +00:00
feat: slim tool responses (#141)
Reduce token usage by slimming tool responses. Instead of returning full Gitea SDK objects (with nested user/repo objects, avatars, permissions, etc.), each operation now has a colocated `slim.go` that extracts only the fields an LLM needs. List endpoints return even fewer fields than single-item endpoints.
Other changes:
- Add `params` helpers to DRY parameter extraction across 40+ handlers
- Remove `{"Result": ...}` wrapper for flatter responses
- Reduce default pageSize from 100 to 30
Fixes: https://gitea.com/gitea/gitea-mcp/issues/128
*Created by Claude on behalf of @silverwind*
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/141
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-committed-by: silverwind <me@silverwind.io>
This commit is contained in:
42
operation/user/slim.go
Normal file
42
operation/user/slim.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
gitea_sdk "code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
func slimUserDetail(u *gitea_sdk.User) map[string]any {
|
||||
if u == nil {
|
||||
return nil
|
||||
}
|
||||
return map[string]any{
|
||||
"id": u.ID,
|
||||
"login": u.UserName,
|
||||
"full_name": u.FullName,
|
||||
"email": u.Email,
|
||||
"avatar_url": u.AvatarURL,
|
||||
"html_url": u.HTMLURL,
|
||||
"is_admin": u.IsAdmin,
|
||||
}
|
||||
}
|
||||
|
||||
func slimOrg(o *gitea_sdk.Organization) map[string]any {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return map[string]any{
|
||||
"id": o.ID,
|
||||
"name": o.Name,
|
||||
"full_name": o.FullName,
|
||||
"description": o.Description,
|
||||
"avatar_url": o.AvatarURL,
|
||||
"website": o.Website,
|
||||
}
|
||||
}
|
||||
|
||||
func slimOrgs(orgs []*gitea_sdk.Organization) []map[string]any {
|
||||
out := make([]map[string]any, 0, len(orgs))
|
||||
for _, o := range orgs {
|
||||
out = append(out, slimOrg(o))
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user