GoFrame MCP Example
Github Source: https://github.com/gogf/examples/tree/main/httpserver/mcp-sse
This example demonstrates how to implement a Model Context Protocol (MCP) server using GoFrame's ghttp server and the mark3labs/mcp-go SDK.
Prerequisites
- Go 1.20 or higher
- An MCP client (e.g., Claude Desktop, or an IDE extension)
Installation
-
Initialize the module (if not already done):
go mod tidy -
Run the server:
go run main.go
Usage
The server exposes two endpoints:
GET /sse: The Server-Sent Events endpoint for establishing the connection.POST /message: The endpoint for sending JSON-RPC messages.
Connecting with Claude Desktop
To use this MCP server with Claude Desktop, add the following configuration to your claude_desktop_config.json:
{
"mcpServers": {
"goframe-mcp": {
"command": "go",
"args": ["run", "path/to/your/project/httpserver/mcp/main.go"]
}
}
}
Note: Since this example runs an HTTP server, you might need to use an MCP client that supports SSE, or use a bridge. However, the configuration above assumes you are running it as a local process. If you want to connect via HTTP (SSE), your client must support remote MCP connections.
For direct SSE testing:
- Start the server.
- Connect to
http://localhost:8080/sse.
MCP client configuration
If your editor or tool supports defining MCP servers via a configuration file (for example, some IDE extensions or local test tools), you can create .vscode/mcp.json in the project root with the following example:
{
"servers": {
"add": {
"url": "http://localhost:8080/sse",
"type": "http"
}
},
"inputs": []
}
Notes:
- The key under
servers(e.g.add) is the identifier used by the client. urlshould point to the SSE endpoint for this example:http://localhost:8080/sse.typeindicates connection type; this example useshttp(SSE).inputsis optional and can be used to predefine input payloads depending on the client.
Save the file and compatible clients can read it to connect to this example MCP server.
Features
- Tools: Exposes an
addtool that takes two numbers (aandb) and returns their sum. - Example: From an MCP client you can send a calculation request, for example:
mcp add 1 and 1
The server will respond with:
Result: 1 + 1 = 2
Code Structure
main.go: Contains the server setup, tool registration, and route binding usingghttp.WrapH.