# README
Gin Integration Example
This example demonstrates how to integrate the MCP server with a Gin web application. It shows how to:
- Create an MCP server with a Gin transport
- Register tools with the server
- Add the MCP endpoint to a Gin router
Running the Example
-
Start the server:
go run main.go
This will start a Gin server on port 8081 with an MCP endpoint at
/mcp
. -
You can test it using the HTTP client example:
cd ../http_example go run client/main.go
Understanding the Code
The key components are:
GinTransport
: A transport implementation that works with Gin's routerHandler()
: Returns a Gin handler function that can be used with any Gin router- Tool Registration: Shows how to register tools that can be called via the MCP endpoint
Integration with Existing Gin Applications
To add MCP support to your existing Gin application:
// Create the transport
transport := http.NewGinTransport()
// Create the MCP server
server := mcp_golang.NewServer(transport)
// Register your tools
server.RegisterTool("mytool", "Tool description", myToolHandler)
// Start the server
go server.Serve()
// Add the MCP endpoint to your Gin router
router.POST("/mcp", transport.Handler())