-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client-stdio.go
More file actions
115 lines (95 loc) · 2.9 KB
/
test-client-stdio.go
File metadata and controls
115 lines (95 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"strings"
"time"
"github.com/kunalkushwaha/mcp-navigator-go/pkg/client"
"github.com/kunalkushwaha/mcp-navigator-go/pkg/mcp"
"github.com/kunalkushwaha/mcp-navigator-go/pkg/transport"
)
// Test client for STDIO transport
// Usage: go run test-client-stdio.go [-debug]
// This launches the math-server in stdio mode and communicates with it
func main() {
testStdioProtocol()
}
func testStdioProtocol() {
debugMode := flag.Bool("debug", false, "Enable debug logging")
flag.Parse()
fmt.Println("=== MCP Navigator - STDIO Protocol Test ===")
fmt.Println("Testing math-server via STDIO transport")
if *debugMode {
fmt.Println("🐛 Debug mode: ENABLED")
}
fmt.Println()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Create STDIO transport - launches math-server in stdio mode
// The command and args should point to the math-server executable
trans := transport.NewStdioTransport("./math-server.exe", []string{"-mode", "stdio"})
// Create and connect client
config := client.ClientConfig{
Name: "test-client-stdio",
Version: "1.0.0",
Debug: *debugMode,
}
c := client.NewClient(trans, config)
// Connect
fmt.Println("📡 Connecting via STDIO...")
if err := c.Connect(ctx); err != nil {
log.Fatalf("❌ Failed to connect: %v", err)
}
defer c.Disconnect()
fmt.Println("✅ Connected successfully")
// Initialize
fmt.Println("\n🔧 Initializing MCP protocol...")
clientInfo := mcp.ClientInfo{
Name: "test-client-stdio",
Version: "1.0.0",
}
if err := c.Initialize(ctx, clientInfo); err != nil {
log.Fatalf("❌ Initialize failed: %v", err)
}
serverInfo := c.GetServerInfo()
fmt.Printf("✅ Initialized with server: %s v%s\n", serverInfo.Name, serverInfo.Version)
// List tools
fmt.Println("\n🔍 Listing tools...")
tools, err := c.ListTools(ctx)
if err != nil {
log.Fatalf("❌ ListTools failed: %v", err)
}
// Display results
fmt.Printf("\n📊 Results: Found %d tools\n", len(tools))
fmt.Println(strings.Repeat("=", 60))
if len(tools) == 0 {
fmt.Println("⚠️ No tools returned")
} else {
for i, tool := range tools {
fmt.Printf("\n🔧 Tool #%d: %s\n", i+1, tool.Name)
fmt.Printf(" Description: %s\n", tool.Description)
if tool.InputSchema != nil {
schemaJSON, _ := json.MarshalIndent(tool.InputSchema, " ", " ")
fmt.Printf(" InputSchema: %s\n", string(schemaJSON))
}
// Test the tool
if tool.Name == "multiply" {
fmt.Println("\n 🧪 Testing multiply tool...")
result, err := c.CallTool(ctx, "multiply", map[string]interface{}{
"a": 4,
"b": 6,
})
if err != nil {
fmt.Printf(" ❌ Tool call failed: %v\n", err)
} else {
fmt.Printf(" ✅ Result: %+v\n", result)
}
}
}
}
fmt.Println("\n" + strings.Repeat("=", 60))
fmt.Println("✅ STDIO Test Completed Successfully")
}