(Just add two lines of code to integrate the library!)
Gin-MCP offers a zero-configuration approach. Just plug it into your Gin application, and it automatically discovers your routes and infers basic schemas, exposing them as MCP tools instantly.
Gin-MCP: A Seamless Integration for MCP Features
Gin-MCP is an opinionated, zero-configuration library designed to effortlessly enable Model Context Protocol (MCP) features for any existing Gin API with just a single line of code. This powerful tool automatically exposes Gin endpoints and makes them accessible to compatible MCP clients like Cursor. With a focus on minimal setup and maximum productivity, Gin-MCP allows developers to concentrate on building features instead of being bogged down with configuration tasks.
gin.Engine.RegisterSchema for precision control.Hide your MCP tools behind a simple setup:
package main
import (
"net/http"
server "github.com/ckanthony/gin-mcp/"
"github.com/gin-gonic/gin"
)
func main() {
// Create a Gin engine
r := gin.Default()
// Define API routes
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "pong"})
})
// Set up MCP server
mcp := server.New(r, &server.Config{
Name: "My Simple API",
Description: "An example API automatically exposed via MCP.",
BaseURL: "http://localhost:8080",
})
// Mount the MCP server endpoint
mcp.Mount("/mcp") // Clients connect here
// Start the Gin server
r.Run(":8080")
}
Gin-MCP automatically generates tools for the defined routes, now available at http://localhost:8080/mcp.
For instances where greater control is required, Gin-MCP allows for customization beyond automatic configuration.
With RegisterSchema, explicitly define schemas for query parameters or request bodies of specific routes, addressing complex structs or unique requirements:
mcp.RegisterSchema("GET", "/products", ListProductsParams{}, nil)
mcp.RegisterSchema("POST", "/products", nil, CreateProductRequest{})
Control which Gin endpoints become accessible as MCP tools:
mcp := server.New(r, &server.Config{
// ...other config...
IncludeOperations: []string{"getUser", "listUsers"},
})
To connect a client like Cursor to your running Gin application:
http://localhost:8080/mcp).For a deeper dive into Gin-MCP, various examples showcasing its features can be found in the examples directory.
Contributions are welcome, and issues or pull requests can be submitted for enhancements or bug fixes.
No comments yet.
Sign in to be the first to comment.