feat(mcp): jsonrpc envelope types and error codes
This commit is contained in:
26
internal/mcp/jsonrpc_test.go
Normal file
26
internal/mcp/jsonrpc_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package mcp_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"gitea.d-ma.be/mathias/gitea-mcp/internal/mcp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRequestUnmarshal(t *testing.T) {
|
||||
raw := []byte(`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}`)
|
||||
var req mcp.Request
|
||||
require.NoError(t, json.Unmarshal(raw, &req))
|
||||
assert.Equal(t, "2.0", req.JSONRPC)
|
||||
assert.Equal(t, "initialize", req.Method)
|
||||
}
|
||||
|
||||
func TestErrorResponseShape(t *testing.T) {
|
||||
resp := mcp.NewErrorResponse(1, mcp.CodePermissionDenied, "no", nil)
|
||||
b, _ := json.Marshal(resp)
|
||||
assert.JSONEq(t,
|
||||
`{"jsonrpc":"2.0","id":1,"error":{"code":-32001,"message":"no"}}`,
|
||||
string(b))
|
||||
}
|
||||
Reference in New Issue
Block a user