Build an MCP Server in Go with the Official SDK

This is the Go companion to Build an MCP Server in TypeScript with the Official SDK. It builds the same kind of server — two tools and a resource — with the official Go SDK (github.com/modelcontextprotocol/go-sdk), served over the stdio transport so a local client launches it as a subprocess. The result is a single compiled binary with no runtime beyond itself. The project uses the cmd/ + internal/ layout, a Makefile, and Go’s built-in testing. ...

13 min

Build a Go Hello World Application

A minimal Go project that prints a greeting, accepts a name from the command line, includes a test suite, and uses a Makefile to drive common tasks. This tutorial covers project structure, flag parsing, table-driven tests, and build automation. Prerequisites Go 1.22 or later A Unix-like terminal (macOS, Linux, or WSL on Windows) make installed (pre-installed on macOS and most Linux distributions) No third-party packages required Step 1: Set up the project structure Create the file mkdir -p hello-world touch hello-world/.gitignore Add the code: hello-world/.gitignore bin/ *.test *.out .DS_Store *.log tmp/ Detailed breakdown bin/ excludes compiled binaries produced by the build step. *.test and *.out exclude Go test binaries and coverage output files. .DS_Store, *.log, and tmp/ cover common OS and temporary artifacts. Step 2: Initialize the Go module Create the file cd hello-world go mod init hello-world Detailed breakdown go mod init hello-world creates a go.mod file that declares the module path as hello-world. All import paths within the project use this prefix. Since the project uses only the standard library, no dependencies are added to go.mod. Step 3: Create the greeter package This package contains the core greeting logic, separated from the entry point so it can be tested independently. ...

6 min

Build a REST API in Go

A JSON REST API for managing a book collection using only the Go standard library. The API supports full CRUD operations, uses Go 1.22 method-based routing, and includes an in-memory store protected by a mutex for concurrent access. Prerequisites Go 1.22 or later A Unix-like terminal (macOS, Linux, or WSL on Windows) curl or a similar HTTP client for manual testing No third-party packages required Step 1: Set up the project structure Create the file mkdir -p rest-api touch rest-api/.gitignore Add the code: rest-api/.gitignore bin/ *.test *.out .DS_Store *.log tmp/ Detailed breakdown bin/ excludes compiled binaries produced by the build step. *.test and *.out exclude Go test binaries and coverage output files. .DS_Store, *.log, and tmp/ cover common OS and temporary artifacts. Step 2: Initialize the Go module Create the file cd rest-api go mod init bookapi Detailed breakdown go mod init bookapi creates a go.mod file that declares the module path as bookapi. All import paths within the project use this prefix. Since the project uses only the standard library, no dependencies are added to go.mod. Step 3: Define the book model and store This file defines the Book struct and an in-memory store with thread-safe CRUD operations. ...

14 min