Skip to content

Commit b5db567

Browse files
committed
improve docs some more
1 parent 3943813 commit b5db567

File tree

7 files changed

+136
-184
lines changed

7 files changed

+136
-184
lines changed

www/docs/pages/clients/basics.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ MCP-Go provides client constructors for each supported transport. The choice of
1212
// STDIO client - for command-line tools
1313
client, err := client.NewStdioMCPClient("command", "arg1", "arg2")
1414

15-
// HTTP client - for web services
16-
client := client.NewStreamableHTTPClient("http://localhost:8080/mcp")
15+
// StreamableHTTP client - for web services
16+
client := client.NewStreamableHttpClient("http://localhost:8080/mcp")
1717

1818
// SSE client - for real-time web applications
1919
client := client.NewSSEMCPClient("http://localhost:8080/mcp/sse")
@@ -70,24 +70,24 @@ func createStdioClientWithEnv() (client.Client, error) {
7070
}
7171
```
7272

73-
### HTTP Client Creation
73+
### StreamableHTTP Client Creation
7474

7575
```go
76-
func createHTTPClient() client.Client {
77-
// Basic HTTP client
78-
httpTransport, err := NewStreamableHTTP(server.URL,
76+
func createStreamableHTTPClient() client.Client {
77+
// Basic StreamableHTTP client
78+
httpTransport, err := transport.NewStreamableHTTP(server.URL,
7979
// Set timeout
80-
WithHTTPTimeout(30*time.Second),
80+
transport.WithHTTPTimeout(30*time.Second),
8181
// Set custom headers
82-
WithHTTPHeaders(map[string]string{
82+
transport.WithHTTPHeaders(map[string]string{
8383
"X-Custom-Header": "custom-value",
8484
"Y-Another-Header": "another-value",
8585
}),
8686
// With custom HTTP client
87-
WithHTTPBasicClient(&http.Client{}),
87+
transport.WithHTTPBasicClient(&http.Client{}),
8888
)
8989
if err != nil {
90-
log.Fatalf("Failed to create HTTP transport: %v", err)
90+
log.Fatalf("Failed to create StreamableHTTP transport: %v", err)
9191
}
9292
c := client.NewClient(httpTransport)
9393
return c
@@ -240,7 +240,7 @@ func NewManagedClient(clientType, address string) (*ManagedClient, error) {
240240
switch clientType {
241241
case "stdio":
242242
c, err = client.NewSSEMCPClient("server-command")
243-
case "http":
243+
case "streamablehttp":
244244
c = client.NewStreamableHttpClient(address)
245245
case "sse":
246246
c = client.NewSSEMCPClient(address)

www/docs/pages/clients/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ func demonstrateClientOperations(ctx context.Context, c client.Client) error {
130130
client, err := client.NewStdioMCPClient("server-command", "arg1", "arg2")
131131
```
132132

133-
### HTTP Client
133+
### StreamableHTTP Client
134134
**Best for:**
135135
- Web applications
136136
- Microservice architectures
137137
- Load-balanced deployments
138138
- REST-like interactions
139139

140140
```go
141-
// Create HTTP client
141+
// Create StreamableHTTP client
142142
client := client.NewStreamableHttpClient("http://localhost:8080/mcp")
143143
```
144144

@@ -313,7 +313,7 @@ type LLMApplication struct {
313313
}
314314

315315
func NewLLMApplication(mcpAddress string) (*LLMApplication, error) {
316-
mcpClient := client.NewHTTPClient(mcpAddress)
316+
mcpClient := client.NewStreamableHttpClient(mcpAddress)
317317

318318
ctx := context.Background()
319319
if err := mcpClient.Initialize(ctx); err != nil {

www/docs/pages/clients/transports.mdx

Lines changed: 71 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MCP-Go provides client implementations for all supported transports. Each transp
99
| Transport | Best For | Connection | Real-time | Multi-client |
1010
|-----------|----------|------------|-----------|--------------|
1111
| **STDIO** | CLI tools, desktop apps | Process pipes | No | No |
12-
| **HTTP** | Web services, APIs | HTTP requests | No | Yes |
12+
| **StreamableHTTP** | Web services, APIs | HTTP requests | No | Yes |
1313
| **SSE** | Web apps, real-time | HTTP + EventSource | Yes | Yes |
1414
| **In-Process** | Testing, embedded | Direct calls | Yes | No |
1515

@@ -244,31 +244,20 @@ var (
244244
)
245245
```
246246

247-
## HTTP Client
247+
## StreamableHTTP Client
248248

249-
HTTP clients communicate with servers using traditional HTTP requests.
249+
StreamableHTTP clients communicate with servers using traditional HTTP requests.
250250

251-
### Basic HTTP Client
251+
### Basic StreamableHTTP Client
252252

253253
```go
254-
func createHTTPClient() {
255-
// Create HTTP client
256-
c := client.NewHTTPClient("http://localhost:8080/mcp")
254+
func createStreamableHTTPClient() {
255+
// Create StreamableHTTP client
256+
c := client.NewStreamableHttpClient("http://localhost:8080/mcp")
257257
defer c.Close()
258258

259-
// Set authentication
260-
c.SetHeader("Authorization", "Bearer your-token")
261-
c.SetHeader("X-API-Version", "v1")
262-
263-
// Set timeout
264-
c.SetTimeout(30 * time.Second)
265-
266259
ctx := context.Background()
267260

268-
if err := c.Start(ctx); err != nil {
269-
return
270-
}
271-
272261
// Initialize
273262
if err := c.Initialize(ctx); err != nil {
274263
log.Fatal(err)
@@ -284,31 +273,30 @@ func createHTTPClient() {
284273
}
285274
```
286275

287-
### HTTP Client with Custom Configuration
276+
### StreamableHTTP Client with Custom Configuration
288277

289278
```go
290-
func createCustomHTTPClient() {
291-
// Create custom HTTP client
292-
httpClient := &http.Client{
293-
Timeout: 30 * time.Second,
294-
Transport: &http.Transport{
295-
MaxIdleConns: 100,
296-
MaxIdleConnsPerHost: 10,
297-
IdleConnTimeout: 90 * time.Second,
298-
TLSClientConfig: &tls.Config{
299-
InsecureSkipVerify: false,
279+
func createCustomStreamableHTTPClient() {
280+
// Create StreamableHTTP client with options
281+
c := client.NewStreamableHttpClient("https://api.example.com/mcp",
282+
transport.WithHTTPTimeout(30*time.Second),
283+
transport.WithHTTPHeaders(map[string]string{
284+
"User-Agent": "MyApp/1.0",
285+
"Accept": "application/json",
286+
}),
287+
transport.WithHTTPBasicClient(&http.Client{
288+
Transport: &http.Transport{
289+
MaxIdleConns: 100,
290+
MaxIdleConnsPerHost: 10,
291+
IdleConnTimeout: 90 * time.Second,
292+
TLSClientConfig: &tls.Config{
293+
InsecureSkipVerify: false,
294+
},
300295
},
301-
},
302-
}
303-
304-
// Create MCP client with custom HTTP client
305-
c := client.NewHTTPClientWithClient("https://api.example.com/mcp", httpClient)
296+
}),
297+
)
306298
defer c.Close()
307299

308-
// Set custom headers
309-
c.SetHeader("User-Agent", "MyApp/1.0")
310-
c.SetHeader("Accept", "application/json")
311-
312300
ctx := context.Background()
313301

314302
if err := c.Initialize(ctx); err != nil {
@@ -319,68 +307,28 @@ func createCustomHTTPClient() {
319307
}
320308
```
321309

322-
### HTTP Authentication
310+
### StreamableHTTP Authentication
323311

324312
```go
325-
type AuthenticatedHTTPClient struct {
326-
client *client.HTTPClient
327-
tokenSource TokenSource
328-
mutex sync.RWMutex
329-
}
330-
331-
type TokenSource interface {
332-
Token() (string, error)
333-
Refresh() error
334-
}
335-
336-
func NewAuthenticatedHTTPClient(baseURL string, tokenSource TokenSource) *AuthenticatedHTTPClient {
337-
return &AuthenticatedHTTPClient{
338-
client: client.NewHTTPClient(baseURL),
339-
tokenSource: tokenSource,
340-
}
341-
}
342-
343-
func (ahc *AuthenticatedHTTPClient) ensureValidToken() error {
344-
ahc.mutex.Lock()
345-
defer ahc.mutex.Unlock()
346-
347-
token, err := ahc.tokenSource.Token()
348-
if err != nil {
349-
// Try to refresh token
350-
if refreshErr := ahc.tokenSource.Refresh(); refreshErr != nil {
351-
return fmt.Errorf("failed to refresh token: %w", refreshErr)
352-
}
353-
354-
token, err = ahc.tokenSource.Token()
355-
if err != nil {
356-
return fmt.Errorf("failed to get token after refresh: %w", err)
357-
}
358-
}
359-
360-
ahc.client.SetHeader("Authorization", "Bearer "+token)
361-
return nil
362-
}
363-
364-
func (ahc *AuthenticatedHTTPClient) CallTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
365-
if err := ahc.ensureValidToken(); err != nil {
366-
return nil, err
367-
}
368-
369-
result, err := ahc.client.CallTool(ctx, req)
370-
if err != nil && isAuthError(err) {
371-
// Token might be expired, refresh and retry
372-
if refreshErr := ahc.tokenSource.Refresh(); refreshErr != nil {
373-
return nil, fmt.Errorf("authentication failed: %w", err)
374-
}
313+
func createAuthenticatedStreamableHTTPClient() {
314+
// Create StreamableHTTP client with OAuth
315+
c := client.NewStreamableHttpClient("http://localhost:8080/mcp",
316+
transport.WithHTTPOAuth(transport.OAuthConfig{
317+
ClientID: "your-client-id",
318+
ClientSecret: "your-client-secret",
319+
TokenURL: "https://auth.example.com/token",
320+
Scopes: []string{"mcp:read", "mcp:write"},
321+
}),
322+
)
323+
defer c.Close()
375324

376-
if err := ahc.ensureValidToken(); err != nil {
377-
return nil, err
378-
}
325+
ctx := context.Background()
379326

380-
return ahc.client.CallTool(ctx, req)
327+
if err := c.Initialize(ctx); err != nil {
328+
log.Fatal(err)
381329
}
382330

383-
return result, err
331+
// Use client...
384332
}
385333

386334
func isAuthError(err error) bool {
@@ -389,21 +337,21 @@ func isAuthError(err error) bool {
389337
}
390338
```
391339

392-
### HTTP Connection Pooling
340+
### StreamableHTTP Connection Pooling
393341

394342
```go
395-
type HTTPClientPool struct {
396-
clients chan *client.HTTPClient
397-
factory func() *client.HTTPClient
343+
type StreamableHTTPClientPool struct {
344+
clients chan *client.Client
345+
factory func() *client.Client
398346
maxSize int
399347
}
400348

401-
func NewHTTPClientPool(baseURL string, maxSize int) *HTTPClientPool {
402-
pool := &HTTPClientPool{
403-
clients: make(chan *client.HTTPClient, maxSize),
349+
func NewStreamableHTTPClientPool(baseURL string, maxSize int) *StreamableHTTPClientPool {
350+
pool := &StreamableHTTPClientPool{
351+
clients: make(chan *client.Client, maxSize),
404352
maxSize: maxSize,
405-
factory: func() *client.HTTPClient {
406-
return client.NewHTTPClient(baseURL)
353+
factory: func() *client.Client {
354+
return client.NewStreamableHttpClient(baseURL)
407355
},
408356
}
409357

@@ -415,7 +363,7 @@ func NewHTTPClientPool(baseURL string, maxSize int) *HTTPClientPool {
415363
return pool
416364
}
417365

418-
func (pool *HTTPClientPool) Get() *client.HTTPClient {
366+
func (pool *StreamableHTTPClientPool) Get() *client.Client {
419367
select {
420368
case c := <-pool.clients:
421369
return c
@@ -424,7 +372,7 @@ func (pool *HTTPClientPool) Get() *client.HTTPClient {
424372
}
425373
}
426374

427-
func (pool *HTTPClientPool) Put(c *client.HTTPClient) {
375+
func (pool *StreamableHTTPClientPool) Put(c *client.Client) {
428376
select {
429377
case pool.clients <- c:
430378
default:
@@ -433,7 +381,7 @@ func (pool *HTTPClientPool) Put(c *client.HTTPClient) {
433381
}
434382
}
435383

436-
func (pool *HTTPClientPool) CallTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
384+
func (pool *StreamableHTTPClientPool) CallTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
437385
c := pool.Get()
438386
defer pool.Put(c)
439387

@@ -865,7 +813,7 @@ func SelectTransport(req TransportRequirements) string {
865813
return "sse"
866814

867815
case req.NetworkRequired && req.MultiClient:
868-
return "http"
816+
return "streamablehttp"
869817

870818
default:
871819
return "stdio" // Default fallback
@@ -926,8 +874,8 @@ func (cf *ClientFactory) SetStdioConfig(command string, args ...string) {
926874
}
927875
}
928876

929-
func (cf *ClientFactory) SetHTTPConfig(baseURL string, headers map[string]string) {
930-
cf.configs["http"] = struct {
877+
func (cf *ClientFactory) SetStreamableHTTPConfig(baseURL string, headers map[string]string) {
878+
cf.configs["streamablehttp"] = struct {
931879
BaseURL string
932880
Headers map[string]string
933881
}{
@@ -955,20 +903,21 @@ func (cf *ClientFactory) CreateClient(transport string) (client.Client, error) {
955903
}
956904
return client.NewStdioClientWithOptions(config)
957905

958-
case "http":
959-
config, ok := cf.configs["http"].(struct {
906+
case "streamablehttp":
907+
config, ok := cf.configs["streamablehttp"].(struct {
960908
BaseURL string
961909
Headers map[string]string
962910
})
963911
if !ok {
964-
return nil, fmt.Errorf("http config not set")
912+
return nil, fmt.Errorf("streamablehttp config not set")
965913
}
966914

967-
c := client.NewHTTPClient(config.BaseURL)
968-
for key, value := range config.Headers {
969-
c.SetHeader(key, value)
915+
options := []transport.StreamableHTTPCOption{}
916+
if len(config.Headers) > 0 {
917+
options = append(options, transport.WithHTTPHeaders(config.Headers))
970918
}
971-
return c, nil
919+
920+
return client.NewStreamableHttpClient(config.BaseURL, options...), nil
972921

973922
case "sse":
974923
config, ok := cf.configs["sse"].(struct {
@@ -979,11 +928,12 @@ func (cf *ClientFactory) CreateClient(transport string) (client.Client, error) {
979928
return nil, fmt.Errorf("sse config not set")
980929
}
981930

982-
c := client.NewSSEClient(config.BaseURL)
983-
for key, value := range config.Headers {
984-
c.SetHeader(key, value)
931+
options := []transport.ClientOption{}
932+
if len(config.Headers) > 0 {
933+
options = append(options, transport.WithHeaders(config.Headers))
985934
}
986-
return c, nil
935+
936+
return client.NewSSEMCPClient(config.BaseURL, options...)
987937

988938
default:
989939
return nil, fmt.Errorf("unknown transport: %s", transport)
@@ -996,7 +946,7 @@ func demonstrateClientFactory() {
996946

997947
// Configure transports
998948
factory.SetStdioConfig("go", "run", "server.go")
999-
factory.SetHTTPConfig("http://localhost:8080/mcp", map[string]string{
949+
factory.SetStreamableHTTPConfig("http://localhost:8080/mcp", map[string]string{
1000950
"Authorization": "Bearer token",
1001951
})
1002952
factory.SetSSEConfig("http://localhost:8080/mcp/sse", map[string]string{

0 commit comments

Comments
 (0)