MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / runServer

Function runServer

examples/http/main.go:113–141  ·  view source on GitHub ↗
(url string)

Source from the content-addressed store, hash-verified

111}
112
113func runServer(url string) {
114 // Create an MCP server.
115 server := mcp.NewServer(&mcp.Implementation{
116 Name: "time-server",
117 Version: "1.0.0",
118 }, nil)
119
120 // Add MCP-level logging middleware.
121 server.AddReceivingMiddleware(createLoggingMiddleware())
122
123 // Add the cityTime tool.
124 mcp.AddTool(server, &mcp.Tool{
125 Name: "cityTime",
126 Description: "Get the current time in NYC, San Francisco, or Boston",
127 }, getTime)
128
129 // Create the streamable HTTP handler.
130 handler := mcp.NewStreamableHTTPHandler(func(req *http.Request) *mcp.Server {
131 return server
132 }, nil)
133
134 log.Printf("MCP server listening on %s", url)
135 log.Printf("Available tool: cityTime (cities: nyc, sf, boston)")
136
137 // Start the HTTP server.
138 if err := http.ListenAndServe(url, handler); err != nil {
139 log.Fatalf("Server failed: %v", err)
140 }
141}
142
143func runClient(url string) {
144 ctx := context.Background()

Callers 1

mainFunction · 0.70

Calls 5

NewServerFunction · 0.92
AddToolFunction · 0.92
NewStreamableHTTPHandlerFunction · 0.92
createLoggingMiddlewareFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…