Skip to content

Commit 1e2c65c

Browse files
committed
Dots
1 parent e312ab5 commit 1e2c65c

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

examples/http/logging_middleware.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
// responseWriter wraps http.ResponseWriter to capture the status code
13+
// responseWriter wraps http.ResponseWriter to capture the status code.
1414
type responseWriter struct {
1515
http.ResponseWriter
1616
statusCode int
@@ -25,20 +25,20 @@ func loggingHandler(handler http.Handler) http.Handler {
2525
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2626
start := time.Now()
2727

28-
// Create a response writer wrapper to capture status code
28+
// Create a response writer wrapper to capture status code.
2929
wrapped := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
3030

31-
// Log request details
31+
// Log request details.
3232
log.Printf("[REQUEST] %s | %s | %s %s",
3333
start.Format(time.RFC3339),
3434
r.RemoteAddr,
3535
r.Method,
3636
r.URL.Path)
3737

38-
// Call the actual handler
38+
// Call the actual handler.
3939
handler.ServeHTTP(wrapped, r)
4040

41-
// Log response details
41+
// Log response details.
4242
duration := time.Since(start)
4343
log.Printf("[RESPONSE] %s | %s | %s %s | Status: %d | Duration: %v",
4444
time.Now().Format(time.RFC3339),

examples/http/main.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
os.Exit(1)
3636
}
3737

38-
// Check if we have at least one argument
38+
// Check if we have at least one argument.
3939
if len(os.Args) < 2 {
4040
fmt.Fprintf(os.Stderr, "Error: Must specify 'client' or 'server' as first argument\n\n")
4141
flag.Usage()
@@ -56,12 +56,12 @@ func main() {
5656
}
5757
}
5858

59-
// GetTimeParams defines the parameters for the cityTime tool
59+
// GetTimeParams defines the parameters for the cityTime tool.
6060
type GetTimeParams struct {
6161
City string `json:"city" jsonschema:"City to get time for (nyc, sf, or boston)"`
6262
}
6363

64-
// getTime implements the tool that returns the current time for a given city
64+
// getTime implements the tool that returns the current time for a given city.
6565
func getTime(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[GetTimeParams]) (*mcp.CallToolResultFor[any], error) {
6666
// Define time zones for each city
6767
locations := map[string]string{
@@ -75,22 +75,22 @@ func getTime(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolPar
7575
city = "nyc" // Default to NYC
7676
}
7777

78-
// Get the timezone
78+
// Get the timezone.
7979
tzName, ok := locations[city]
8080
if !ok {
8181
return nil, fmt.Errorf("unknown city: %s", city)
8282
}
8383

84-
// Load the location
84+
// Load the location.
8585
loc, err := time.LoadLocation(tzName)
8686
if err != nil {
8787
return nil, fmt.Errorf("failed to load timezone: %w", err)
8888
}
8989

90-
// Get current time in that location
90+
// Get current time in that location.
9191
now := time.Now().In(loc)
9292

93-
// Format the response
93+
// Format the response.
9494
cityNames := map[string]string{
9595
"nyc": "New York City",
9696
"sf": "San Francisco",
@@ -109,19 +109,19 @@ func getTime(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolPar
109109
}
110110

111111
func runServer(host, port string) {
112-
// Create an MCP server
112+
// Create an MCP server.
113113
server := mcp.NewServer(&mcp.Implementation{
114114
Name: "time-server",
115115
Version: "1.0.0",
116116
}, nil)
117117

118-
// Add the cityTime tool
118+
// Add the cityTime tool.
119119
mcp.AddTool(server, &mcp.Tool{
120120
Name: "cityTime",
121121
Description: "Get the current time in NYC, San Francisco, or Boston",
122122
}, getTime)
123123

124-
// Create the streamable HTTP handler
124+
// Create the streamable HTTP handler.
125125
handler := mcp.NewStreamableHTTPHandler(func(req *http.Request) *mcp.Server {
126126
return server
127127
}, nil)
@@ -132,7 +132,7 @@ func runServer(host, port string) {
132132
log.Printf("MCP server listening on http://%s", addr)
133133
log.Printf("Available tool: cityTime (cities: nyc, sf, boston)")
134134

135-
// Start the HTTP server with logging handler
135+
// Start the HTTP server with logging handler.
136136
if err := http.ListenAndServe(addr, handlerWithLogging); err != nil {
137137
log.Fatalf("Server failed: %v", err)
138138
}
@@ -141,20 +141,20 @@ func runServer(host, port string) {
141141
func runClient(host, port string) {
142142
ctx := context.Background()
143143

144-
// Create the URL for the server
144+
// Create the URL for the server.
145145
url := fmt.Sprintf("http://%s:%s", host, port)
146146
log.Printf("Connecting to MCP server at %s", url)
147147

148-
// Create a streamable client transport
148+
// Create a streamable client transport.
149149
transport := mcp.NewStreamableClientTransport(url, nil)
150150

151-
// Create an MCP client
151+
// Create an MCP client.
152152
client := mcp.NewClient(&mcp.Implementation{
153153
Name: "time-client",
154154
Version: "1.0.0",
155155
}, nil)
156156

157-
// Connect to the server
157+
// Connect to the server.
158158
session, err := client.Connect(ctx, transport)
159159
if err != nil {
160160
log.Fatalf("Failed to connect: %v", err)
@@ -163,7 +163,7 @@ func runClient(host, port string) {
163163

164164
log.Printf("Connected to server (session ID: %s)", session.ID())
165165

166-
// First, list available tools
166+
// First, list available tools.
167167
log.Println("Listing available tools...")
168168
toolsResult, err := session.ListTools(ctx, nil)
169169
if err != nil {
@@ -174,12 +174,12 @@ func runClient(host, port string) {
174174
log.Printf(" - %s: %s\n", tool.Name, tool.Description)
175175
}
176176

177-
// Call the cityTime tool for each city
177+
// Call the cityTime tool for each city.
178178
cities := []string{"nyc", "sf", "boston"}
179179

180180
log.Println("Getting time for each city...")
181181
for _, city := range cities {
182-
// Call the tool
182+
// Call the tool.
183183
result, err := session.CallTool(ctx, &mcp.CallToolParams{
184184
Name: "cityTime",
185185
Arguments: map[string]any{
@@ -191,7 +191,7 @@ func runClient(host, port string) {
191191
continue
192192
}
193193

194-
// Print the result
194+
// Print the result.
195195
for _, content := range result.Content {
196196
if textContent, ok := content.(*mcp.TextContent); ok {
197197
log.Printf(" %s", textContent.Text)

0 commit comments

Comments
 (0)