From 071a84561916fb4fce685fff1ce84a51ffffa388 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Mon, 5 Jan 2026 22:21:57 +0200 Subject: [PATCH 1/3] allow test to set client info This allows testing of mcp server behavior that depends on the type of the mcp client. --- mcptest/mcptest.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mcptest/mcptest.go b/mcptest/mcptest.go index df85753f2..d658e2fab 100644 --- a/mcptest/mcptest.go +++ b/mcptest/mcptest.go @@ -24,6 +24,7 @@ type Server struct { prompts []server.ServerPrompt resources []server.ServerResource resourceTemplates []server.ServerResourceTemplate + clientInfo mcp.Implementation cancel func() @@ -120,6 +121,11 @@ func (s *Server) AddResourceTemplates(templates ...server.ServerResourceTemplate s.resourceTemplates = append(s.resourceTemplates, templates...) } +// SetClientInfo sets the client info for the test client. +func (s *Server) SetClientInfo(info mcp.Implementation) { + s.clientInfo = info +} + // Start starts the server in a goroutine. Make sure to defer Close() after Start(). // When using NewServer(), the returned server is already started. func (s *Server) Start(ctx context.Context) error { @@ -157,6 +163,7 @@ func (s *Server) Start(ctx context.Context) error { var initReq mcp.InitializeRequest initReq.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION + initReq.Params.ClientInfo = s.clientInfo if _, err := s.client.Initialize(ctx, initReq); err != nil { return fmt.Errorf("client.Initialize(): %w", err) } From 650460be55e46ec5a41a6f393ec39e74c0035426 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Mon, 5 Jan 2026 22:25:02 +0200 Subject: [PATCH 2/3] test allowing test to set client info --- mcptest/mcptest_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mcptest/mcptest_test.go b/mcptest/mcptest_test.go index f8a12f7ff..352da1911 100644 --- a/mcptest/mcptest_test.go +++ b/mcptest/mcptest_test.go @@ -411,3 +411,44 @@ func TestListToolsWithHeader(t *testing.T) { t.Fatalf("Expected value is %s, got %s", expectedHeaderValue, gotHeaderValue) } } + +func TestSimulateClientInfo(t *testing.T) { + ctx := context.Background() + + srv := mcptest.NewUnstartedServer(t) + defer srv.Close() + srv.AddTool(mcp.NewTool("whoami", mcp.WithDescription("Says hello to client.")), + func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { + clientName := "" + if clientSession := server.ClientSessionFromContext(ctx); clientSession != nil { + if sessionWithClientInfo, ok := clientSession.(server.SessionWithClientInfo); ok { + clientName = sessionWithClientInfo.GetClientInfo().Name + } + } + return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", clientName)), nil + }) + srv.SetClientInfo(mcp.Implementation{ + Name: "test-client", + }) + srv.Start(context.TODO()) + + client := srv.Client() + + var req mcp.CallToolRequest + req.Params.Name = "whoami" + + result, err := client.CallTool(ctx, req) + if err != nil { + t.Fatal("CallTool:", err) + } + + got, err := resultToString(result) + if err != nil { + t.Fatal(err) + } + + want := "Hello, test-client!" + if got != want { + t.Errorf("Got %q, want %q", got, want) + } +} From 4742c41cca7d4750aaf2bec2ab66eace55c9b685 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Mon, 5 Jan 2026 22:45:48 +0200 Subject: [PATCH 3/3] CR comment check Start() return code and use ctx consistently --- mcptest/mcptest_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mcptest/mcptest_test.go b/mcptest/mcptest_test.go index 352da1911..8e2a6a162 100644 --- a/mcptest/mcptest_test.go +++ b/mcptest/mcptest_test.go @@ -430,7 +430,10 @@ func TestSimulateClientInfo(t *testing.T) { srv.SetClientInfo(mcp.Implementation{ Name: "test-client", }) - srv.Start(context.TODO()) + err := srv.Start(ctx) + if err != nil { + t.Fatal("Start:", err) + } client := srv.Client()