Skip to content
Open
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
64 changes: 64 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Git
.git/
.gitignore
.gitattributes

# Build artifacts
bin/
*.exe
*.test
*.out
coverage.out
coverage.html
*_coverage.out

# IDE
.idea/
.vscode/
*.iml
.DS_Store
Thumbs.db

# Environment files
.env
.env.local
.env.*.local

# Logs
logs/
*.log

# Temporary files
*.tmp
*.swp
*~

# Documentation and specs (not needed in image)
docs/
specs/
*.md
!README.md

# Test files
test/
*_test.go

# Reports
reports/

# Helm charts source (not needed)
helm/kagent-tools/

# Dagger
.dagger/

# Go vendor (not used, but ignore if present)
vendor/

# Scripts (not needed in image)
scripts/

# Dist artifacts
dist/

helm/
23 changes: 0 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,3 @@ jobs:
working-directory: .
run: |
make e2e

helm-unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.17.0

- name: Install unittest plugin
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest

- name: Chart init
run: |
make helm-version

- name: Run helm unit tests
run: |
make helm-test
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,25 @@ bin/
/helm/kagent-tools/Chart.yaml
/reports/tools-cve.csv
.dagger/

# Go build artifacts
*.exe
*.test
vendor/

# Test coverage
coverage.out
coverage.html
*_coverage.out
e2e_coverage.out
integration_coverage.out
telemetry_coverage.out

# Temporary files
*.tmp
*.swp
*~

# IDE
*.iml
Thumbs.db
8 changes: 7 additions & 1 deletion CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ See the [DEVELOPMENT.md](DEVELOPMENT.md) file for more information.

