Repository navigation
Expand file tree
/
Copy pathclient.go
More file actions
627 lines (560 loc) · 21.8 KB
/
Copy pathclient.go
File metadata and controls
627 lines (560 loc) · 21.8 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package core
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"strings"
"sync"
"github.com/googleapis/mcp-toolbox-sdk-go/core/transport"
mcp20241105 "github.com/googleapis/mcp-toolbox-sdk-go/core/transport/mcp/v20241105"
mcp20250326 "github.com/googleapis/mcp-toolbox-sdk-go/core/transport/mcp/v20250326"
mcp20250618 "github.com/googleapis/mcp-toolbox-sdk-go/core/transport/mcp/v20250618"
mcp20251125 "github.com/googleapis/mcp-toolbox-sdk-go/core/transport/mcp/v20251125"
mcp20260728 "github.com/googleapis/mcp-toolbox-sdk-go/core/transport/mcp/v20260728"
"golang.org/x/oauth2"
)
// The synchronous interface for a Toolbox service client.
type ToolboxClient struct {
mu sync.RWMutex
baseURL string
httpClient *http.Client
protocol Protocol
protocolSet bool
transport transport.Transport
clientHeaderSources map[string]oauth2.TokenSource
defaultToolOptions []ToolOption
defaultOptionsSet bool
clientName string
clientVersion string
supportedProtocols []Protocol
}
// NewToolboxClient creates and configures a new, immutable client for interacting with a
// Toolbox server.
//
// Inputs:
// - url: The base URL of the Toolbox server.
// - opts: A variadic list of ClientOption functions to configure the client,
// such as setting a custom http.Client, default headers, or the underlying protocol.
//
// Returns:
//
// A configured *ToolboxClient and a nil error on success, or a nil client
// and an error if configuration fails.
func NewToolboxClient(url string, opts ...ClientOption) (*ToolboxClient, error) {
// Initialize the client with default values.
// We default to MCP Protocol (the newest version alias) if not overridden.
tc := &ToolboxClient{
baseURL: url,
httpClient: &http.Client{},
protocol: MCP, // Default
clientHeaderSources: make(map[string]oauth2.TokenSource),
defaultToolOptions: []ToolOption{},
clientName: "toolbox-core-go",
}
// Apply each functional option to customize the client configuration.
for _, opt := range opts {
if opt == nil {
return nil, fmt.Errorf("NewToolboxClient: received a nil ClientOption")
}
if err := opt(tc); err != nil {
return nil, err
}
}
checkSecureHeaders(tc.baseURL, len(tc.clientHeaderSources) > 0)
// Initialize the Transport based on the selected Protocol.
var transportErr error
switch tc.protocol {
case MCPv20260728:
tc.transport, transportErr = mcp20260728.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20251125:
tc.transport, transportErr = mcp20251125.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20250618:
tc.transport, transportErr = mcp20250618.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20250326:
tc.transport, transportErr = mcp20250326.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20241105:
tc.transport, transportErr = mcp20241105.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
default:
return nil, fmt.Errorf("unsupported protocol version: %s", tc.protocol)
}
return tc, transportErr
}
// newToolboxTool is an internal factory method that constructs a
// ToolboxTool from its schema and a final configuration.
//
// Inputs:
// - name: The name of the tool being created.
// - schema: The definition of the tool from the server manifest.
// - finalConfig: The combined default and user-provided tool options.
// - isStrict: A flag that, if true, errors if a bound parameter or
// secure parameter config does not exist in the tool's schema.
//
// Returns:
// - *ToolboxTool: The fully constructed tool, ready for invocation.
// - []string: A slice of authentication source keys that were used by the tool.
// - []string: A slice of bound parameter keys that were used by the tool.
// - []string: A slice of bound secure parameter keys that were used by the tool.
// - error: An error if validation fails (e.g., in strict mode).
func (tc *ToolboxClient) newToolboxTool(
name string,
schema ToolSchema,
finalConfig *ToolConfig,
isStrict bool,
tr transport.Transport,
) (*ToolboxTool, []string, []string, []string, error) {
// These will be the parameters that the end-user must provide at invocation time.
finalParameters := make([]ParameterSchema, 0)
// This map collects parameters that require an auth token to be fulfilled.
authnParams := make(map[string][]string)
// This map tracks all parameter schemas defined in the schema.
allParamSchemas := make(map[string]ParameterSchema)
// This map stores bound parameters that are applicable to this specific tool.
localBoundParams := make(map[string]any)
// This map stores the schemas of the bound parameters for validation during invocation.
localBoundSchemas := make(map[string]ParameterSchema)
// Build lookup maps for validation.
secSchemaMap := make(map[string]ParameterSchema)
for _, sp := range schema.SecureParameters {
secSchemaMap[sp.Name] = sp
}
// Iterate over the tool's parameters from the schema to categorize them.
for _, p := range schema.Parameters {
if ap, ok := p.AdditionalProperties.(map[string]any); ok {
apParam, err := mapToSchema(ap)
if err != nil {
return nil, nil, nil, nil, err
}
p.AdditionalProperties = apParam
}
// Validate parameter schema
if err := p.ValidateDefinition(); err != nil {
// Return a detailed error indicating which tool failed validation.
return nil, nil, nil, nil, fmt.Errorf("invalid schema for tool '%s': %w", name, err)
}
allParamSchemas[p.Name] = p
if len(p.AuthSources) > 0 {
// The parameter is satisfied by an authentication source.
authnParams[p.Name] = p.AuthSources
} else if val, isBound := finalConfig.BoundParams[p.Name]; isBound {
// The parameter is satisfied by a pre-configured bound value.
localBoundParams[p.Name] = val
localBoundSchemas[p.Name] = p
} else {
// The parameter is not satisfied by auth or bindings, so it must
// be provided by the user at invocation.
finalParameters = append(finalParameters, p)
}
}
// Process secure parameters from the schema.
finalSecureParameters := make([]ParameterSchema, 0)
localBoundSecureParams := make(map[string]any)
localBoundSecureSchemas := make(map[string]ParameterSchema)
for _, sp := range schema.SecureParameters {
if err := sp.ValidateDefinition(); err != nil {
return nil, nil, nil, nil, fmt.Errorf("invalid secure parameter schema for tool '%s': %w", name, err)
}
if val, isBound := finalConfig.SecureParams[sp.Name]; isBound {
localBoundSecureParams[sp.Name] = val
localBoundSecureSchemas[sp.Name] = sp
} else {
finalSecureParameters = append(finalSecureParameters, sp)
}
}
// In strict mode, validate that all provided bound parameters and secure parameters exist.
if isStrict {
for boundName := range finalConfig.BoundParams {
if _, isSec := secSchemaMap[boundName]; isSec {
return nil, nil, nil, nil, fmt.Errorf("parameter %q is a secure parameter; use WithBindSecureParam* instead", boundName)
}
if _, exists := allParamSchemas[boundName]; !exists {
return nil, nil, nil, nil, fmt.Errorf("unable to bind parameter: no parameter named '%s' found on tool '%s'", boundName, name)
}
}
for secName := range finalConfig.SecureParams {
if _, isReg := allParamSchemas[secName]; isReg {
return nil, nil, nil, nil, fmt.Errorf("parameter %q is a regular parameter; use WithBindParam* instead", secName)
}
if _, exists := secSchemaMap[secName]; !exists {
return nil, nil, nil, nil, fmt.Errorf("unable to bind secure parameter: no secure parameter named %q found on tool %q", secName, name)
}
}
}
// Collect the keys of the bound parameters that were actually used.
var usedBoundKeys []string
for k := range localBoundParams {
usedBoundKeys = append(usedBoundKeys, k)
}
// Collect the keys of the bound secure parameters that were actually used.
var usedSecureKeys []string
for k := range localBoundSecureParams {
usedSecureKeys = append(usedSecureKeys, k)
}
// Determine which auth requirements are still unmet after applying the provided tokens.
remainingAuthnParams, remainingAuthzTokens, usedAuthKeys := identifyAuthRequirements(
authnParams,
schema.AuthRequired,
finalConfig.AuthTokenSources,
)
// Construct the final tool object.
tt := &ToolboxTool{
name: name,
description: schema.Description,
parameters: finalParameters,
secureParameters: finalSecureParameters,
transport: tr,
authTokenSources: finalConfig.AuthTokenSources,
boundParams: localBoundParams,
boundParamSchemas: localBoundSchemas,
boundSecureParams: localBoundSecureParams,
boundSecureParamSchemas: localBoundSecureSchemas,
requiredAuthnParams: remainingAuthnParams,
requiredAuthzTokens: remainingAuthzTokens,
clientHeaderSources: tc.clientHeaderSources,
clientName: tc.clientName,
clientVersion: tc.clientVersion,
}
return tt, usedAuthKeys, usedBoundKeys, usedSecureKeys, nil
}
// LoadTool fetches a manifest for a single tool
//
// Inputs:
// - name: The specific name of the tool to load.
// - ctx: The context to control the lifecycle of the request.
// - opts: A variadic list of ToolOption functions to configure auth tokens,
// bind parameters, or bind secure parameters for this tool.
//
// Returns:
//
// A configured *ToolboxTool and a nil error on success, or a nil tool and
// an error if loading or validation fails.
func (tc *ToolboxClient) LoadTool(name string, ctx context.Context, opts ...ToolOption) (*ToolboxTool, error) {
finalConfig := newToolConfig()
// Apply client-wide default options first.
for _, opt := range tc.defaultToolOptions {
if err := opt(finalConfig); err != nil {
return nil, err
}
}
// Then, apply the tool-specific options provided in this call.
for _, opt := range opts {
if opt == nil {
return nil, fmt.Errorf("LoadTool: received a nil ToolOption in options list")
}
if err := opt(finalConfig); err != nil {
return nil, err
}
}
checkSecureHeaders(tc.baseURL, len(finalConfig.AuthTokenSources) > 0)
resolvedHeaders, err := resolveClientHeaders(tc.clientHeaderSources)
if err != nil {
return nil, err
}
// Fetch the manifest for the specified tool.
var manifest *transport.ManifestSchema
res, err := tc.executeWithFallback(func(tr transport.Transport) (any, error) {
return tr.GetTool(ctx, name, resolvedHeaders)
})
if err != nil {
return nil, fmt.Errorf("failed to load tool manifest for '%s': %w", name, err)
}
manifest = res.(*transport.ManifestSchema)
if manifest.Tools == nil {
return nil, fmt.Errorf("tool '%s' not found (manifest contains no tools)", name)
}
schema, ok := manifest.Tools[name]
if !ok {
return nil, fmt.Errorf("tool '%s' not found", name)
}
// Construct the tool from its schema and the final configuration.
tc.mu.RLock()
activeTransport := tc.transport
tc.mu.RUnlock()
tool, usedAuthKeys, usedBoundKeys, usedSecureKeys, err := tc.newToolboxTool(name, schema, finalConfig, true, activeTransport)
if err != nil {
return nil, fmt.Errorf("failed to create toolbox tool from schema for '%s': %w", name, err)
}
// Create sets of provided and used keys for efficient lookup.
providedAuthKeys := make(map[string]struct{})
for k := range finalConfig.AuthTokenSources {
providedAuthKeys[k] = struct{}{}
}
providedBoundKeys := make(map[string]struct{})
for k := range finalConfig.BoundParams {
providedBoundKeys[k] = struct{}{}
}
providedSecureKeys := make(map[string]struct{})
for k := range finalConfig.SecureParams {
providedSecureKeys[k] = struct{}{}
}
usedAuthSet := make(map[string]struct{})
for _, k := range usedAuthKeys {
usedAuthSet[k] = struct{}{}
}
usedBoundSet := make(map[string]struct{})
for _, k := range usedBoundKeys {
usedBoundSet[k] = struct{}{}
}
usedSecureSet := make(map[string]struct{})
for _, k := range usedSecureKeys {
usedSecureSet[k] = struct{}{}
}
// Find any provided options that were not consumed during tool creation.
var errorMessages []string
unusedAuth := findUnusedKeys(providedAuthKeys, usedAuthSet)
unusedBound := findUnusedKeys(providedBoundKeys, usedBoundSet)
unusedSecure := findUnusedKeys(providedSecureKeys, usedSecureSet)
if len(unusedAuth) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused auth tokens: %s", strings.Join(unusedAuth, ", ")))
}
if len(unusedBound) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused bound parameters: %s", strings.Join(unusedBound, ", ")))
}
if len(unusedSecure) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused secure parameters: %s", strings.Join(unusedSecure, ", ")))
}
if len(errorMessages) > 0 {
return nil, fmt.Errorf("validation failed for tool '%s': %s", name, strings.Join(errorMessages, "; "))
}
return tool, nil
}
// LoadToolset fetches a manifest for a collection of tools.
//
// Inputs:
// - name: Name of the toolset to be loaded. Set this arg to "" to load the default toolset.
// - ctx: The context to control the lifecycle of the request.
// - opts: A variadic list of ToolOption functions. These can include WithStrict
// and options for auth, bound params, or secure params that may apply to tools in the set.
//
// Returns:
//
// A slice of configured *ToolboxTool and a nil error on success, or a nil
// slice and an error if loading or validation fails.
func (tc *ToolboxClient) LoadToolset(name string, ctx context.Context, opts ...ToolOption) ([]*ToolboxTool, error) {
finalConfig := newToolConfig()
// Apply client-wide default options first.
for _, opt := range tc.defaultToolOptions {
if err := opt(finalConfig); err != nil {
return nil, err
}
}
// Then, apply the toolset-specific options provided in this call.
for _, opt := range opts {
if opt == nil {
return nil, fmt.Errorf("LoadToolset: received a nil ToolOption in options list")
}
if err := opt(finalConfig); err != nil {
return nil, err
}
}
checkSecureHeaders(tc.baseURL, len(finalConfig.AuthTokenSources) > 0)
// Fetch the manifest for the toolset.
resolvedHeaders, err := resolveClientHeaders(tc.clientHeaderSources)
if err != nil {
return nil, err
}
// Fetch Manifest via Transport
var manifest *transport.ManifestSchema
res, err := tc.executeWithFallback(func(tr transport.Transport) (any, error) {
return tr.ListTools(ctx, name, resolvedHeaders)
})
if err != nil {
return nil, fmt.Errorf("failed to load toolset manifest for '%s': %w", name, err)
}
manifest = res.(*transport.ManifestSchema)
if manifest.Tools == nil {
return nil, fmt.Errorf("toolset '%s' not found (manifest contains no tools)", name)
}
var tools []*ToolboxTool
overallUsedAuthKeys := make(map[string]struct{})
overallUsedBoundParams := make(map[string]struct{})
overallUsedSecureParams := make(map[string]struct{})
providedAuthKeys := make(map[string]struct{})
for k := range finalConfig.AuthTokenSources {
providedAuthKeys[k] = struct{}{}
}
providedBoundKeys := make(map[string]struct{})
for k := range finalConfig.BoundParams {
providedBoundKeys[k] = struct{}{}
}
providedSecureKeys := make(map[string]struct{})
for k := range finalConfig.SecureParams {
providedSecureKeys[k] = struct{}{}
}
tc.mu.RLock()
activeTransport := tc.transport
tc.mu.RUnlock()
for toolName, schema := range manifest.Tools {
// Construct each tool from its schema and the shared configuration.
tool, usedAuthKeys, usedBoundKeys, usedSecureKeys, err := tc.newToolboxTool(toolName, schema, finalConfig, finalConfig.Strict, activeTransport)
if err != nil {
return nil, fmt.Errorf("failed to create tool '%s': %w", toolName, err)
}
tools = append(tools, tool)
// Validation behavior depends on whether strict mode is enabled.
if finalConfig.Strict {
// In strict mode, validate each tool individually for unused options.
usedAuthSet := make(map[string]struct{})
for _, k := range usedAuthKeys {
usedAuthSet[k] = struct{}{}
}
usedBoundSet := make(map[string]struct{})
for _, k := range usedBoundKeys {
usedBoundSet[k] = struct{}{}
}
usedSecureSet := make(map[string]struct{})
for _, k := range usedSecureKeys {
usedSecureSet[k] = struct{}{}
}
unusedAuth := findUnusedKeys(providedAuthKeys, usedAuthSet)
unusedBound := findUnusedKeys(providedBoundKeys, usedBoundSet)
unusedSecure := findUnusedKeys(providedSecureKeys, usedSecureSet)
var errorMessages []string
if len(unusedAuth) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused auth tokens: %s", strings.Join(unusedAuth, ", ")))
}
if len(unusedBound) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused bound parameters: %s", strings.Join(unusedBound, ", ")))
}
if len(unusedSecure) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused secure parameters: %s", strings.Join(unusedSecure, ", ")))
}
if len(errorMessages) > 0 {
return nil, fmt.Errorf("validation failed for tool '%s': %s", toolName, strings.Join(errorMessages, "; "))
}
} else {
// In non-strict mode, aggregate all used keys across all tools.
// Validation will happen once at the end.
for _, k := range usedAuthKeys {
overallUsedAuthKeys[k] = struct{}{}
}
for _, k := range usedBoundKeys {
overallUsedBoundParams[k] = struct{}{}
}
for _, k := range usedSecureKeys {
overallUsedSecureParams[k] = struct{}{}
}
}
}
// For non-strict mode, perform a final validation to ensure all provided
// options were used by at least one tool in the set.
if !finalConfig.Strict {
unusedAuth := findUnusedKeys(providedAuthKeys, overallUsedAuthKeys)
unusedBound := findUnusedKeys(providedBoundKeys, overallUsedBoundParams)
unusedSecure := findUnusedKeys(providedSecureKeys, overallUsedSecureParams)
var errorMessages []string
if len(unusedAuth) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused auth tokens could not be applied to any tool: %s", strings.Join(unusedAuth, ", ")))
}
if len(unusedBound) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused bound parameters could not be applied to any tool: %s", strings.Join(unusedBound, ", ")))
}
if len(unusedSecure) > 0 {
errorMessages = append(errorMessages, fmt.Sprintf("unused secure parameters could not be applied to any tool: %s", strings.Join(unusedSecure, ", ")))
}
if len(errorMessages) > 0 {
if name == "" {
name = "default"
}
return nil, fmt.Errorf("validation failed for toolset '%s': %s", name, strings.Join(errorMessages, "; "))
}
}
return tools, nil
}
// GetProtocol returns the active protocol version for the client.
func (tc *ToolboxClient) GetProtocol() Protocol {
tc.mu.RLock()
defer tc.mu.RUnlock()
return tc.protocol
}
func (tc *ToolboxClient) executeWithFallback(fn func(tr transport.Transport) (any, error)) (any, error) {
for {
tc.mu.RLock()
tr := tc.transport
currentProtocol := tc.protocol
tc.mu.RUnlock()
result, err := fn(tr)
if err == nil {
return result, nil
}
var negErr *transport.ProtocolNegotiationError
if errors.As(err, &negErr) {
fallbackVersion := Protocol(negErr.FallbackVersion)
supportedVersions := GetSupportedMcpVersions()
serverIdx := -1
for i, v := range supportedVersions {
if Protocol(v) == fallbackVersion {
serverIdx = i
break
}
}
if serverIdx == -1 {
return nil, fmt.Errorf("server returned unknown protocol version: %s", fallbackVersion)
}
var serverSupported []Protocol
for _, v := range supportedVersions[serverIdx:] {
serverSupported = append(serverSupported, Protocol(v))
}
var fallbackProtocol Protocol
tc.mu.RLock()
supportedProtos := tc.supportedProtocols
tc.mu.RUnlock()
if len(supportedProtos) > 0 {
var mutuallySupported []Protocol
for _, v := range supportedProtos {
if slices.Contains(serverSupported, v) {
mutuallySupported = append(mutuallySupported, v)
}
}
if len(mutuallySupported) == 0 {
return nil, fmt.Errorf("no mutually supported protocol version. Client supports: %v, Server supports: %s", supportedProtos, fallbackVersion)
}
fallbackProtocol = mutuallySupported[0]
} else {
fallbackProtocol = fallbackVersion
}
if fallbackProtocol == currentProtocol {
return nil, err
}
var fallbackTransport transport.Transport
var createErr error
switch fallbackProtocol {
case MCPv20260728:
fallbackTransport, createErr = mcp20260728.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20251125:
fallbackTransport, createErr = mcp20251125.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20250618:
fallbackTransport, createErr = mcp20250618.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20250326:
fallbackTransport, createErr = mcp20250326.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
case MCPv20241105:
fallbackTransport, createErr = mcp20241105.New(tc.baseURL, tc.httpClient, tc.clientName, tc.clientVersion)
default:
return nil, fmt.Errorf("unsupported fallback protocol: %s", fallbackProtocol)
}
if createErr != nil {
return nil, fmt.Errorf("failed to create transport for fallback version %s: %w", fallbackProtocol, createErr)
}
tc.mu.Lock()
tc.protocol = fallbackProtocol
tc.transport = fallbackTransport
tc.mu.Unlock()
} else {
return nil, err
}
}
}