-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitalization_test.go
58 lines (49 loc) · 1.43 KB
/
initalization_test.go
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
package mcp_test
import (
"context"
"log/slog"
"net"
"testing"
"time"
"github.com/agent-api/jsonrpc2"
"github.com/agent-api/mcp"
)
func TestInitialization(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
// Create in-memory pipe connection
connA, connB := net.Pipe()
// Setup server
serverOpts := mcp.ServerOpts{
SupportedVersions: []string{"2024-11-05"},
Info: &mcp.ServerInfo{Name: "TestServer", Version: "1.0.0"},
Capabilities: &mcp.ServerCapabilities{
Logging: &mcp.LoggingCapabilities{},
Prompts: &mcp.PromptsCapabilities{ListChanged: true},
},
Logger: slog.Default(),
}
server := mcp.NewServer(&serverOpts)
// Start server connection
jsonrpcServer := jsonrpc2.NewConn(ctx, jsonrpc2.NewPlainObjectStream(connA), server.Handler())
defer jsonrpcServer.Close()
// Setup client
jsonrpcClient := jsonrpc2.NewConn(ctx, jsonrpc2.NewPlainObjectStream(connB), nil)
defer jsonrpcClient.Close()
clientOpts := mcp.ClientOpts{
Conn: jsonrpcClient,
SupportedVersions: []string{"2024-11-05"},
Logger: slog.Default(),
}
client := mcp.NewClient(&clientOpts)
// Perform initialization
err := client.Initialize(ctx,
mcp.ClientInfo{Name: "TestClient", Version: "1.0.0"},
mcp.ClientCapabilities{
Roots: &mcp.RootsCapabilities{ListChanged: true},
},
)
if err != nil {
t.Errorf("could not initialize server: %s", err)
}
}