Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .govulncheck.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
ignored-vulnerabilities:
# MCP Go SDK Vulnerable to Improper Handling of Case Sensitivity in github.com/modelcontextprotocol/go-sdk
# Found in: github.com/modelcontextprotocol/go-sdk/mcp@v1.2.0
# Fixed in: github.com/modelcontextprotocol/go-sdk/mcp@v1.3.1
- id: GO-2026-4569
info: https://pkg.go.dev/vuln/GO-2026-4569
silence-until: 2026-04-22
# Incorrect parsing of IPv6 host literals in net/url
# Found in: net/url@go1.24.13
# Fixed in: net/url@go1.25.8
Expand Down
3 changes: 2 additions & 1 deletion cmd/start_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ var startServerCmd = &cobra.Command{
mux.Handle("/mcp", mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
return srv
}, &mcp.StreamableHTTPOptions{
Stateless: stateless,
Stateless: stateless,
DisableLocalhostProtection: true,
}))

// Metrics endpoint
Expand Down
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
module github.com/codeready-toolchain/argocd-mcp-server

go 1.24.13
go 1.24.6

toolchain go1.24.13

require (
github.com/argoproj/argo-cd/v3 v3.1.11
github.com/argoproj/gitops-engine v0.7.1-0.20250905160054-e48120133eec
github.com/codeready-toolchain/mcp-common v0.0.0-20260311065550-14ceedd27660
github.com/codeready-toolchain/toolchain-e2e v0.0.0-20260112152755-eb77a8e22ccb
github.com/google/jsonschema-go v0.3.0
github.com/google/jsonschema-go v0.4.2
github.com/h2non/gock v1.2.0
github.com/modelcontextprotocol/go-sdk v1.2.0
github.com/modelcontextprotocol/go-sdk v1.4.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Security: mcp-go-sdk v1.4.0 has known HIGH severity vulnerabilities.

The static analysis tools have flagged two HIGH severity vulnerabilities in github.com/modelcontextprotocol/go-sdk v1.4.0:

  1. GHSA-89xv-2j6f-qhc8 (CSRF): "The Go SDK's Streamable HTTP transport accepted browser-generated cross-site POST requests without validating the Origin header and without requiring …"

  2. GHSA-q382-vc8q-7jhj (JSON Key Collusion): "The Model Context Protocol (MCP) Go SDK, via its dependency on segmentio/encoding, is vulnerable to JSON Key Collusion. The JSON parser improperly handles null Unicode characters during struct field mapping, allowing attackers to smuggle overriding keys past security filters and manipulate backend application logic."

Both vulnerabilities are fixed in v1.4.1. While the PR description notes v1.4.1 requires Go 1.25, consider:

  • Adding a comment in go.mod documenting this known limitation
  • Creating a tracking issue to upgrade once Go 1.25 is available
  • Evaluating if additional mitigations (e.g., authentication, rate limiting) can reduce the risk while pinned to v1.4.0
🧰 Tools
🪛 OSV Scanner (2.3.3)

[HIGH] 14-14: github.com/modelcontextprotocol/go-sdk 1.4.0: Cross-Site Tool Execution for HTTP Servers without Authorizatrion in github.com/modelcontextprotocol/go-sdk

(GHSA-89xv-2j6f-qhc8)


[HIGH] 14-14: github.com/modelcontextprotocol/go-sdk 1.4.0: Improper handling of null Unicode character when parsing JSON in github.com/modelcontextprotocol/go-sdk

(GHSA-q382-vc8q-7jhj)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go.mod` at line 14, The dependency line
"github.com/modelcontextprotocol/go-sdk v1.4.0" is flagged with two HIGH
vulnerabilities; update go.mod by adding a clear comment above that dependency
noting the vulnerabilities (GHSA-89xv-2j6f-qhc8 and GHSA-q382-vc8q-7jhj), that
v1.4.1 fixes them but requires Go 1.25, and that upgrade is deferred until the
toolchain is available; create a tracking issue (reference the GHSA IDs and
v1.4.1) to perform the upgrade when Go 1.25 is adopted, and add a short note in
the repo (README or SECURITY.md) listing temporary mitigations to apply while
pinned to v1.4.0 (e.g., enforce CSRF protections, tighten auth/rate-limiting) so
reviewers can find and act on these items.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
github.com/modelcontextprotocol/go-sdk v1.4.0
github.com/modelcontextprotocol/go-sdk v1.4.1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let me open another PR for to upgrade to github.com/modelcontextprotocol/go-sdk v1.4.1 and hence, to Go 1.25

github.com/prometheus/client_golang v1.22.0
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.9
Expand Down Expand Up @@ -65,7 +67,7 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
Expand Down Expand Up @@ -113,6 +115,8 @@ require (
github.com/redis/go-redis/v9 v9.8.0 // indirect
github.com/robfig/cron/v3 v3.0.2-0.20210106135023-bc59245fe10e // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/segmentio/asm v1.1.3 // indirect
github.com/segmentio/encoding v0.5.4 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
Expand All @@ -131,7 +135,7 @@ require (
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.12.0 // indirect
Expand Down
24 changes: 14 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
Expand All @@ -174,8 +174,8 @@ github.com/google/go-github/v72 v72.0.0/go.mod h1:WWtw8GMRiL62mvIquf1kO3onRHeWWK
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q=
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbcqoRA8=
github.com/google/jsonschema-go v0.4.2/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
Expand Down Expand Up @@ -245,8 +245,8 @@ github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
github.com/modelcontextprotocol/go-sdk v1.2.0 h1:Y23co09300CEk8iZ/tMxIX1dVmKZkzoSBZOpJwUnc/s=
github.com/modelcontextprotocol/go-sdk v1.2.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
github.com/modelcontextprotocol/go-sdk v1.4.0 h1:u0kr8lbJc1oBcawK7Df+/ajNMpIDFE41OEPxdeTLOn8=
github.com/modelcontextprotocol/go-sdk v1.4.0/go.mod h1:Nxc2n+n/GdCebUaqCOhTetptS17SXXNu9IfNTaLDi1E=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -326,6 +326,10 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/segmentio/asm v1.1.3 h1:WM03sfUOENvvKexOLp+pCqgb/WDjsi7EK8gIsICtzhc=
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
Expand Down Expand Up @@ -464,8 +468,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -495,8 +499,8 @@ golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
51 changes: 34 additions & 17 deletions internal/argocd/unhealthy_application_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"reflect"

argocdv3 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var UnhealthyResourcesPrompt = &mcp.Prompt{
Expand Down Expand Up @@ -56,26 +59,40 @@ func UnhealthyApplicationResourcesPromptHandle(logger *slog.Logger, cl *Client)
}
}

var UnhealthyApplicationResourcesTool = &mcp.Tool{
Name: "argocd_list_unhealthy_application_resources",
Description: "list unhealthy resources of a given Argo CD Application",
InputSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"name": {
Type: "string",
Description: "the name of the Argo CD Application to get details of",
},
},
Required: []string{"name"},
},
OutputSchema: UnhealthyApplicationResourcesOutputSchema,
var UnhealthyApplicationResourcesTool *mcp.Tool

type UnhealthyApplicationResourcesInput struct {
Name string `json:"name" jsonschema:"the name of the Argo CD Application to get details of"`
}

var UnhealthyApplicationResourcesOutputSchema, _ = jsonschema.For[UnhealthyApplicationResourcesOutput](&jsonschema.ForOptions{})
var UnhealthyApplicationResourcesInputSchema *jsonschema.Schema
var UnhealthyApplicationResourcesOutputSchema *jsonschema.Schema

type UnhealthyApplicationResourcesInput struct {
Name string `json:"name"`
func init() {
var err error
// create the input schema
UnhealthyApplicationResourcesInputSchema, err = jsonschema.For[UnhealthyApplicationResourcesInput](&jsonschema.ForOptions{})
if err != nil {
log.Fatalf("failed to create UnhealthyApplicationResourcesInputSchema: %v", err.Error())
}
log.Println("UnhealthyApplicationResourcesInputSchema initialized")
// create the output schema
UnhealthyApplicationResourcesOutputSchema, err = jsonschema.For[UnhealthyApplicationResourcesOutput](&jsonschema.ForOptions{
TypeSchemas: map[reflect.Type]*jsonschema.Schema{
reflect.TypeFor[metav1.Time](): {
Type: "string", // see https://github.com/modelcontextprotocol/go-sdk/pull/470
},
},
})
if err != nil {
log.Fatalf("failed to create UnhealthyApplicationResourcesOutputSchema: %v", err.Error())
}
UnhealthyApplicationResourcesTool = &mcp.Tool{
Name: "argocd_list_unhealthy_application_resources",
Description: "list unhealthy resources of a given Argo CD Application",
InputSchema: UnhealthyApplicationResourcesInputSchema,
OutputSchema: UnhealthyApplicationResourcesOutputSchema,
}
}

type UnhealthyApplicationResourcesOutput UnhealthyResources
Expand Down
22 changes: 22 additions & 0 deletions internal/argocd/unhealthy_application_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"log/slog"
"os"
"reflect"
"testing"

testresources "github.com/codeready-toolchain/argocd-mcp-server/test/resources"

argocdv3 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/google/jsonschema-go/jsonschema"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestListUnhealthyApplicationResources(t *testing.T) {
Expand Down Expand Up @@ -92,3 +95,22 @@ func TestListUnhealthyApplicationResources(t *testing.T) {
assert.EqualError(t, err, "unexpected 500 response for GET http://argocd.example.com/api/v1/applications?name=example: mock error!")
})
}

func TestUnhealthyApplicationResourcesSchemas(t *testing.T) {

t.Run("output schema", func(t *testing.T) {
// when
schema, err := jsonschema.For[UnhealthyApplicationResourcesOutput](&jsonschema.ForOptions{
TypeSchemas: map[reflect.Type]*jsonschema.Schema{
// reflect.TypeFor[UnhealthyResources](): resourcesStatusSchema,
reflect.TypeFor[metav1.Time](): {
Type: "string", // see https://github.com/modelcontextprotocol/go-sdk/pull/470
},
},
})

// then
require.NoError(t, err)
assert.Equal(t, UnhealthyApplicationResourcesOutputSchema, schema)
})
}
37 changes: 26 additions & 11 deletions internal/argocd/unhealthy_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package argocd
import (
"context"
"encoding/json"
"log"
"log/slog"

"github.com/google/jsonschema-go/jsonschema"
Expand All @@ -12,21 +13,35 @@ import (
argocdhealth "github.com/argoproj/gitops-engine/pkg/health"
)

var UnhealthyApplicationsTool = &mcp.Tool{
Name: "argocd_list_unhealthy_applications",
Description: "list the unhealthy ('degraded' and 'progressing') Applications in Argo CD",
InputSchema: UnhealthyApplicationsInputSchema,
OutputSchema: UnhealthyApplicationsOutputSchema,
}

type UnhealthyApplicationsInput struct {
}
type UnhealthyApplicationsInput struct{}
type UnhealthyApplicationsOutput UnhealthyApplications

var UnhealthyApplicationsInputSchema, _ = jsonschema.For[UnhealthyApplicationsInput](&jsonschema.ForOptions{})
var UnhealthyApplicationsOutputSchema, _ = jsonschema.For[UnhealthyApplicationsOutput](&jsonschema.ForOptions{})

type UnhealthyApplicationsOutput UnhealthyApplications
var UnhealthyApplicationsTool *mcp.Tool

var UnhealthyApplicationsOutputSchema, _ = jsonschema.For[UnhealthyApplicationsOutput](&jsonschema.ForOptions{})
func init() {
var err error
// create the input schema
UnhealthyApplicationsInputSchema, err = jsonschema.For[UnhealthyApplicationsInput](&jsonschema.ForOptions{})
if err != nil {
log.Fatalf("failed to create UnhealthyApplicationsInputSchema: %v", err.Error())
}
log.Println("UnhealthyApplicationsInputSchema initialized")
// create the output schema
UnhealthyApplicationsOutputSchema, err = jsonschema.For[UnhealthyApplicationsOutput](&jsonschema.ForOptions{})
if err != nil {
log.Fatalf("failed to create UnhealthyApplicationsOutputSchema: %v", err.Error())
}
log.Println("UnhealthyApplicationsOutputSchema initialized")
UnhealthyApplicationsTool = &mcp.Tool{
Name: "argocd_list_unhealthy_applications",
Description: "list the unhealthy ('degraded' and 'progressing') Applications in Argo CD",
InputSchema: UnhealthyApplicationsInputSchema,
OutputSchema: UnhealthyApplicationsOutputSchema,
}
}

func UnhealthyApplicationsToolHandle(logger *slog.Logger, cl *Client) mcp.ToolHandlerFor[UnhealthyApplicationsInput, UnhealthyApplicationsOutput] {
return func(ctx context.Context, _ *mcp.CallToolRequest, _ UnhealthyApplicationsInput) (*mcp.CallToolResult, UnhealthyApplicationsOutput, error) {
Expand Down
13 changes: 13 additions & 0 deletions internal/argocd/unhealthy_applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

testresources "github.com/codeready-toolchain/argocd-mcp-server/test/resources"

"github.com/google/jsonschema-go/jsonschema"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -66,3 +67,15 @@ func TestListUnhealthyApplications(t *testing.T) {
assert.EqualError(t, err, "unexpected 500 response for GET http://argocd.example.com/api/v1/applications: mock error!")
})
}

func TestUnhealthyApplicationsSchemas(t *testing.T) {

t.Run("output schema", func(t *testing.T) {
// when
schema, err := jsonschema.For[UnhealthyApplicationsOutput](&jsonschema.ForOptions{})

// then
require.NoError(t, err)
assert.Equal(t, UnhealthyApplicationsOutputSchema, schema)
})
}
Loading