
An agent filing issues through an MCP server
The agent filing issues through an MCP server, with the server’s tool definitions pinned.
On the agent compass Stage 3 of 4 · Run the toolsThe tracker is the one part of the triage job that lives in another program, with its own data.
In this example the agent reaches it only through MCP, the Model Context Protocol, a standard way for an agent to use tools that another program serves: the program starts the tracker’s MCP server as a child process, lists its tools, and offers them to the model under prefixed names such as tracker__issue_search.
The model’s replies are recorded, but the server, the protocol, and every tool call run for real.
What it shows
- A hand-written MCP client and server in Go, newline-delimited JSON-RPC (a request-and-reply message format built on JSON) over standard input and output. MCP in Go explains both sides.
- Server tools adapted into agent tools, with names prefixed by the server’s name, descriptions labeled as the server’s, and the server’s hints about its tools, such as which ones only read, ignored unless the server is trusted.
- A server whose tool definitions can be pinned by hash, so a change stops the run before it starts.
Run it
From the code directory of a clone of go-agents-book-code, with no OPENROUTER_API_KEY set:
$ go run ./ch10
It replays a 13-turn run of the same task as the ch07 example, a batch of four crash reports, two of which already have issues filed. Notice the tool names in the second turn:
turn 2
model says: Four reports fall into three groups. I'll read each group's
details first.
model asks: crash_read {"id": "cr_fd4982"}
model asks: crash_read {"id": "cr_1e2ea0"}
model asks: crash_read {"id": "cr_f9ee9e"}
model asks: tracker__issue_search {}
tool result: cr_fd4982: panic in v1.4.0 (commit 9c41e... (16 lines)
tool result: cr_1e2ea0: panic in v1.4.0 (commit 9c41e... (16 lines)
tool result: cr_f9ee9e: panic in v1.4.0 (commit 9c41e... (17 lines)
tool result: #101 Crash in auth.parseBearer: runtime ... (5 lines)
tracker__issue_search is the server’s issue_search, reached over the protocol.
On this run the agent marked both already-filed crashes as duplicates of their existing issues, filed one new issue through the server, and scored 16 out of 16 on the crash catalog’s checks, for $0.0055:
stopped: the model answered
166511 tokens in (153368 from the cache), 4745 out, $0.0055
with the sub-agent's calls: $0.0055
diagnosis:
fp_4828a6 cr_1e2ea0,cr_ee551c: fixed, root cause store/store.go (*Store).Get, issue #103
fp_6b14b3 cr_f9ee9e: duplicate, root cause auth/auth.go parseBearer, duplicate of #101
fp_2bcd17 cr_fd4982: duplicate, root cause notify/notify.go (*Dispatcher).Stop, duplicate of #102
filed #103: store.Get returns (nil, nil) for a deleted reminder, crashing api.owned
graded against the catalog: 16 of 16 checks passed
The second cost line adds the spending of any sub-agent (a separate agent loop that one of the agent’s tools starts); it matches the first because this run started none.
The agent caught the duplicates this time because the prompt had changed since that earlier run; the protocol didn’t change what the agent could do.
In three runs each way on the default model, anthropic/claude-haiku-5.5, the agent worked with the server’s tools as readily as with its own hand-written ones, and every run passed every check.
Serve the tracker to anything
The server is an ordinary command, and any MCP client can start it: the triage agent, or an assistant app you already use.
func main() {
data := flag.String("data", "issues.json",
"file the issues are kept in")
flag.Parse()
log.SetOutput(os.Stderr) // standard output carries only messages
err := trackermcp.Serve(context.Background(), *data, time.Now,
os.Stdin, os.Stdout, os.Stderr)
if err != nil {
log.Fatal(err)
}
}
Its log goes to standard error, since standard output carries only protocol messages: a single leftover fmt.Println would reach the client as a line it can’t parse as a message.
To connect it to an assistant app, add a server entry to that app’s MCP configuration naming the command to run, go run ./ch10/cmd/tracker-mcp -data /path/to/issues.json, from the code directory; each app documents its own format.
Pin the server’s tools
A server’s tool descriptions go straight into the model’s context. One sentence in a description decided 79 of 80 first moves in one recorded measurement, so the client can pin each tool’s definition by hash after a person reads it:
$ go run ./ch10 -print-digests > pins.json
$ go run ./ch10 -tracker-pins pins.json
The first prints the four tools’ digests; the second runs the replay with them checked.
Next, edit a single word in the description of issue_search in ch10/triage/issuetools.go, which defines the tools the server serves, then repeat the second command.
The run stops before it starts, with an error naming the tool, its new digest, and the pinned one.
To undo the edit, run git restore ch10/triage/issuetools.go from the code directory.
Run the tests
$ go test ./ch10/mcp/ ./ch10/mcptools/
They cover the protocol (discovery, pagination, cancellation at a timeout, falling back to the older initialize handshake for servers that need it), launching and shutting down a server process in the sequence the protocol requires, keeping the agent’s API key out of the server’s environment, and the trust rules: hidden characters removed, descriptions labeled, and pins that fail on any change to a description or a schema.
Key files
| File | What it holds |
|---|---|
ch10/mcp/jsonrpc.go |
JSON-RPC messages, errors, and line framing |
ch10/mcp/client.go |
The client: one reader, calls matched by ID, timeouts, starting and stopping a server |
ch10/mcp/server.go |
The server: one goroutine per request, cancellation, pagination |
ch10/mcptools/adapter.go |
Server tools as agent tools |
ch10/mcptools/trust.go |
Labels, hidden characters, schema limits, digests, and pins |
ch10/trackermcp/trackermcp.go |
The tracker’s four tools, served |
ch10/sdk |
The same server on the official MCP Go SDK, in a module of its own |
var data *string
ch10/cmd/tracker-mcp/main.go:19
var data *string. In ch10/cmd/tracker-mcp/main.go, line 19.
package flag ("flag")
Package flag implements command-line flag parsing.
Package flag implements command-line flag parsing. package flag ("flag"). Documented at pkg.go.dev, flag.
func String(name string, value string, usage string) *string
String defines a string flag with specified name, default value, and usage string.
String defines a string flag with specified name, default value, and usage string. func String(name string, value string, usage string) *string. Documented at pkg.go.dev, flag.String.
func Parse()
Parse parses the command-line flags from os.Args[1:].
Parse parses the command-line flags from os.Args[1:]. func Parse(). Documented at pkg.go.dev, flag.Parse.
package log ("log")
Package log implements a simple logging package.
Package log implements a simple logging package. package log ("log"). Documented at pkg.go.dev, log.
func SetOutput(w io.Writer)
SetOutput sets the output destination for the standard logger.
SetOutput sets the output destination for the standard logger. func SetOutput(w io.Writer). Documented at pkg.go.dev, log.SetOutput.
package os ("os")
Package os provides a platform-independent interface to operating system functionality.
Package os provides a platform-independent interface to operating system functionality. package os ("os"). Documented at pkg.go.dev, os.
var Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
var Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr"). Documented at pkg.go.dev, os.Stderr.
var err error
ch10/cmd/tracker-mcp/main.go:23
var err error. In ch10/cmd/tracker-mcp/main.go, line 23.
package trackermcp ("github.com/blackwell-systems/go-agents-book/code/ch10/trackermcp")
Package trackermcp is the book's issue tracker as an MCP server: the triage agent's four issue tools, served over the protocol by hand (chapter 10).
Package trackermcp is the book's issue tracker as an MCP server: the triage agent's four issue tools, served over the protocol by hand (chapter 10). package trackermcp ("github.com/blackwell-systems/go-agents-book/code/ch10/trackermcp"). In ch10/trackermcp.
func Serve(ctx context.Context, file string, now func() time.Time,
r io.Reader, w, logw io.Writer) error
Serve serves the issues kept in file over r and w until r ends, with its log lines on logw.
ch10/trackermcp/trackermcp.go:24
Serve serves the issues kept in file over r and w until r ends, with its log lines on logw. func Serve(ctx context.Context, file string, now func() time.Time, r io.Reader, w, logw io.Writer) error. In ch10/trackermcp/trackermcp.go, line 24.
package context ("context")
Package context defines the Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes. package context ("context"). Documented at pkg.go.dev, context.
func Background() Context
Background returns a non-nil, empty [Context].
Background returns a non-nil, empty [Context]. func Background() Context. Documented at pkg.go.dev, context.Background.
package time ("time")
Package time provides functionality for measuring and displaying time.
Package time provides functionality for measuring and displaying time. package time ("time"). Documented at pkg.go.dev, time.
func Now() Time
Now returns the current local time.
Now returns the current local time. func Now() Time. Documented at pkg.go.dev, time.Now.
var Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
var Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin"). Documented at pkg.go.dev, os.Stdin.
var Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
var Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout"). Documented at pkg.go.dev, os.Stdout.
var nil Type
nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type.
nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type. var nil Type. Documented at pkg.go.dev, builtin.nil.
func Fatal(v ...any)
Fatal is equivalent to [Print] followed by a call to os.Exit(1).
Fatal is equivalent to [Print] followed by a call to os.Exit(1). func Fatal(v ...any). Documented at pkg.go.dev, log.Fatal.

