Skip to main content

Minimal FastMCP server that wraps the OpenAI Codex CLI

Project description

CodexMCP

Minimal FastMCP server that wraps the OpenAI Codex CLI and makes the model available over standard‑I/O so it can be consumed with mcp‑cli (or any other MCP‑compatible client).

Tools exposed by this server (all asynchronous):

  1. generate_code(description, language="Python", model="o4-mini")
  2. refactor_code(code, instruction, model="o4-mini")
  3. write_tests(code, description="", model="o4-mini")
  4. explain_code(code, detail_level="medium", model="o4-mini")
  5. generate_docs(code, doc_format="docstring", model="o4-mini")

Everything that the Codex subprocess prints (stdout and stderr) is recorded to ~/.codexmcp/logs/ with rotation (5 files × 5 MiB).


Installation (Linux/macOS)

Prerequisites

  1. Install Node 18 LTS and the Codex CLI globally:
npm install -g @openai/codex
  1. Create a .env file in your working directory:
OPENAI_API_KEY=sk-<your-key>

Install CodexMCP

Install using pip:

pip install codexmcp

Alternatively, install the latest version directly from GitHub:

pip install "git+https://github.com/tomascupr/codexMCP.git#egg=codexmcp"

Running the server

Once installed, you can start the server in one of two ways:

  • Using the console script:

    codexmcp
    
  • Using Python's module mode:

    python -m codexmcp.server
    

The first request may take a couple of seconds while the model warms up; after that each call returns in ~0.5‑1.5 s.


Using mcp-cli

# List available tools (smoke-test: should answer <2 s)
 mcp-cli chat --server CodexMCP -q '["list_tools"]'

# Ask Codex to write a Rust hello-world program
mcp-cli chat --server CodexMCP -q \
    'mcp__CodexMCP__generate_code("hello world", "Rust")'

# Get an explanation of code
mcp-cli chat --server CodexMCP -q \
    'mcp__CodexMCP__explain_code("def fibonacci(n):\n    if n <= 1:\n        return n\n    return fibonacci(n-1) + fibonacci(n-2)", "brief")'

API examples

# Refactor some code
mcp-cli chat --server CodexMCP -q \
  'mcp__CodexMCP__refactor_code("print(1+1)", "convert to a function")'

# Generate PyTest tests
mcp-cli chat --server CodexMCP -q \
  'mcp__CodexMCP__write_tests("def fib(n): return 1 if n<2 else fib(n-1)+fib(n-2)")'

Troubleshooting

codex: command not found → ensure npm's global bin directory is on $PATH. • .env warnings → make sure your .env file is in your working directory. • Logs not written → check permissions for ~/.codexmcp. • Long delay before first answer → normal, model container has to warm up.

Testing

Run the test suite with pytest:

# Install test dependencies
pip install -r requirements.txt

# Run all tests
pytest

# Run with coverage report
pytest --cov=codexmcp

# Run specific test file
pytest tests/test_tools.py

License

MIT‑0 – see LICENSE if present.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codexmcp-0.1.3.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codexmcp-0.1.3-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file codexmcp-0.1.3.tar.gz.

File metadata

  • Download URL: codexmcp-0.1.3.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for codexmcp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1db75ae777e6feaff1576eb146a4931e94d6166b8ae782dd71b496d6512ec7ad
MD5 5425e2c63474652b4ca0d460e50ab3ac
BLAKE2b-256 440842ca621e61be62ce7a3297656cc6b3d7e77967f20922c4e9f706aeaa3113

See more details on using hashes here.

File details

Details for the file codexmcp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: codexmcp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for codexmcp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d25c8323575254ca9be4be1ba5d4e1aa9bcdd497a70ca5bc72a10b07a480e395
MD5 e179955c3c9ae50409ff4740242e01a0
BLAKE2b-256 6e2c2deac264f69ebd933989f706da844d3cf2459aa9e1c85baccb5b410de3e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page