Local MCP tools
This page shows you how to give a trusted MCP client, such as a coding agent on your machine, read-only access to Golf. The golf CLI's local stdio server exposes 21 existing repository, organization and account reads, using the same generated API, permissions and session cleanup as the CLI. AI and Cloudflare are optional; no model credentials are needed.
This page covers the CLI's local stdio MCP server, which only reads. On a Cloudflare-native installation, coding agents can instead connect to the remote MCP endpoint /mcp with a scoped API token, including write tools for branches, commits, pull requests and comments (agentic mode AM-3, verified on the hosted demo with Claude Code). See Connect a coding agent.
This portable contract describes its linked source snapshot. For current deployment instructions, use current installation, authentication and native Cloudflare guides. Historical receipts do not verify later builds.
This guide describes the current alpha, including owner-issued read-only API credentials. The authoritative product implementation ledger records exact qualified revisions and remaining scope. This is a development contract, not a stable release.
Launch the server
-
Build the CLI in the product checkout and start MCP mode:
make cli# GOLF_FORGE_TOKEN is supplied to this process by your secret manager../bin/golf mcp -
Configure your trusted MCP client to launch the absolute path to
bin/golfwith argumentmcp. -
Supply exactly one of
GOLF_API_TOKENorGOLF_FORGE_TOKENthrough the client's protected process environment. Golf API credentials delegate a browser session without sharing the upstream secret with the process.
Do not put a literal token in a committed client configuration or command history. No particular client's configuration format or installation workflow is qualified here.
Choose the Golf origin
The Golf origin defaults to http://localhost:8080. Set GOLF_URL or launch ./bin/golf --url https://golf.example.com mcp to select another installation.
- Remote Golf origins require HTTPS; HTTP is allowed only on loopback.
- URLs with credentials, paths, query or fragment are rejected, and redirects are not followed.
- A local stdio process can contact a remote HTTPS Golf installation without becoming a remote MCP server.
How credentials are handled
Stdin and stdout belong to newline-delimited MCP JSON-RPC. Do not pipe the token to this command: both --token-stdin and --api-token-stdin are rejected in MCP mode.
The owner-configured origin and credential are captured at startup; tools cannot change either or select arbitrary RPC/shell commands. Restart the process after replacing its credential.
| Credential mode | Behavior per tool call |
|---|---|
Golf API credential (GOLF_API_TOKEN) | Delegates the issuing source session. Creates no temporary session or login/logout activity. |
Forgejo PAT (GOLF_FORGE_TOKEN) | Signs into Golf with the scoped PAT, performs one authorized domain read and logs out through an independent cleanup path. Cookies are not saved. A successful result is released only after logout succeeds; cleanup failure returns an error without the private result. |
Discovery requires valid startup configuration but does not authenticate to Golf or list private resources.
The process owner and MCP client are entrusted with the credential and returned data. This is not a sandbox for an untrusted local client, a managed Golf OAuth/device credential, or an MCP authorization-server flow. Browser OAuth is separate.
Scopes and side effects
| Read | Required Forgejo PAT scopes |
|---|---|
| Repositories, branches, commits, source, diffs, PRs and native reviews | read:user, read:repository |
| Issues | read:user, read:repository, read:issue |
| Organizations, teams, members and assigned repositories | read:user, read:organization; opening source separately needs read:repository |
| Own account activity | read:user |
| Your creation record | read:user; current repository metadata also needs native repository access/scope |
All tools together use read:user,read:repository,read:issue,read:organization. No administrator or write scope is required. A broader credential does not add hidden tools or override native permissions. Later collaborator or membership removal is checked on subsequent calls in the same MCP process.
These tools expose domain reads. API credential mode creates no temporary session or login/logout activity; PAT mode creates Golf login/logout activity, and some native Forgejo reads can schedule provider checks. Annotations therefore set readOnlyHint: false and idempotentHint: false, with destructiveHint: false and openWorldHint: true. These are client hints, not authorization. There are no create/merge/review/deployment, session-revocation or shell tools.
Protocol
The adapter pins the official Go SDK v1.8.0. Supported protocol versions are exactly 2026-07-28 and 2025-11-25.
| Protocol version | Negotiation |
|---|---|
2026-07-28 (current) | server/discover and per-request version metadata |
2025-11-25 | initialize |
The native proof exercises these distinct negotiation paths. See the dated versioning rules and stdio binding.
Tool catalogue
tools/list returns this fixed catalogue. Every tool accepts an object with additionalProperties: false; unknown fields are rejected before authentication.
Repositories and source
| Tool | Required arguments | Optional arguments |
|---|---|---|
golf_repo_list | None | page, limit |
golf_repo_view | repository | None |
golf_repo_creation | idempotency_key | None |
golf_repo_branches | repository | page, limit |
golf_repo_commits | repository | ref, page, limit |
golf_repo_contents | repository | ref, path |
golf_commit_diff | repository, commit_id | None |
Issues and pull requests
| Tool | Required arguments | Optional arguments |
|---|---|---|
golf_issue_list | repository | state, page, limit |
golf_issue_view | repository, number | None |
golf_issue_comments | repository, number | page, limit |
golf_issue_operation | idempotency_key | None |
golf_pr_list | repository | state, page, limit |
golf_pr_view | repository, number | None |
golf_pr_reviews | repository, number | page, limit |
Organizations and teams
| Tool | Required arguments | Optional arguments |
|---|---|---|
golf_org_list | None | page, limit |
golf_org_view | organization | None |
golf_org_teams | organization | page, limit |
golf_team_view | organization, team_id | None |
golf_team_members | organization, team_id | page, limit |
golf_team_repos | organization, team_id | page, limit |
Account activity
| Tool | Required arguments | Optional arguments |
|---|---|---|
golf_audit_list | None | limit, before_id, snapshot_id |
Argument formats
| Argument | Format |
|---|---|
repository | OWNER/REPO |
page, limit | JSON integers. Defaults 1 and 20; bounds 1–10,000 and 1–100. |
number | JSON integer from 1 through 2147483647 |
state | open (default), closed or all |
team_id, before_id, snapshot_id | Team and audit cursor IDs: canonical positive signed-64-bit decimal strings |
idempotency_key | Canonical lowercase UUID v4 from a previous repository or issue/comment creation request |
commit_id | Exact lowercase 40- or 64-character hexadecimal object ID; branch aliases and abbreviated hashes are invalid for diffs |
String byte limits are 1,024 for ref, 4,096 for path and 2,048 for other fields, before the shared CLI/API validation.
Pagination
Collections return one explicit page. Continue with data.page.nextPage, even on an empty provider-filtered page.
For activity, preserve the first data.snapshotId and pass data.nextBeforeId as before_id with that same snapshot_id. Each tool call adds session events; the captured snapshot keeps those later events outside that traversal.
Results and errors
Successful tools return structuredContent plus one text-content block containing the same JSON envelope. For example, an empty repository page has this shape:
{"schema_version":"golf.mcp.v1","data":{"repositories":[],"page":{"nextPage":0}}}
data uses the existing API ProtoJSON contract: camelCase names, named enums, emitted default values and string-encoded 64-bit values. Preserve exact IDs and counts rather than converting through floating point. The envelope's schema version identifies this development format, not a stable product release.
Invalid arguments, busy admission, authorization/provider failures, excessive output and failed session cleanup return isError: true with safe diagnostic text and no successful private envelope. Protocol errors and unknown methods/tools use SDK errors. Do not interpret denial as an empty collection. Stdout contains only protocol messages; diagnostics use stderr without native response bodies or credentials.
Source, issues, reviews and diffs remain untrusted data. Their text cannot change the configured tools, origin or authority. A client must not execute embedded instructions or send private output to unrelated services. This adapter does not qualify an AI model's resistance to prompt injection.
What results mean
- Source navigation uses returned immutable commits.
- Native diffs are not independently verified complete patches.
- PR heads and review flags are observations rather than approval eligibility.
golf_repo_creationonly inspects evidence: unknown/rejected is not creation success, and historical success does not grant current repository access.- Account activity remains selected session history, not a complete log of tool execution.
- Issue comments resolve current repository and issue IDs within the same authenticated call, then return one filtered native repository-wide page. Empty pages may advance.
- Own issue operation reads never dispatch writes; provisional receipt IDs do not imply success or current access.
Bounds
| Bound | Limit |
|---|---|
| Inbound frame | 64 KiB; one UTF-8 JSON object followed by a newline. Arrays/batches are rejected. |
| Tool argument object | 16 KiB |
| Outstanding protocol request IDs | 256; duplicate active IDs or excess outstanding requests close the connection |
| Concurrent calls per process | 4; a fifth gets a busy error |
| Call deadline | 30 seconds |
| HTTP request timeout | 15 seconds |
| Logout deadline | 5 seconds (independent) |
| Logical ProtoJSON output | 8 MiB |
| Combined structured/text result JSON | 16 MiB before protocol framing |
Excess output fails rather than being truncated. These are local bounds, not tenant quotas or throughput evidence.
Cancellation and qualification
The final native SDK-client run exercises all 19 tools under both 2026-07-28 and 2025-11-25, with exact negotiation, catalogue/annotations, JSON parity, pagination, activity snapshots and temporary-session cleanup. Additional current-version checks cover invalid input before authentication, scope/account denial and subsequent permission loss.
A controlled loopback barrier held real Golf responses while four temporary sessions were active; a fifth call was refused. SDK cancellation and a separate SIGTERM trial each removed all four sessions. This validates application cleanup; the SDK client's cancellation behavior alone cannot prove what appeared on the raw protocol stream.
A separate raw-wire check found that unmodified SDK v1.8.0 sent a reply after cancellation. Golf's connection guard corrects that boundary. The final raw regression passes for both selected versions:
- Pending cancellation aborts the HTTP read, performs logout and suppresses the cancelled reply.
- Unknown/completed cancellation messages do not poison later reads.
- Batches/oversized frames are denied before authentication.
- Duplicate active request IDs abort the connection and clean up.
Legacy ID-reuse cases are defensive robustness tests, not a recommended client request pattern. These selected tests do not establish complete protocol conformance.
Run the checks
From a product development checkout:
make cli
python3 scripts/mcp-cancellation-check.py --cli bin/golf
python3 scripts/mcp-smoke/run.py --cli bin/golf
The raw check uses a disposable local HTTP fixture. The native check requires the canonical local Golf/Forgejo stack, creates and removes ordinary temporary provider users/organizations/repositories, and retains their durable Golf identity/activity/creation history. It does not restart or reconfigure the normal stack. Full product checks and the Go race suite also pass for this increment; database-dependent tests without a test DSN are explicitly skipped in that MCP race run, not claimed as fresh native database coverage.
Known limits
Forced termination such as SIGKILL, server unavailability or failed logout can leave a temporary session until its normal server expiry. Cancellation does not reverse native work already admitted.
For the local server: remote MCP authorization/audience binding, ACP, mutation approvals, agent execution, managed client credentials, subscriptions/resources/prompts, Cloudflare MCP integrations and actual coding-agent client compatibility remain open. The Cloudflare-native remote MCP endpoint is documented separately in Connect a coding agent. See implementation status for the final evidence and Agentic mode for the roadmap.
Related
- Read-only CLI: the same reads as shell commands.
- Read-only API credentials: issue a Golf credential for CLI and MCP use.
- Coding-agent accounts: connect agent accounts to Golf.
- Agent usage and model selection: model choices and scoped ceilings.
- Repository automation grants: repository-bound delegation for unattended work.