AI agents and MCP
Give Claude Code, Codex or Cursor an agent token and connect the MCP server. Scopes, tools, run_tests availability and the guide in every clone.
Short answer: Each AI agent gets its own token and belongs to a person. Its clone and its MCP calls carry only that person's access, or less. The agent can inspect its fence, ask for access, follow and review pull requests and, where Fenced CI runs, run the real tests.
Steps
- Create the agent token. On the member's Gitfence home, choose Connect an AI agent, pick the AI tool (Claude Code, Codex or Cursor), optionally set Limit this agent, then choose Connect Claude Code, Connect Codex or Connect Cursor. The token is shown once.
- Limit it if needed. Limit this agent can choose a Repository, the paths It may edit, whether Everything else is Read-only or Hidden, and when It stops working: When its pull request is merged or closed or After the expiry date. A limit only narrows the person's access.
- Connect MCP. Export the token as
GITFENCE_TOKENand usehttps://gitfence.dev/mcp:
claude mcp add --transport http gitfence https://gitfence.dev/mcp \
--header "Authorization: Bearer $GITFENCE_TOKEN"
Codex uses url = "https://gitfence.dev/mcp" and bearer_token_env_var = "GITFENCE_TOKEN" in ~/.codex/config.toml. Cursor uses the same URL and an Authorization header in ~/.cursor/mcp.json or .cursor/mcp.json.
- Or skip the hand wiring. The one-paste setup on the member home gives one prompt or command that clones, configures git and connects MCP. Its link works once and expires after 15 minutes; redemption creates the token for that setup, such as a 30-day agent token.
Tools
list_repos, fence_status, check_paths, request_access, my_access_requests, run_tests, test_status, my_pull_requests, pull_request_status, pull_request_diff, pull_request_file_lines, comment_on_line, submit_review, reply_to_review, resolve_thread, react, apply_suggestion, set_labels, set_assignees, list_issues, get_issue, comment_on_issue, create_issue and whoami.
update_pull_requestedits the title or description, or changes the draft state.close_pull_requestcloses or reopens your own pull request.delete_branchdeletes your own branch.translate_committranslates a commit id between your clone and GitHub.
See Working on pull requests for branch names, push options, review updates and commit ids.
The guide Gitfence writes into AGENTS.md and CLAUDE.md in every clone explains the fence: do not recreate or stub hidden code, ask for access instead, and push to a branch. The MCP server is Streamable HTTP, POST only, with no sessions or SSE.
Reviewing pull requests
Agents can read a pull request diff from their own filtered copy and review it through REST or MCP. Hidden files stay hidden, and types-only files show their generated declarations or stubs. The review rules are the same as in the contractor guide.
For REST, send the token as Authorization: Bearer <token>:
GET /api/collab/repos/<owner>/<repo>/pulls
GET /api/collab/repos/<owner>/<repo>/pulls/<n>/files
GET /api/collab/repos/<owner>/<repo>/pulls/<n>/files?format=patch
GET /api/collab/repos/<owner>/<repo>/pulls/<n>/files?path=<file>
GET /api/collab/repos/<owner>/<repo>/pulls/<n>/lines?path=<file>&side=RIGHT|LEFT&from=1&to=50
POST /api/collab/repos/<owner>/<repo>/pulls/<n>/comments
POST /api/collab/repos/<owner>/<repo>/pulls/<n>/reviews
The first endpoint returns your own pullRequests and a reviewing list. files returns JSON files with hunks and an outside count. format=patch returns plain unified diff text, and path=<file> loads one file in full. lines returns lines of the file from your copy.
Post line comments with {"path","line","side","body"}. Post reviews with {"event":"comment"|"approve"|"request_changes","body"}.
For MCP, my_pull_requests also lists reviewing. The review tools are:
pull_request_status.pull_request_diffwithrepo,number, optionalpath, and optionalformatset to"patch"or"json".pull_request_file_lineswithrepo,number,path,side,fromandto.comment_on_linewithrepo,number,path,line,sideandbody.submit_reviewwithrepo,number,eventandbody.reply_to_review.resolve_threadwithrepo,number,comment_idand optionalresolved, which defaults totrue.reactwithrepo,number,comment_id,contentand optionalkindset to"issue"or"review".apply_suggestionwithrepo,numberandcomment_id.set_labelswithrepo,numberandlabels.set_assigneeswithrepo,numberandassignees.
Tests in the fence
run_tests runs the repository's test command on the full code in a sandbox with no network, and returns the verdict (or redacted output, if the repository allows it). It works today on self-hosted Gitfence. On our hosted service it is not self-serve yet: we set it up with you, so contact us.
Where it is not set up, fence_status says tests in the fence are not available on this server, and run_tests answers unavailable. The guide then tells the agent to push its branch and say in the pull request that the full tests were not run. Saving a test command under Tests does not switch it on.
Gotchas
- A folder marked No AI agents is hidden from every agent, whatever its scope says.
- Git and MCP tokens keep working when Require SSO is on, but the token must not be expired or revoked.
- Revoke a token under Your passwords and agents on the member home. A revoked token stops working at once.
- MCP does not see prompts. It records the calls it receives.
Next: code review and access levels.
Related guides
- Access levelsThe four Gitfence access levels, how rules combine, and what restricted people and AI agents can read, edit or never receive.
- Code reviewThe Gitfence review check, risk areas, approvals and what restricted people see from reviews, checks and comments on GitHub.
- Reviewing a pull requestReview your team's pull requests in Gitfence: a diff from your own copy, line comments, reviews, and the REST API and MCP tools for AI agents.
- What contractors see from CIShow contractors why CI failed without exposing hidden code: results, error locations, filtered logs, MCP and REST access, re-runs and audit records.