You can also create an HTTP-based MCP server. Note that HTTP transport is stateless and doesn’t support bidirectional features like notifications - use stdio transport if you need those features.
Copy
package mainimport ( "context" "log" "github.com/metoro-io/mcp-golang" "github.com/metoro-io/mcp-golang/transport/http")func main() { // Create an HTTP transport transport := http.NewHTTPTransport("/mcp") transport.WithAddr(":8080") // Create server with the HTTP transport server := mcp.NewServer(transport) // Register your tools server.RegisterTool("hello", &HelloTool{}) // Start the server if err := server.Serve(); err != nil { log.Fatal(err) }}
Or using the Gin framework:
Copy
package mainimport ( "github.com/gin-gonic/gin" "github.com/metoro-io/mcp-golang" "github.com/metoro-io/mcp-golang/transport/http")func main() { // Create a Gin transport transport := http.NewGinTransport() // Create server with the Gin transport server := mcp.NewServer(transport) // Register your tools server.RegisterTool("hello", &HelloTool{}) // Set up Gin router router := gin.Default() router.POST("/mcp", transport.Handler()) // Start the server router.Run(":8080")}