mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
7fc94018a9
Rename the entire project from mcphost to kit, including: - Go module path and all import paths - SDK type MCPHost -> Kit, file renames mcphost.go -> kit.go - CLI command name, usage strings, UI labels (KIT in literature) - Config paths (.mcphost -> .kit), env prefix (MCPHOST_ -> KIT_) - Data/credential/hooks directory paths - Remove legacy .mcp config fallbacks - Session metadata field (mcphost_version -> kit_version) - MCP client identity name - Build output, goreleaser binary name - All documentation, examples, scripts, and test files
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/mark3labs/kit/sdk"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
// Example 1: Use all defaults (loads ~/.kit.yml)
|
|
fmt.Println("=== Example 1: Default configuration ===")
|
|
host, err := sdk.New(ctx, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer func() { _ = host.Close() }()
|
|
|
|
response, err := host.Prompt(ctx, "What is 2+2?")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("Response: %s\n\n", response)
|
|
|
|
// Example 2: Override model
|
|
fmt.Println("=== Example 2: Custom model ===")
|
|
host2, err := sdk.New(ctx, &sdk.Options{
|
|
Model: "ollama/qwen3:8b",
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer func() { _ = host2.Close() }()
|
|
|
|
response, err = host2.Prompt(ctx, "Tell me a short joke")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("Response: %s\n\n", response)
|
|
|
|
// Example 3: With callbacks
|
|
fmt.Println("=== Example 3: With tool callbacks ===")
|
|
host3, err := sdk.New(ctx, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer func() { _ = host3.Close() }()
|
|
|
|
response, err = host3.PromptWithCallbacks(
|
|
ctx,
|
|
"List files in the current directory",
|
|
func(name, args string) {
|
|
fmt.Printf("🔧 Calling tool: %s\n", name)
|
|
},
|
|
func(name, args, result string, isError bool) {
|
|
if isError {
|
|
fmt.Printf("❌ Tool %s failed\n", name)
|
|
} else {
|
|
fmt.Printf("✅ Tool %s completed\n", name)
|
|
}
|
|
},
|
|
func(chunk string) {
|
|
fmt.Print(chunk) // Stream output
|
|
},
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("\nFinal response: %s\n", response)
|
|
|
|
// Example 4: Session management
|
|
fmt.Println("\n=== Example 4: Session management ===")
|
|
host4, err := sdk.New(ctx, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer func() { _ = host4.Close() }()
|
|
|
|
// First message
|
|
_, err = host4.Prompt(ctx, "Remember that my favorite color is blue")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Second message (should remember context)
|
|
response, err = host4.Prompt(ctx, "What's my favorite color?")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("Response: %s\n", response)
|
|
|
|
// Save session
|
|
if err := host4.SaveSession("./session.json"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println("Session saved to ./session.json")
|
|
}
|