- **Go Code**:
- Follow the [Go Code Review Comments](https://go.dev/wiki/CodeReviewComments)
- Use the official MCP SDK patterns: `github.com/modelcontextprotocol/go-sdk` (Principle I)
- Implement type-safe input validation for all parameters (Principle II)
- Write tests BEFORE implementation - TDD is mandatory (Principle III)
- Maintain modular package design under `pkg/` (Principle IV)
- Use structured logging and sanitize inputs (Principle V)
- Run `make lint` before submitting your changes
- Ensure all tests pass with `make test`
- Add tests for new functionality
- Achieve minimum 80% test coverage
- Follow MCP specification for tool implementations

#### Commit Guidelines

Expand Down
52 changes: 44 additions & 8 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ These tools enhance functionality but aren't required for basic development:
- `istioctl` - Istio service mesh CLI for istio tools
- `cilium` - Cilium CLI for cilium tools

### MCP Tools
```json
{
"mcpServers": {
"kagent-tools": {
"command": "kagent-tools",
"args": ["--stdio", "--kubeconfig", "~/.kube/config", "--tools", "k8s,helm,istio,utils"]
},
"go-sdk-docs": {
"url": "https://gitmcp.io/modelcontextprotocol/go-sdk"
},
"modelcontextprotocol-docs": {
"url": "https://gitmcp.io/modelcontextprotocol/modelcontextprotocol"
}
}
}
```

## Project Structure

```
Expand Down Expand Up @@ -157,7 +175,7 @@ package category

import (
"context"
"github.com/mark3labs/mcp-go/pkg/mcp"
"github.com/modelcontextprotocol/go-sdk/src/go/mcp"
)

type Tools struct {
Expand All @@ -169,11 +187,33 @@ func NewTools() *Tools {
}

func (t *Tools) RegisterTools(server *mcp.Server) {
server.RegisterTool("tool_name", t.handleTool)
tool := mcp.NewTool("tool_name",
mcp.WithDescription("Description of what this tool does"),
mcp.WithString("param1",
mcp.Required(),
mcp.Description("Description of parameter 1"),
),
mcp.WithBool("param2",
mcp.Description("Optional boolean parameter"),
),
)
server.AddTool(tool, t.handleTool)
}

func (t *Tools) handleTool(ctx context.Context, params map[string]interface{}) (*mcp.ToolResult, error) {
// implementation
func (t *Tools) handleTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Parse required parameters with type safety
param1, err := request.RequireString("param1")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

// Parse optional parameters
param2, _ := request.GetBool("param2")

// Tool implementation logic here
result := fmt.Sprintf("Processing %s with flag %v", param1, param2)

return mcp.NewToolResultText(result), nil
}
```

Expand Down Expand Up @@ -250,10 +290,6 @@ func TestToolFunction(t *testing.T) {

```go
func TestIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}

// Setup test environment
ctx := context.Background()
tools := NewTools()
Expand Down
42 changes: 34 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ FROM $BASE_IMAGE_REGISTRY/chainguard/wolfi-base:latest AS tools
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

RUN apk update && apk add \
curl openssl bash git ca-certificates \
&& rm -rf /var/cache/apk/*
RUN apk update && apk add --no-cache \
curl openssl bash git ca-certificates go

ARG TARGETARCH
WORKDIR /downloads
Expand All @@ -31,12 +30,36 @@ RUN curl -L https://istio.io/downloadIstio | ISTIO_VERSION=$TOOLS_ISTIO_VERSION
&& rm -rf istio-* \
&& /downloads/istioctl --help

# Install kubectl-argo-rollouts
# Install kubectl-argo-rollouts from source and fix CVE's
# PENDING PR https://github.com/argoproj/argo-rollouts/pull/4515/files
ARG TOOLS_ARGO_ROLLOUTS_VERSION
RUN curl -Lo /downloads/kubectl-argo-rollouts https://github.com/argoproj/argo-rollouts/releases/download/v${TOOLS_ARGO_ROLLOUTS_VERSION}/kubectl-argo-rollouts-linux-${TARGETARCH} \
&& chmod +x /downloads/kubectl-argo-rollouts \
RUN git clone --depth 1 https://github.com/argoproj/argo-rollouts.git -b v${TOOLS_ARGO_ROLLOUTS_VERSION}
RUN cd argo-rollouts \
&& go mod edit -replace=golang.org/x/net=golang.org/x/[email protected] \
&& go mod edit -replace=golang.org/x/crypto=golang.org/x/[email protected] \
&& go mod edit -replace=k8s.io/kubernetes=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/apimachinery=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/client-go=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/api=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/apiserver=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/apiextensions-apiserver=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/cli-runtime=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/kubectl=k8s.io/[email protected] \
&& go mod edit -replace=k8s.io/code-generator=k8s.io/[email protected] \
&& go mod edit -replace=github.com/argoproj/notifications-engine=github.com/argoproj/[email protected] \
&& go mod edit -replace=github.com/expr-lang/expr=github.com/expr-lang/[email protected] \
&& sed -i 's/v0.30.14/v0.34.1/g' go.mod \
&& sed -i 's/ValidatePodTemplateSpecForReplicaSet(&template, nil, selector,/ValidatePodTemplateSpecForReplicaSet(\&template, selector,/g' pkg/apis/rollouts/validation/validation.go \
&& go mod tidy \
&& CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "-s -w" -o /downloads/kubectl-argo-rollouts ./cmd/kubectl-argo-rollouts \
&& /downloads/kubectl-argo-rollouts version

# Install Argo CLI
ARG TOOLS_ARGO_CLI_VERSION
RUN curl -sSL -o /downloads/argocd https://github.com/argoproj/argo-cd/releases/download/v${TOOLS_ARGO_CLI_VERSION}/argocd-linux-${TARGETARCH} \
&& chmod +x /downloads/argocd \
&& /downloads/argocd version --client

# Install Cilium CLI
ARG TOOLS_CILIUM_VERSION
RUN curl -Lo cilium.tar.gz https://github.com/cilium/cilium-cli/releases/download/v${TOOLS_CILIUM_VERSION}/cilium-linux-${TARGETARCH}.tar.gz \
Expand Down Expand Up @@ -80,22 +103,25 @@ COPY pkg pkg
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
--mount=type=cache,target=/root/.cache/go-build,rw \
echo "Building tool-server for $TARGETARCH on $BUILDARCH" && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o tool-server cmd/main.go
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o tool-server ./cmd/server

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot

WORKDIR /
USER 65532:65532
ENV HOME=/home/nonroot
ENV PATH=$PATH:/bin

# Copy the tools
COPY --from=tools --chown=65532:65532 /downloads/kubectl /bin/kubectl
COPY --from=tools --chown=65532:65532 /downloads/istioctl /bin/istioctl
COPY --from=tools --chown=65532:65532 /downloads/helm /bin/helm
COPY --from=tools --chown=65532:65532 /downloads/kubectl-argo-rollouts /bin/kubectl-argo-rollouts
COPY --from=tools --chown=65532:65532 /downloads/cilium /bin/cilium
COPY --from=tools --chown=65532:65532 /downloads/argocd /bin/argocd
COPY --from=tools --chown=65532:65532 /downloads/kubectl-argo-rollouts /bin/kubectl-argo-rollouts

# Copy the tool-server binary
COPY --from=builder --chown=65532:65532 /workspace/tool-server /tool-server

Expand Down
Loading