GitHub REST import
A slice of the GitHub REST API served as an MCP tool with one call to
mcp.FromREST. The GitHub struct describes the endpoint with a rest:
tag (GET /repos/{owner}/{repo}/issues?per_page=...) and names its
arguments with args:"owner,repo,per_page"; the nested Issues section
becomes the tool name issues.list.
The token comes from GITHUB_TOKEN and rides a static Authorization
header (mcp.WithHeader), which is sent only to the backend's own host -
never taken from tool arguments. Every declared operation is exposed;
examples/curated shows how to narrow and fix arguments.
See main.go.
Run it
From the repository root (this one calls the real api.github.com):
GITHUB_TOKEN=ghp_... go run ./examples/github # stdio
GITHUB_TOKEN=ghp_... go run ./examples/github -addr 127.0.0.1:8080 # Streamable HTTP on /mcp
Test it - the test never dials GitHub; it serves the same structure
against an offline stand-in backend and checks the credential header:
go test ./examples/github
Expected output
Without a token it refuses to start (exit status 1):
$ go run ./examples/github
mcp-github: set GITHUB_TOKEN; the GitHub API requires a credential
(prefixed with the log timestamp). With a token and -addr, listing the
tools needs no call to GitHub; the generated input and output schemas
come from the Go signature, and the annotations from its
hint:"readonly" tag - with "openWorldHint": true, because the tool
calls a backend mcp.FromREST imported:
$ curl -s -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2025-11-25' http://127.0.0.1:8080/mcp \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
{"jsonrpc":"2.0","id":1,"result":{"ttlMs":0,"cacheScope":"private","tools":[{"annotations":{"destructiveHint":false,"idempotentHint":false,"openWorldHint":true,"readOnlyHint":true},"description":"lists a repository's issues, newest first.","inputSchema":{"additionalProperties":false,"properties":{"owner":{"type":"string"},"per_page":{"type":"integer"},"repo":{"type":"string"}},"required":["owner","repo","per_page"],"type":"object"},"name":"issues.list","outputSchema":{"additionalProperties":false,"properties":{"result":{"items":{"additionalProperties":false,"properties":{"number":{"type":"integer"},"state":{"type":"string"},"title":{"type":"string"}},"required":["number","title","state"],"type":"object"},"type":"array"}},"required":["result"],"type":"object"}}]}}
A tools/call of issues.list returns the repository's issues as
{"result":[{"number":...,"title":...,"state":...}]}; that call needs a
real token and network access, so no captured output is shown here.