Skip to content

Commit 3943813

Browse files
authored
Optimize docs (#386)
Optimize docs
1 parent 8c7a09d commit 3943813

File tree

5 files changed

+69
-112
lines changed

5 files changed

+69
-112
lines changed

www/docs/pages/clients/basics.mdx

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ MCP-Go provides client constructors for each supported transport. The choice of
1010

1111
```go
1212
// STDIO client - for command-line tools
13-
client, err := client.NewStdioClient("command", "arg1", "arg2")
13+
client, err := client.NewStdioMCPClient("command", "arg1", "arg2")
1414

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

1818
// SSE client - for real-time web applications
19-
client := client.NewSSEClient("http://localhost:8080/mcp/sse")
19+
client := client.NewSSEMCPClient("http://localhost:8080/mcp/sse")
2020

2121
// In-process client - for testing and embedded scenarios
2222
client := client.NewInProcessClient(server)
@@ -43,8 +43,8 @@ import (
4343

4444
func createStdioClient() (client.Client, error) {
4545
// Create client that spawns a subprocess
46-
c, err := client.NewStdioClient(
47-
"go", "run", "/path/to/server/main.go",
46+
c, err := client.NewStdioMCPClient(
47+
"go", []string{}, "run", "/path/to/server/main.go",
4848
)
4949
if err != nil {
5050
return nil, fmt.Errorf("failed to create STDIO client: %w", err)
@@ -55,16 +55,13 @@ func createStdioClient() (client.Client, error) {
5555

5656
// With custom environment variables
5757
func createStdioClientWithEnv() (client.Client, error) {
58-
c, err := client.NewStdioClientWithOptions(client.StdioOptions{
59-
Command: "go",
60-
Args: []string{"run", "/path/to/server/main.go"},
61-
Env: []string{
62-
"LOG_LEVEL=debug",
63-
"DATABASE_URL=sqlite://test.db",
64-
},
65-
WorkingDir: "/path/to/server",
66-
Timeout: 30 * time.Second,
67-
})
58+
env := []string{
59+
"LOG_LEVEL=debug",
60+
"DATABASE_URL=sqlite://test.db",
61+
}
62+
c, err := client.NewStdioMCPClient(
63+
"go", env, "run", "/path/to/server/main.go",
64+
)
6865
if err != nil {
6966
return nil, fmt.Errorf("failed to create STDIO client: %w", err)
7067
}
@@ -78,30 +75,22 @@ func createStdioClientWithEnv() (client.Client, error) {
7875
```go
7976
func createHTTPClient() client.Client {
8077
// Basic HTTP client
81-
c := client.NewHTTPClient("http://localhost:8080/mcp")
82-
83-
// Set custom headers
84-
c.SetHeader("Authorization", "Bearer your-token")
85-
c.SetHeader("X-API-Version", "v1")
86-
87-
// Set timeout
88-
c.SetTimeout(30 * time.Second)
89-
90-
return c
91-
}
92-
93-
// With custom HTTP client
94-
func createCustomHTTPClient() client.Client {
95-
httpClient := &http.Client{
96-
Timeout: 30 * time.Second,
97-
Transport: &http.Transport{
98-
MaxIdleConns: 100,
99-
MaxIdleConnsPerHost: 10,
100-
IdleConnTimeout: 90 * time.Second,
101-
},
78+
httpTransport, err := NewStreamableHTTP(server.URL,
79+
// Set timeout
80+
WithHTTPTimeout(30*time.Second),
81+
// Set custom headers
82+
WithHTTPHeaders(map[string]string{
83+
"X-Custom-Header": "custom-value",
84+
"Y-Another-Header": "another-value",
85+
}),
86+
// With custom HTTP client
87+
WithHTTPBasicClient(&http.Client{}),
88+
)
89+
if err != nil {
90+
log.Fatalf("Failed to create HTTP transport: %v", err)
10291
}
103-
104-
return client.NewHTTPClientWithClient("http://localhost:8080/mcp", httpClient)
92+
c := client.NewClient(httpTransport)
93+
return c
10594
}
10695
```
10796

@@ -110,29 +99,15 @@ func createCustomHTTPClient() client.Client {
11099
```go
111100
func createSSEClient() client.Client {
112101
// Basic SSE client
113-
c := client.NewSSEClient("http://localhost:8080/mcp/sse")
114-
115-
// Set authentication
116-
c.SetHeader("Authorization", "Bearer your-token")
117-
102+
c, err := NewSSEMCPClient(testServer.URL+"/sse",
103+
// Set custom headers
104+
WithHeaders(map[string]string{
105+
"X-Custom-Header": "custom-value",
106+
"Y-Another-Header": "another-value",
107+
}),
108+
)
118109
return c
119110
}
120-
121-
// With custom options
122-
func createSSEClientWithOptions() client.Client {
123-
options := client.SSEOptions{
124-
URL: "http://localhost:8080/mcp/sse",
125-
Headers: map[string]string{
126-
"Authorization": "Bearer your-token",
127-
"X-Client-ID": "my-app",
128-
},
129-
ReconnectInterval: 5 * time.Second,
130-
MaxReconnects: 10,
131-
BufferSize: 1000,
132-
}
133-
134-
return client.NewSSEClientWithOptions(options)
135-
}
136111
```
137112

138113
## Client Lifecycle
@@ -151,7 +126,7 @@ Understanding the client lifecycle is crucial for proper resource management and
151126
```go
152127
func demonstrateClientLifecycle() error {
153128
// 1. Creation
154-
c, err := client.NewStdioClient("server-command")
129+
c, err := client.NewSSEMCPClient("server-command")
155130
if err != nil {
156131
return fmt.Errorf("client creation failed: %w", err)
157132
}
@@ -264,11 +239,11 @@ func NewManagedClient(clientType, address string) (*ManagedClient, error) {
264239

265240
switch clientType {
266241
case "stdio":
267-
c, err = client.NewStdioClient("server-command")
242+
c, err = client.NewSSEMCPClient("server-command")
268243
case "http":
269-
c = client.NewHTTPClient(address)
244+
c = client.NewStreamableHttpClient(address)
270245
case "sse":
271-
c = client.NewSSEClient(address)
246+
c = client.NewSSEMCPClient(address)
272247
default:
273248
return nil, fmt.Errorf("unknown client type: %s", clientType)
274249
}

www/docs/pages/clients/index.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030

3131
func main() {
3232
// Create STDIO client
33-
c, err := client.NewStdioClient(
34-
"go", "run", "/path/to/server/main.go",
33+
c, err := client.NewStdioMCPClient(
34+
"go", []string{} , "run", "/path/to/server/main.go",
3535
)
3636
if err != nil {
3737
log.Fatal(err)
@@ -41,7 +41,7 @@ func main() {
4141
ctx := context.Background()
4242

4343
// Initialize the connection
44-
if err := c.Initialize(ctx); err != nil {
44+
if err := c.Initialize(ctx, initRequest); err != nil {
4545
log.Fatal(err)
4646
}
4747

@@ -127,7 +127,7 @@ func demonstrateClientOperations(ctx context.Context, c client.Client) error {
127127

128128
```go
129129
// Create STDIO client
130-
client, err := client.NewStdioClient("server-command", "arg1", "arg2")
130+
client, err := client.NewStdioMCPClient("server-command", "arg1", "arg2")
131131
```
132132

133133
### HTTP Client
@@ -139,7 +139,7 @@ client, err := client.NewStdioClient("server-command", "arg1", "arg2")
139139

140140
```go
141141
// Create HTTP client
142-
client := client.NewHTTPClient("http://localhost:8080/mcp")
142+
client := client.NewStreamableHttpClient("http://localhost:8080/mcp")
143143
```
144144

145145
### SSE Client
@@ -151,7 +151,7 @@ client := client.NewHTTPClient("http://localhost:8080/mcp")
151151

152152
```go
153153
// Create SSE client
154-
client := client.NewSSEClient("http://localhost:8080/mcp/sse")
154+
client := client.NewSSEMCPClient("http://localhost:8080/mcp/sse")
155155
```
156156

157157
### In-Process Client
@@ -195,11 +195,11 @@ func NewMCPClientManager(clientType, address string) (*MCPClientManager, error)
195195

196196
switch clientType {
197197
case "stdio":
198-
c, err = client.NewStdioClient("server-command")
198+
c, err = client.NewStdioMCPClient("server-command")
199199
case "http":
200-
c = client.NewHTTPClient(address)
200+
c = client.NewStreamableHttpClient(address)
201201
case "sse":
202-
c = client.NewSSEClient(address)
202+
c = client.NewSSEMCPClient(address)
203203
default:
204204
return nil, fmt.Errorf("unknown client type: %s", clientType)
205205
}
@@ -385,9 +385,9 @@ func (msc *MultiServerClient) AddServer(name, address string, clientType string)
385385

386386
switch clientType {
387387
case "http":
388-
c = client.NewHTTPClient(address)
388+
c = client.NewStreamableHttpClient(address)
389389
case "sse":
390-
c = client.NewSSEClient(address)
390+
c = client.NewSSEMCPClient(address)
391391
default:
392392
return fmt.Errorf("unsupported client type: %s", clientType)
393393
}

www/docs/pages/clients/transports.mdx

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import (
4040

4141
func createStdioClient() {
4242
// Create client that spawns a subprocess
43-
c, err := client.NewStdioClient(
44-
"go", "run", "/path/to/server/main.go",
43+
c, err := client.NewStdioMCPClient(
44+
"go", []string{}, "run", "/path/to/server/main.go",
4545
)
4646
if err != nil {
4747
log.Fatal(err)
@@ -51,12 +51,12 @@ func createStdioClient() {
5151
ctx := context.Background()
5252

5353
// Initialize connection
54-
if err := c.Initialize(ctx); err != nil {
54+
if err := c.Initialize(ctx, initRequest); err != nil {
5555
log.Fatal(err)
5656
}
5757

5858
// Use the client
59-
tools, err := c.ListTools(ctx)
59+
tools, err := c.ListTools(ctx, listToolsRequest)
6060
if err != nil {
6161
log.Fatal(err)
6262
}
@@ -65,36 +65,6 @@ func createStdioClient() {
6565
}
6666
```
6767

68-
### Advanced STDIO Configuration
69-
70-
```go
71-
func createAdvancedStdioClient() {
72-
options := client.StdioOptions{
73-
Command: "python",
74-
Args: []string{"/path/to/server.py"},
75-
Env: []string{
76-
"PYTHONPATH=/custom/path",
77-
"LOG_LEVEL=debug",
78-
"DATABASE_URL=sqlite:///data.db",
79-
},
80-
WorkingDir: "/path/to/server",
81-
Timeout: 30 * time.Second,
82-
BufferSize: 8192,
83-
RestartOnError: true,
84-
MaxRestarts: 3,
85-
RestartDelay: 1 * time.Second,
86-
}
87-
88-
c, err := client.NewStdioClientWithOptions(options)
89-
if err != nil {
90-
log.Fatal(err)
91-
}
92-
defer c.Close()
93-
94-
// Use client...
95-
}
96-
```
97-
9868
### STDIO Error Handling
9969

10070
```go
@@ -295,6 +265,10 @@ func createHTTPClient() {
295265

296266
ctx := context.Background()
297267

268+
if err := c.Start(ctx); err != nil {
269+
return
270+
}
271+
298272
// Initialize
299273
if err := c.Initialize(ctx); err != nil {
300274
log.Fatal(err)

www/docs/pages/getting-started.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MCP-Go is designed to make building MCP servers in Go fast, simple, and complete
2020
- **Minimal boilerplate**: Get started with just a few lines of code
2121
- **Full MCP spec support**: Tools, resources, prompts, and all transport methods
2222
- **Type safety**: Leverage Go's type system for robust MCP servers
23-
- **Multiple transports**: Stdio, HTTP, and Server-Sent Events support
23+
- **Multiple transports**: Stdio, HTTP, Server-Sent Events and In-Process support
2424

2525
### Installation
2626

@@ -151,6 +151,7 @@ MCP-Go supports multiple transport methods:
151151
- **Stdio** (most common): `server.ServeStdio(s)`
152152
- **HTTP**: `server.ServeHTTP(s, ":8080")`
153153
- **Server-Sent Events**: `server.ServeSSE(s, ":8080")`
154+
- **In-Process**: `client.NewInProcessClient(server)`
154155

155156
## Need Help?
156157

www/docs/pages/quick-start.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ import (
121121

122122
func main() {
123123
// Create a stdio client that connects to another MCP server
124-
c, err := client.NewStdioClient(
124+
// NTOE: NewStdioMCPClient will start the connection automatically. Don't call the Start method manually
125+
c, err := client.NewStdioMCPClient(
125126
"go", "run", "path/to/server/main.go",
126127
)
127128
if err != nil {
@@ -149,7 +150,7 @@ func main() {
149150

150151
// Call a tool
151152
result, err := c.CallTool(ctx, mcp.CallToolRequest{
152-
Params: mcp.CallToolRequestParams{
153+
Params: mcp.CallToolParams{
153154
Name: "hello_world",
154155
Arguments: map[string]interface{}{
155156
"name": "World",
@@ -187,11 +188,17 @@ import (
187188

188189
func main() {
189190
// Create an HTTP client
190-
c := client.NewHTTPClient("http://localhost:8080/mcp")
191+
c, _ := client.NewStreamableHttpClient("http://localhost:8080/mcp")
191192
defer c.Close()
192193

193194
ctx := context.Background()
194195

196+
// Start initiates the connection to the server
197+
if err := c.Start(ctx); err != nil {
198+
log.Fatal(err)
199+
return
200+
}
201+
195202
// Initialize and use the client
196203
if err := c.Initialize(ctx); err != nil {
197204
log.Fatal(err)

0 commit comments

Comments
 (0)