GPT Codex CLIΒΆ

Building AI Scientists with GPT Codex CLI and ToolUniverse

OverviewΒΆ

GPT Codex CLI integration enables powerful command-line-based scientific research through the Model Context Protocol (MCP). This approach provides a terminal-based interface for scientific research while leveraging Codex’s advanced reasoning capabilities and ToolUniverse’s comprehensive scientific tools ecosystem.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Codex CLI     β”‚ ← Command Line Interface & Reasoning
β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ MCP Protocol
          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
β”‚ ToolUniverse     β”‚ ← MCP Server
β”‚   MCP Server     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
β”‚ 600+ Scientific β”‚ ← Scientific Tools Ecosystem
β”‚     Tools       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benefits of Codex CLI Integration:

  • Command-Line Efficiency: Fast, scriptable scientific research workflows

  • Advanced Reasoning: Codex’s sophisticated reasoning for complex scientific problems

  • Comprehensive Tools: Access to 600+ scientific tools across multiple domains

  • Automated Execution: Direct tool execution through natural language commands

  • Batch Processing: Handle multiple research tasks efficiently

Installation and SetupΒΆ

  • Codex CLI: Install using npm or Homebrew

  • Python 3.10+: Required for ToolUniverse

  • UV Package Manager: For dependency management

  • ChatGPT Account: For authentication (recommended)

Step 1: Install Codex CLIΒΆ

# Using npm (recommended):
npm install -g @openai/codex

# OR Using Homebrew (macOS/Linux):
brew install codex

#Verify installation:
codex --version

Step 2: Install UV and ToolUniverseΒΆ

# Install UV package manager
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create environment and install ToolUniverse
mkdir -p ~/tooluniverse-env
uv --directory ~/tooluniverse-env pip install tooluniverse

# Verify installation
uv --directory ~/tooluniverse-env run python -c "import tooluniverse; print('ToolUniverse installed successfully')"

Step 3: Configure Codex CLIΒΆ

Create the configuration file:

mkdir -p ~/.codex
vim ~/.codex/config.toml

Add the ToolUniverse MCP server configuration:

[mcp_servers.tooluniverse]
command = "uv"
args = [
  "--directory",
  "~/tooluniverse-env",
  "run",
  "tooluniverse-smcp-stdio"
]
Advanced Settings
[mcp_servers.tooluniverse]
command = "uv"
args = [
  "--directory",
  "~/tooluniverse-env",
  "run",
  "tooluniverse-smcp-stdio",
  "--exclude-tool-types",
  "PackageTool",
  "--hook-type",
  "SummarizationHook"
]

[mcp_servers.tooluniverse.env]
AZURE_OPENAI_API_KEY = "your-azure-openai-api-key"
AZURE_OPENAI_ENDPOINT = "https://your-resource.openai.azure.com"

Configuration Benefits:

  • --exclude-tool-types PackageTool: Removes package management tools to save context window space if you don’t have coding needs

  • --hook-type SummarizationHook: Provides summary of the output that is too long to fit in the context window

  • AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT: Required for SummarizationHook functionality

Step 4: Authenticate and StartΒΆ

Sign in with ChatGPT (recommended):

codex

Select Sign in with ChatGPT when prompted.

Or use API key:

export OPENAI_API_KEY="your-api-key-here"
codex

Step 5: Configure Context File (Optional)ΒΆ

Create a context file to provide project-specific instructions for scientific research:

  1. Create AGENTS.md file in your project root:

    vim AGENTS.md
    
  2. Add ToolUniverse-specific context:

    # ToolUniverse Scientific Research Project
    
    ## General Instructions
    
    - Leverage ToolUniverse's scientific tools ecosystem for evidence-based research
    - Use tools from tooluniverse mcp server first
    - Cross-validate findings across multiple tools and databases
    - Use appropriate scientific terminology
    - Follow systematic research methodologies
    

Step 6: Verify IntegrationΒΆ

  1. Start Codex CLI: codex

  2. Check MCP status: /mcp

  3. Test with: What scientific tools are available?

Scientific Research CapabilitiesΒΆ

Codex CLI with ToolUniverse provides comprehensive scientific research capabilities:

Drug Discovery and Development - Target identification and validation - Drug information retrieval and analysis - Safety profile analysis and clinical trial data

Genomics and Molecular Biology - Gene analysis from UniProt - Protein structure and interaction analysis - Pathway analysis and functional annotation

Literature Research - PubMed and Semantic Scholar searches - Abstract summarization and trend analysis - Citation analysis and gap identification

Clinical Research - ClinicalTrials.gov searches - FDA approvals and safety information - Regulatory information access

Multi-Step Workflows - Hypothesis-driven research - Comparative analysis - Complex research task automation

Advanced ConfigurationΒΆ

Tool Selection

Load only specific tools for better performance:

[mcp_servers.tooluniverse]
command = "uv"
args = [
  "--directory",
  "~/tooluniverse-env",
  "run",
  "tooluniverse-smcp-stdio",
  "--include-tools",
  "EuropePMC_search_articles",
  "ChEMBL_search_similar_molecules",
  "search_clinical_trials"
]

Multiple Servers

Run different ToolUniverse instances for different purposes:

[mcp_servers.tooluniverse-research]
command = "uv"
args = ["--directory", "~/tooluniverse-env", "run", "tooluniverse-smcp-stdio"]
timeout = 30000

[mcp_servers.tooluniverse-analysis]
command = "uv"
args = ["--directory", "~/tooluniverse-env", "run", "tooluniverse-smcp-stdio"]
timeout = 45000

TroubleshootingΒΆ

Step-by-Step Debugging:

  1. Check Codex CLI Version: .. code-block:: bash

    codex –version

    Ensure you’re using the latest version. Older versions may have MCP server issues.

  2. Verify Configuration File: .. code-block:: bash

    cat ~/.codex/config.toml

    Ensure the file exists and has correct TOML syntax.

  3. Test MCP Server Manually: .. code-block:: bash

    uv –directory ~/tooluniverse-env run tooluniverse-smcp-stdio

    This should start the MCP server directly to check if it works.

  4. Check Codex CLI Logs: .. code-block:: bash

    DEBUG=true codex

    This enables detailed logging to see MCP server connection errors.

  5. Verify MCP Server Status: Start Codex CLI and run: .. code-block:: text

    codex /mcp

    Check if ToolUniverse tools are listed.

  6. Check Available Commands: .. code-block:: bash

    codex –help

    View all available Codex CLI options.

Common Issues:

  • MCP Server Not Loading: Check ToolUniverse installation path and UV installation

  • No Tools Discovered: Verify MCP server is working and tool filters aren’t too restrictive

  • Tools Not Executing: Check API keys and network connectivity

  • Authentication Issues: Ensure ChatGPT sign-in or valid API key

Debug Commands:

  • DEBUG=true codex: Run with detailed logging

  • codex --help: Show all available options

  • /mcp: Show MCP server status (if available)

ReferencesΒΆ