Skip to content

Commit 3561157

Browse files
authored
[FEATURE] Add quickstart guide for agentgateway (#15)
* - πŸ› Fix stdio implementation - πŸš€ Add quickstart guide for agentgateway - πŸ“ Update cursor MCP documentation Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * - πŸ› Fix stdio implementation - πŸš€ Add quickstart guide for agentgateway - πŸ“ Update cursor MCP documentation Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * add homebrew path Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * increase default timeout Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> * quickstart updated Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com> --------- Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
1 parent 30a791a commit 3561157

10 files changed

Lines changed: 165 additions & 14 deletions

File tree

β€ŽMakefileβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ LDFLAGS := -X github.com/kagent-dev/tools/internal/version.Version=$(VERSION) -X
1919

2020
## Location to install dependencies to
2121
LOCALBIN ?= $(shell pwd)/bin
22+
PATH := $HOME/local/bin:/opt/homebrew/bin/:$(LOCALBIN):$(PATH)
2223
HELM_DIST_FOLDER ?= $(shell pwd)/dist
2324

2425
.PHONY: clean
2526
clean:
2627
rm -rf ./bin/kagent-tools-*
28+
rm -rf $(HOME)/.local/bin/kagent-tools-*
2729

2830
.PHONY: fmt
2931
fmt: ## Run go fmt against code.
@@ -210,6 +212,19 @@ otel-local:
210212
docker run -d --name jaeger-desktop --restart=always -p 16686:16686 -p 4317:4317 -p 4318:4318 jaegertracing/jaeger:2.7.0
211213
open http://localhost:16686/
212214

215+
.PHONY: tools-install
216+
tools-install: clean
217+
mkdir -p $HOME/.local/bin
218+
go build -ldflags "$(LDFLAGS)" -o $(LOCALBIN)/kagent-tools ./cmd
219+
go build -ldflags "$(LDFLAGS)" -o $(HOME)/.local/bin/kagent-tools ./cmd
220+
$HOME/.local/bin/kagent-tools --version
221+
222+
.PHONY: run-agentgateway
223+
run-agentgateway: tools-install
224+
open http://localhost:15000/ui
225+
cd scripts \
226+
&& agentgateway -f agentgateway-config-tools.yaml
227+
213228
.PHONY: report/image-cve
214229
report/image-cve: docker-build govulncheck
215230
echo "Running CVE scan :: CVE -> CSV ... reports/$(SEMVER)/"

β€ŽREADME.mdβ€Ž

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ This directory contains the Go implementation of all KAgent tools, migrated from
2828

2929
- **Bash:**
3030

31-
`curl -sL https://github.com/kagent-dev/tools/blob/main/scripts/install.sh | bash`
31+
```bash
32+
curl -sL https://raw.githubusercontent.com/kagent-dev/tools/refs/heads/main/scripts/install.sh | bash
33+
```
3234

3335
- **Docker:**
3436

35-
`docker run -it --rm ghcr.io/kagent-dev/kagent/tools:<version>`
37+
```bash
38+
docker run -it --rm -p 8084:8084 ghcr.io/kagent-dev/kagent/tools:0.0.10
39+
```
3640

3741
- **Kubernetes**
3842

39-
`helm upgrade -i kagent-tools --version <version> oci://ghcr.io/kagent-dev/tools/helm/`
43+
```bash
44+
helm upgrade -i -n kagent --create-namespace kagent-tools oci://ghcr.io/kagent-dev/tools/helm/kagent-tools --version 0.0.10
45+
helm ls -A
46+
```
47+
48+
## Quickstart Guide
4049

50+
For a quickstart guide on how to run KAgent tools using AgentGateway, please refer to the [Quickstart Guide](docs/quickstart.md).
4151

4252
## Architecture
4353

β€Žcmd/main.goβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func run(cmd *cobra.Command, args []string) {
8989
return
9090
}
9191

92-
logger.Init()
92+
logger.Init(stdio)
9393
defer logger.Sync()
9494

9595
// Setup context with cancellation for graceful shutdown

β€Ždocs/quickstart.mdβ€Ž

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
# Quickstart Guide for KAgnet Tools
3+
4+
## About this guide
5+
6+
This guide provides a quick overview of how to set up and run KAgent tools using AgentGateway.
7+
8+
For more detaled information on KAgent tools, please refer to the [KAgent Tools Documentation](https://kagent.dev/tools).
9+
10+
To learn more about agentgateway, see [AgentGateway](https://agentgateway.dev/docs/about/)
11+
12+
### Running KAgent Tools using AgentGateway
13+
14+
1. Download tools binary and install it.
15+
2. Download tools configuration file for agentgateway.
16+
3. Download the agentgateway binary and install it.
17+
4. Run the agentgateway with the configuration file.
18+
5. open http://localhost:15000/ui
19+
20+
```bash
21+
curl -sL https://raw.githubusercontent.com/kagent-dev/tools/refs/heads/main/scripts/install.sh | bash
22+
curl -sL https://raw.githubusercontent.com/kagent-dev/tools/refs/heads/main/scripts/agentgateway-config-tools.yaml
23+
curl -sL https://raw.githubusercontent.com/agentgateway/agentgateway/refs/heads/main/common/scripts/get-agentproxy | bash
24+
25+
export PATH=$PATH:$HOME/.local/bin/
26+
agentgateway -f agentgateway-config-tools.yaml
27+
```
28+
29+
agentgateway-config-tools.yaml:
30+
```yaml
31+
binds:
32+
- port: 30805
33+
listeners:
34+
- routes:
35+
- policies:
36+
cors:
37+
allowOrigins:
38+
- "*"
39+
allowHeaders:
40+
- mcp-protocol-version
41+
- content-type
42+
backends:
43+
- mcp:
44+
name: default
45+
targets:
46+
- name: kagent-tools
47+
stdio:
48+
cmd: kagent-tools
49+
args: ["--stdio", "--kubeconfig", "~/.kube/config"]
50+
```
51+
Afterwards, you can run it with make command
52+
```bash
53+
make run-agentgateway
54+
```
55+
56+
### Running KAgent Tools using Cursor MCP
57+
58+
59+
1. Download the agentgateway binary and install it.
60+
```
61+
curl -sL https://raw.githubusercontent.com/kagent-dev/tools/refs/heads/main/scripts/install.sh | bash
62+
```
63+
64+
2. Create `.cursor/mcp.json`
65+
66+
```json
67+
{
68+
"mcpServers": {
69+
"kagent-tools": {
70+
"command": "kagent-tools",
71+
"args": ["--stdio", "--kubeconfig", "~/.kube/config"]
72+
}
73+
}
74+
}
75+
```
76+
77+
78+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apiVersion: v2
22
name: kagent-tools
3-
description: A Helm chart for kagent-tools,
3+
description: A Helm chart for kagent-tools
44
type: application
55
version: ${VERSION}
6+
appVersion: ${VERSION}

β€Žinternal/commands/builder.goβ€Ž

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515
"go.opentelemetry.io/otel/attribute"
1616
)
1717

18+
const (
19+
// DefaultTimeout is the default timeout for command execution
20+
DefaultTimeout = 2 * time.Minute
21+
// DefaultCacheTTL is the default cache TTL
22+
DefaultCacheTTL = 1 * time.Minute
23+
)
24+
1825
// CommandBuilder provides a fluent interface for building CLI commands
1926
type CommandBuilder struct {
2027
command string
@@ -43,10 +50,10 @@ func NewCommandBuilder(command string) *CommandBuilder {
4350
args: make([]string, 0),
4451
labels: make(map[string]string),
4552
annotations: make(map[string]string),
46-
timeout: 60 * time.Second,
53+
timeout: DefaultTimeout,
4754
useTimeout: false, // Only enable timeout when explicitly requested
4855
validate: true,
49-
cacheTTL: 1 * time.Minute,
56+
cacheTTL: DefaultCacheTTL,
5057
}
5158
}
5259

β€Žinternal/commands/builder_test.goβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestNewCommandBuilder(t *testing.T) {
1919
assert.Empty(t, cb.output)
2020
assert.NotNil(t, cb.labels)
2121
assert.NotNil(t, cb.annotations)
22-
assert.Equal(t, 60*time.Second, cb.timeout)
23-
assert.Equal(t, 1*time.Minute, cb.cacheTTL)
22+
assert.Equal(t, DefaultTimeout, cb.timeout)
23+
assert.Equal(t, DefaultCacheTTL, cb.cacheTTL)
2424
assert.True(t, cb.validate)
2525
assert.False(t, cb.cached)
2626
assert.False(t, cb.dryRun)

β€Žinternal/logger/logger.goβ€Ž

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,39 @@ import (
1010

1111
var globalLogger *slog.Logger
1212

13-
func Init() {
13+
// Init initializes the global logger
14+
// If useStderr is true, logs will be written to stderr (for stdio mode)
15+
// If useStderr is false, logs will be written to stdout (for HTTP mode)
16+
func Init(useStderr bool) {
1417
opts := &slog.HandlerOptions{
1518
Level: slog.LevelInfo,
1619
}
1720

21+
// Choose output destination based on mode
22+
output := os.Stdout
23+
if useStderr {
24+
output = os.Stderr
25+
}
26+
1827
if os.Getenv("KAGENT_LOG_FORMAT") == "json" {
19-
globalLogger = slog.New(slog.NewJSONHandler(os.Stdout, opts))
28+
globalLogger = slog.New(slog.NewJSONHandler(output, opts))
2029
} else {
21-
globalLogger = slog.New(slog.NewTextHandler(os.Stdout, opts))
30+
globalLogger = slog.New(slog.NewTextHandler(output, opts))
2231
}
2332

2433
slog.SetDefault(globalLogger)
2534
}
2635

36+
// InitWithEnv initializes the logger using environment variables
37+
// This is a convenience function that defaults to stdout unless KAGENT_USE_STDERR is set
38+
func InitWithEnv() {
39+
useStderr := os.Getenv("KAGENT_USE_STDERR") == "true"
40+
Init(useStderr)
41+
}
42+
2743
func Get() *slog.Logger {
2844
if globalLogger == nil {
29-
Init()
45+
InitWithEnv()
3046
}
3147
return globalLogger
3248
}

β€Žinternal/logger/logger_test.goβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func TestGet(t *testing.T) {
6464
}
6565

6666
func TestInit(t *testing.T) {
67-
assert.NotPanics(t, Init)
67+
assert.NotPanics(t, func() { Init(false) })
68+
assert.NotPanics(t, func() { Init(true) })
6869
}
6970

7071
func TestSync(t *testing.T) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
binds:
2+
- port: 30805
3+
listeners:
4+
- routes:
5+
- backends:
6+
- mcp:
7+
name: default
8+
targets:
9+
- name: kagent-tools
10+
stdio:
11+
cmd: kagent-tools
12+
args:
13+
- --stdio
14+
- --kubeconfig
15+
- ~/.kube/config
16+
policies:
17+
cors:
18+
allowOrigins:
19+
- '*'
20+
allowHeaders:
21+
- mcp-protocol-version
22+
- content-type
23+
- cache-control

0 commit comments

Comments
Β (0)