From ea53c3a6c1f34cde94b26d10359a04ba55ee68ed Mon Sep 17 00:00:00 2001 From: GitCaddy Date: Mon, 12 Jan 2026 00:30:04 +0000 Subject: [PATCH] fix(mcp): use json.RawMessage for proper JSON unmarshaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add RawMessage type alias to modules/json and use it in MCP handler. The custom RawMessage type was not implementing json.Unmarshaler, causing parse errors when receiving MCP tool calls with params object. 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 --- modules/json/json.go | 4 ++++ routers/api/v2/mcp.go | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/json/json.go b/modules/json/json.go index d053f91cf7..26942cd2b6 100644 --- a/modules/json/json.go +++ b/modules/json/json.go @@ -109,3 +109,7 @@ func UnmarshalHandleDoubleEncode(bs []byte, v any) error { } return err } + +// RawMessage is a raw encoded JSON value. +// It implements Marshaler and Unmarshaler and can be used to delay JSON decoding. +type RawMessage = json.RawMessage diff --git a/routers/api/v2/mcp.go b/routers/api/v2/mcp.go index 9b0622b367..6093d45764 100644 --- a/routers/api/v2/mcp.go +++ b/routers/api/v2/mcp.go @@ -22,16 +22,13 @@ import ( "code.gitea.io/gitea/services/context" ) -// RawMessage is a raw encoded JSON value (equivalent to encoding/json.RawMessage) -type RawMessage []byte - // MCP Protocol Types (JSON-RPC 2.0) type MCPRequest struct { - JSONRPC string `json:"jsonrpc"` - ID any `json:"id"` - Method string `json:"method"` - Params RawMessage `json:"params,omitempty"` + JSONRPC string `json:"jsonrpc"` + ID any `json:"id"` + Method string `json:"method"` + Params json.RawMessage `json:"params,omitempty"` } type MCPResponse struct {