MCPcopy Create free account
hub / github.com/github/gh-aw / runHTTPServer

Function runHTTPServer

pkg/cli/mcp_server_http.go:65–96  ·  view source on GitHub ↗

runHTTPServer runs the MCP server with HTTP/SSE transport

(server *mcp.Server, port int)

Source from the content-addressed store, hash-verified

63
64// runHTTPServer runs the MCP server with HTTP/SSE transport
65func runHTTPServer(server *mcp.Server, port int) error {
66 mcpLog.Printf("Creating HTTP server on port %d", port)
67
68 // Create the streamable HTTP handler.
69 handler := mcp.NewStreamableHTTPHandler(func(req *http.Request) *mcp.Server {
70 return server
71 }, &mcp.StreamableHTTPOptions{
72 SessionTimeout: 2 * time.Hour, // Close idle sessions after 2 hours
73 Logger: logger.NewSlogLoggerWithHandler(mcpLog),
74 })
75
76 handlerWithLogging := loggingHandler(handler)
77
78 // Create HTTP server
79 addr := fmt.Sprintf(":%d", port)
80 httpServer := &http.Server{
81 Addr: addr,
82 Handler: handlerWithLogging,
83 ReadHeaderTimeout: MCPServerHTTPTimeout,
84 }
85
86 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Starting MCP server on http://localhost"+addr))
87 mcpLog.Printf("HTTP server listening on %s", addr)
88
89 // Run the HTTP server
90 if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
91 mcpLog.Printf("HTTP server failed: %v", err)
92 return fmt.Errorf("HTTP server failed: %w", err)
93 }
94
95 return nil
96}

Callers 1

runMCPServerFunction · 0.85

Calls 5

NewSlogLoggerWithHandlerFunction · 0.92
FormatInfoMessageFunction · 0.92
loggingHandlerFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected