# codex连接mcp服务器进行使用

# codex连接远程github mcp server

  1. 登录github

  2. Settings → Developer Settings→ Personal Access Tokens->Fine-grained tokens(或者使用这个链接github个人令牌)

    Repository access选All repositories

    Permissions中的Repositories 进行添加permissions:

    • Contents:Read and write
    • Issues : Read and write
    • Pull request:Read and write

    Expires 我选的是90天

    然后generate token,记住得立马复制,否则离开界面就要重新生成

  3. 更新环境变量

    echo 'export GITHUB_TOKEN="你复制的token"' >> ~/.zshrc
    source ~/.zshrc

    验证是否成功保存

    echo $GITHUB_TOKEN

    如果能打印出来,说明成功。

  4. 增加mcp配置

    experimental_use_rmcp_client = true
    
    [mcp_servers.github]
    url = "https://api.githubcopilot.com/mcp/"
    bearer_token_env_var = "GITHUB_TOKEN"
    startup_timeout_sec = 60 

    其中,experimental_use_rmcp_client = true需放在文件最顶部。

  5. 测试github mcp连通性

    首先,测试本地网络,如果太慢, 可能是代理节点的问题,需修改

     time curl -I https://api.githubcopilot.com/mcp

    其次,测试codex,

    codex "list my github repo"

    如果正常则会将你的仓库列出来;

#

# Codex Development Governance

This document defines how Codex is allowed to modify this repository.
All rules below are mandatory unless explicitly overridden.

---

## 1. Workflow Control

- Always work on branch: `codex`
- Never commit or push directly to `main`
- If the current branch is not `codex`, stop and request branch switch
- Do not create additional branches unless explicitly instructed

---

## 2. Version Control Policy

Every Codex-generated commit MUST:

- Start with prefix: `[codex]`
- Use a concise summary line (<= 72 characters preferred)
- Include a blank line after the title
- Include a section named exactly: `Design:`
- Include a section named exactly: `Testing:`

Example structure:

[codex] short summary of change

Design:
- ...

Testing:
- ...

---

## 3. Change Scope Control

- Only modify files directly related to the requested task
- Do not refactor unrelated modules
- Do not rename, reformat, or restructure unrelated code
- Keep the diff minimal and task-scoped
- Avoid large multi-purpose commits

---

## 4. Design Documentation Requirements

Each commit must contain a structured Design section:

Design:
- Goal: what problem this change solves
- Approach: high-level strategy and key data structures/algorithms
- Alternatives considered: 1–2 alternatives and why rejected
- Complexity/Performance: big-O or performance impact if relevant
- Concurrency/Safety: thread-safety, locking, race conditions, error handling
- Limitations: known constraints or trade-offs
- Scope: what is intentionally NOT changed

Design explanations must focus on reasoning, not just describing code changes.

---

## 5. Testing Requirements

Each commit must contain a structured Testing section:

Testing:
- Build status: success / not run + reason
- Unit tests: executed / not applicable
- Manual verification: what behavior was verified
- Edge cases checked: if any
- Known risks: if any

Testing must not be empty.

---

## 6. Large Change Protocol

If a change affects any of the following:

- Concurrency model
- Network protocol
- Database schema
- Core service logic
- Public API behavior

Codex must first provide a standalone design proposal and wait for approval
before modifying any code.

---

## 7. Safety Constraints

- Avoid introducing blocking calls in async/event-driven code
- Do not introduce global mutable state without explicit approval
- Do not silently change public API behavior
- Do not remove error handling unless explicitly instructed
- Preserve backward compatibility unless instructed otherwise

---

## 8. Self-check Requirements (Pre-commit Verification)

Before committing, Codex must verify:

- Design includes at least one alternative and one explicit limitation
- Concurrency/Safety is addressed (even if "not applicable")
- Testing section is complete
- Diff is minimal and scoped
- No unrelated files were modified

If any requirement is not satisfied, do not commit.

---

End of governance rules.

## Remote Upload Protocol (GitHub MCP Only)

- Codex must NOT use `git push` for remote uploads.
- When the user explicitly says: **"上传远端"** or **"Upload remote"**
  Codex MUST perform the remote update via **GitHub MCP API** (create commit / update files).
- Before remote upload, Codex MUST:
  1) summarize changed files and the intent
  2) confirm the target branch (default: `codex`)
  3) ensure commit message follows repository rules
- After remote upload, Codex MUST output:
  - branch name
  - commit SHA (or equivalent)
  - list of updated files

# 踩坑

  1. 我第一次的时候让他进行帮我上传github远端仓库的时候,他上传失败了,需要我的登录,原因是他走的是git push路线,而非mcp server路线,所以需要注意让codex不要走错