Skip to content

Commit ec7f2ab

Browse files
committed
fixes
1 parent d066c97 commit ec7f2ab

File tree

6 files changed

+64
-68
lines changed

6 files changed

+64
-68
lines changed

www/docs/pages/servers/advanced.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package main
1313

1414
import (
1515
"context"
16+
"encoding/json"
1617
"fmt"
1718

1819
"github.com/mark3labs/mcp-go/mcp"
@@ -120,13 +121,15 @@ func handleCreateUser(ctx context.Context, req mcp.CallToolRequest, input UserCr
120121
return nil, fmt.Errorf("failed to create user: %w", err)
121122
}
122123

123-
return &UserCreateOutput{
124+
output := &UserCreateOutput{
124125
ID: user.ID,
125126
Name: user.Name,
126127
Email: user.Email,
127128
CreatedAt: user.CreatedAt,
128129
Status: "created",
129-
}, nil
130+
}
131+
132+
return mcp.NewToolResultJSON(output), nil
130133
}
131134
```
132135

@@ -302,6 +305,7 @@ func NewLoggingMiddleware(logger *log.Logger) *LoggingMiddleware {
302305
func (m *LoggingMiddleware) ToolMiddleware(next server.ToolHandlerFunc) server.ToolHandlerFunc {
303306
return func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
304307
start := time.Now()
308+
sessionID := server.GetSessionID(ctx)
305309

306310
m.logger.Printf("Tool call started: tool=%s", req.Params.Name)
307311

www/docs/pages/servers/prompts.mdx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,7 @@ func handleCodeReview(ctx context.Context, req mcp.GetPromptRequest) (*mcp.GetPr
8989
Messages: []mcp.PromptMessage{
9090
{
9191
Role: "user",
92-
Content: mcp.NewTextContent(fmt.Sprintf(`Please review the following %s code:
93-
94-
%s
95-
96-
Instructions: %s
97-
98-
Please provide:
99-
1. Overall assessment
100-
2. Specific issues found
101-
3. Suggested improvements
102-
4. Best practice recommendations
103-
104-
Code:
105-
```%s
106-
%s
107-
````, language, instructions, language, code)),
92+
Content: mcp.NewTextContent(fmt.Sprintf("Please review the following %s code:\n\n%s\n\nInstructions: %s\n\nPlease provide:\n1. Overall assessment\n2. Specific issues found\n3. Suggested improvements\n4. Best practice recommendations\n\nCode:\n```%s\n%s\n```", language, instructions, language, code)),
10893
},
10994
},
11095
}, nil

www/docs/pages/servers/resources.mdx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ func handleAppConfig(ctx context.Context, req mcp.ReadResourceRequest) (*mcp.Rea
9797
return nil, err
9898
}
9999

100-
return []mcp.ResourceContents{
101-
mcp.TextResourceContents{
102-
URI: req.Params.URI,
103-
MIMEType: "application/json",
104-
Text: string(configJSON),
100+
return &mcp.ReadResourceResult{
101+
Contents: []mcp.ResourceContent{
102+
mcp.TextResourceContent{
103+
URI: req.Params.URI,
104+
MIMEType: "application/json",
105+
Text: string(configJSON),
106+
},
105107
},
106108
}, nil
107109
}
@@ -166,6 +168,16 @@ func extractUserID(uri string) string {
166168
Expose database records dynamically:
167169

168170
```go
171+
import (
172+
"context"
173+
"database/sql"
174+
"encoding/json"
175+
"fmt"
176+
177+
"github.com/mark3labs/mcp-go/mcp"
178+
"github.com/mark3labs/mcp-go/server"
179+
)
180+
169181
// Database table resource
170182
s.AddResource(
171183
mcp.NewResource(
@@ -205,14 +217,17 @@ func handleDatabaseRecord(ctx context.Context, req mcp.ReadResourceRequest) (*mc
205217
return nil, err
206218
}
207219

208-
return []mcp.ResourceContents{
209-
mcp.TextResourceContents{
210-
URI: req.Params.URI,
211-
MIMEType: "application/json",
212-
Text: string(jsonData),
220+
return &mcp.ReadResourceResult{
221+
Contents: []mcp.ResourceContent{
222+
mcp.TextResourceContent{
223+
URI: req.Params.URI,
224+
MIMEType: "application/json",
225+
Text: string(jsonData),
226+
},
213227
},
214228
}, nil
215229
}
230+
}
216231
```
217232

218233
### API Resources
@@ -434,14 +449,17 @@ func handleResourceWithTimeout(ctx context.Context, req mcp.ReadResourceRequest)
434449
return nil, err
435450
}
436451

437-
return []mcp.ResourceContents{
438-
mcp.TextResourceContents{
439-
URI: req.Params.URI,
440-
MIMEType: "application/json",
441-
Text: string(jsonData),
452+
return &mcp.ReadResourceResult{
453+
Contents: []mcp.ResourceContent{
454+
mcp.TextResourceContent{
455+
URI: req.Params.URI,
456+
MIMEType: "application/json",
457+
Text: string(jsonData),
458+
},
442459
},
443460
}, nil
444461
}
462+
}
445463
```
446464

447465
## Resource Listing

www/docs/pages/servers/tools.mdx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,21 @@ func handleCreateFile(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo
257257

258258
```go
259259
func handleDatabaseQuery(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
260-
query, err := req.RequireString("query")
261-
if err != nil {
262-
return mcp.NewToolResultError(err.Error()), nil
263-
}
264-
265-
// Handle optional params array
266-
var params []interface{}
267-
if err := req.BindArguments(&struct {
260+
// Define struct to bind both Query and Params
261+
var args struct {
268262
Query string `json:"query"`
269263
Params []interface{} `json:"params"`
270-
}{Params: params}); err == nil {
271-
// params extracted successfully
272264
}
273265

266+
// Bind arguments to the struct
267+
if err := req.BindArguments(&args); err != nil {
268+
return mcp.NewToolResultError(err.Error()), nil
269+
}
270+
271+
// Extract values from the bound struct
272+
query := args.Query
273+
params := args.Params
274+
274275
// Validate query for security (basic example)
275276
if !isSelectQuery(query) {
276277
return mcp.NewToolResultError("only SELECT queries are allowed"), nil
@@ -583,15 +584,6 @@ tool := mcp.NewTool("search_database",
583584
mcp.Items(mcp.StringSchema()),
584585
),
585586
)
586-
},
587-
{
588-
Description: "Find all products in electronics category",
589-
Arguments: map[string]interface{}{
590-
"query": "*",
591-
"categories": []string{"electronics"},
592-
},
593-
),
594-
)
595587

596588
s.AddTool(tool, handleSearchDatabase)
597589
```

www/docs/pages/transports/http.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,6 @@ func main() {
281281
}
282282

283283
// Helper functions for the advanced example
284-
func setupHTTPMiddleware(s *server.MCPServer) {
285-
// Placeholder implementation - would add middleware
286-
}
287-
288284
func addCRUDTools(s *server.MCPServer) {
289285
// Placeholder implementation - would add CRUD tools
290286
}

www/docs/pages/transports/stdio.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ func detectMIMEType(path string) string {
188188
### Advanced STDIO Server
189189

190190
```go
191+
import (
192+
"context"
193+
"fmt"
194+
"log"
195+
"os"
196+
"os/signal"
197+
"syscall"
198+
"time"
199+
200+
"github.com/mark3labs/mcp-go/mcp"
201+
"github.com/mark3labs/mcp-go/server"
202+
)
203+
191204
func main() {
192205
s := server.NewMCPServer("Advanced CLI Tool", "1.0.0",
193206
server.WithAllCapabilities(),
@@ -201,18 +214,6 @@ func main() {
201214
},
202215
}),
203216
)
204-
import (
205-
"context"
206-
"fmt"
207-
"log"
208-
"os"
209-
"os/signal"
210-
"syscall"
211-
"time"
212-
213-
"github.com/mark3labs/mcp-go/mcp"
214-
"github.com/mark3labs/mcp-go/server"
215-
)
216217

217218
// Add comprehensive tools
218219
addSystemTools(s)

0 commit comments

Comments
 (0)