MCP Go#
MCP Go uses the native Go SDK to implement the Model Context Protocol (MCP). The framework provides type-safe tool definitions and is best suited for high-throughput and high-performance services, system-level integrations, and performance-critical applications.
Prerequisites#
- Install go version 1.23 or later.
- Install the MCP inspector tool to access and test your MCP server.
npx @modelcontextprotocol/inspector
Create the MCP project#
-
Create a scaffold for your MCP Go server project.
The following command creates an MCP server in the
my-mcp-serverdirectory and a sample echo tool that you can later use to test your server. Follow the interactive CLI prompts to optionaly add a description and author for your project.kmcp init go my-mcp-server --go-module-name my-mcp-server -
Review the project structure that was created for you.
find my-mcp-serverExample project structure:
my-mcp-server/βββ main.go # Server entry pointβββ go.mod # Go module definitionβββ go.sum # Dependency checksumsβββ tools/ # Tool implementationsβ βββ all_tools.go # Tool registrationβ βββ echo.go # Example toolβ βββ tool.go # Tool templateβββ Dockerfile # Container definitionβββ .gitignore # Git ignore rulesβββ kmcp.yaml # Project configurationβββ README.md # Project documentation
Add tools#
-
Create a boilerplate for an MCP tool that is named
mytool. The following command creates themytool.gotool in thetoolsdirectory of your MCP project.The boilerplate includes code for an echo tool that is similar to the
my-mcp-server/tools/echo.gotool that is automatically created when you initialize the project. You can use the boilerplate as a base to create your own tools.kmcp add-tool mytool --project-dir my-mcp-server -
Review the code for the
mytooltool.cat my-mcp-server/tools/mytool.go -
Make changes to the
mytool.gotool to implement your own tool logic.
Run locally#
Use the kmcp run command to run your MCP server on your local machine so that you can test your MCP server and tools.
-
Run your MCP server on your local machine. The command builds the Docker image for your MCP server and automatically opens the MCP inspector tool so that you can connect to your MCP server and test it.
Tip: The following command automatically opens the MCP inspector tool so that you can test your MCP server. If you do not want to open the MCP inspector tool, add the
--no-inspectoroption to your command.kmcp run --project-dir my-mcp-server -
In the MCP inspector tool, click Connect to connect to your MCP server. Note that it might take a few seconds for the MCP inspector tool to successfully connect to your MCP server. If the connection fails, make sure the following fields are set in the MCP inspector tool.
- Select STDIO from the Transport Type drop down.
- In the Command section, enter
go. - In the Arguments section, enter
run main.go. - In the Configuration section, enter the Proxy Session Token that was returned in the
kmcp runcommand.

Locally run your MCP server with the MCP inspector tool -
Try out the
mytoolMCP tool.- Go to the Tools tab and click List Tools.
- Select the
mytooltool. - Enter any string in the message field, such as
Hello worldand click Run Tool. - Verify that you see your message echoed in the Tool result card.

Successful run of the mytool tool
Next#
- Explore other MCP frameworks, such as FastMCP Python.
- Deploy your MCP server to a Kubernetes cluster.
- Learn how to manage secrets for your MCP server.