Skip to content

Commit 2e4f116

Browse files
committed
merge main and fix conflict
2 parents c5fa4ea + 9f39a43 commit 2e4f116

22 files changed

+1708
-73
lines changed

client/http.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/mark3labs/mcp-go/client/transport"
7+
)
8+
9+
// NewStreamableHttpClient is a convenience method that creates a new streamable-http-based MCP client
10+
// with the given base URL. Returns an error if the URL is invalid.
11+
func NewStreamableHttpClient(baseURL string, options ...transport.StreamableHTTPCOption) (*Client, error) {
12+
trans, err := transport.NewStreamableHTTP(baseURL, options...)
13+
if err != nil {
14+
return nil, fmt.Errorf("failed to create SSE transport: %w", err)
15+
}
16+
return NewClient(trans), nil
17+
}

client/sse_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func TestSSEMCPClient(t *testing.T) {
2525
"test-tool",
2626
mcp.WithDescription("Test tool"),
2727
mcp.WithString("parameter-1", mcp.Description("A string tool parameter")),
28+
mcp.WithToolAnnotation(mcp.ToolAnnotation{
29+
Title: "Test Tool Annotation Title",
30+
ReadOnlyHint: true,
31+
DestructiveHint: false,
32+
IdempotentHint: true,
33+
OpenWorldHint: false,
34+
}),
2835
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
2936
return &mcp.CallToolResult{
3037
Content: []mcp.Content{
@@ -95,10 +102,21 @@ func TestSSEMCPClient(t *testing.T) {
95102

96103
// Test ListTools
97104
toolsRequest := mcp.ListToolsRequest{}
98-
_, err = client.ListTools(ctx, toolsRequest)
105+
toolListResult, err := client.ListTools(ctx, toolsRequest)
99106
if err != nil {
100107
t.Errorf("ListTools failed: %v", err)
101108
}
109+
if toolListResult == nil || len((*toolListResult).Tools) == 0 {
110+
t.Errorf("Expected one tool")
111+
}
112+
testToolAnnotations := (*toolListResult).Tools[0].Annotations
113+
if testToolAnnotations.Title != "Test Tool Annotation Title" ||
114+
testToolAnnotations.ReadOnlyHint != true ||
115+
testToolAnnotations.DestructiveHint != false ||
116+
testToolAnnotations.IdempotentHint != true ||
117+
testToolAnnotations.OpenWorldHint != false {
118+
t.Errorf("The annotations of the tools are invalid")
119+
}
102120
})
103121

104122
// t.Run("Can handle notifications", func(t *testing.T) {

client/transport/stdio_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"path/filepath"
10+
"runtime"
1011
"sync"
1112
"testing"
1213
"time"
@@ -31,6 +32,10 @@ func compileTestServer(outputPath string) error {
3132
func TestStdio(t *testing.T) {
3233
// Compile mock server
3334
mockServerPath := filepath.Join(os.TempDir(), "mockstdio_server")
35+
// Add .exe suffix on Windows
36+
if runtime.GOOS == "windows" {
37+
mockServerPath += ".exe"
38+
}
3439
if err := compileTestServer(mockServerPath); err != nil {
3540
t.Fatalf("Failed to compile mock server: %v", err)
3641
}
@@ -302,16 +307,19 @@ func TestStdioErrors(t *testing.T) {
302307
})
303308

304309
t.Run("RequestBeforeStart", func(t *testing.T) {
305-
// 创建一个新的 Stdio 实例但不调用 Start 方法
306310
mockServerPath := filepath.Join(os.TempDir(), "mockstdio_server")
311+
// Add .exe suffix on Windows
312+
if runtime.GOOS == "windows" {
313+
mockServerPath += ".exe"
314+
}
307315
if err := compileTestServer(mockServerPath); err != nil {
308316
t.Fatalf("Failed to compile mock server: %v", err)
309317
}
310318
defer os.Remove(mockServerPath)
311319

312320
uninitiatedStdio := NewStdio(mockServerPath, nil)
313321

314-
// 准备一个请求
322+
// Prepare a request
315323
request := JSONRPCRequest{
316324
JSONRPC: "2.0",
317325
ID: 99,
@@ -331,6 +339,10 @@ func TestStdioErrors(t *testing.T) {
331339
t.Run("RequestAfterClose", func(t *testing.T) {
332340
// Compile mock server
333341
mockServerPath := filepath.Join(os.TempDir(), "mockstdio_server")
342+
// Add .exe suffix on Windows
343+
if runtime.GOOS == "windows" {
344+
mockServerPath += ".exe"
345+
}
334346
if err := compileTestServer(mockServerPath); err != nil {
335347
t.Fatalf("Failed to compile mock server: %v", err)
336348
}

0 commit comments

Comments
 (0)