mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-13 11:53:07 +00:00
efcbdbb17f
## Summary Replace `github.com/mark3labs/mcp-go` with the official `github.com/modelcontextprotocol/go-sdk v1.7.0`. All 54 existing tools, scopes, CLI, `stdio` and HTTP (`/mcp`) modes, and per-request authentication remain supported. This PR is limited to the SDK equivalence migration; the stateless 2026 HTTP transport is deferred to a follow-up PR. ## Verification - Tool definitions were compared with `main` and matched for all 54 tools. - `make lint`, `make fmt`, `go test -count=1 -race ./...`, `make build`, and `make tidy` pass. --------- Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/223 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com> Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
120 lines
2.6 KiB
Go
120 lines
2.6 KiB
Go
package operation
|
|
|
|
import "testing"
|
|
|
|
func TestNewHTTPServerConfig(t *testing.T) {
|
|
server := newHTTPServer(":12345", newMCPServer("test"))
|
|
if server.Addr != ":12345" {
|
|
t.Errorf("Addr = %q, want %q", server.Addr, ":12345")
|
|
}
|
|
if server.Handler == nil {
|
|
t.Error("Handler is nil")
|
|
}
|
|
if server.ReadHeaderTimeout != httpReadHeaderTimeout {
|
|
t.Errorf("ReadHeaderTimeout = %v, want %v", server.ReadHeaderTimeout, httpReadHeaderTimeout)
|
|
}
|
|
if server.WriteTimeout != 0 {
|
|
t.Errorf("WriteTimeout = %v, want zero for SSE", server.WriteTimeout)
|
|
}
|
|
}
|
|
|
|
func TestParseAuthToken(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
header string
|
|
wantToken string
|
|
wantOK bool
|
|
}{
|
|
{
|
|
name: "valid Bearer token",
|
|
header: "Bearer validtoken",
|
|
wantToken: "validtoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "lowercase bearer",
|
|
header: "bearer lowercase",
|
|
wantToken: "lowercase",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "uppercase BEARER",
|
|
header: "BEARER uppercase",
|
|
wantToken: "uppercase",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "token with spaces trimmed",
|
|
header: "Bearer spacedToken ",
|
|
wantToken: "spacedToken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "bearer with no token",
|
|
header: "Bearer ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "bearer with only spaces",
|
|
header: "Bearer ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "missing space after Bearer",
|
|
header: "Bearertoken",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "Gitea token format",
|
|
header: "token giteaapitoken",
|
|
wantToken: "giteaapitoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "Gitea Token format capitalized",
|
|
header: "Token giteaapitoken",
|
|
wantToken: "giteaapitoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "token with no value",
|
|
header: "token ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "different auth type",
|
|
header: "Basic dXNlcjpwYXNz",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "empty header",
|
|
header: "",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "bearer token with internal spaces",
|
|
header: "Bearer token with spaces",
|
|
wantToken: "token with spaces",
|
|
wantOK: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotToken, gotOK := parseAuthToken(tt.header)
|
|
if gotToken != tt.wantToken {
|
|
t.Errorf("parseAuthToken() token = %q, want %q", gotToken, tt.wantToken)
|
|
}
|
|
if gotOK != tt.wantOK {
|
|
t.Errorf("parseAuthToken() ok = %v, want %v", gotOK, tt.wantOK)
|
|
}
|
|
})
|
|
}
|
|
}
|