Skip to content

fix(codex): declare agentmemory MCP server as stdio#822

Open
jinzheng8115 wants to merge 2 commits into
rohitg00:mainfrom
jinzheng8115:codex/agentmemory-codex-stdio
Open

fix(codex): declare agentmemory MCP server as stdio#822
jinzheng8115 wants to merge 2 commits into
rohitg00:mainfrom
jinzheng8115:codex/agentmemory-codex-stdio

Conversation

@jinzheng8115
Copy link
Copy Markdown

@jinzheng8115 jinzheng8115 commented Jun 4, 2026

Summary

  • add type = "stdio" to the Codex MCP block written by agentmemory connect codex
  • add a focused Codex adapter regression test to lock the generated block shape

Why

In my local Codex Desktop setup, the agentmemory server entry was written without an explicit transport type. Other Codex MCP entries in config.toml use type = "stdio", and adding it locally brought the config back into the expected shape for stdio-launched MCP servers.

Validation

  • reproduced that memory_save and memory_lesson_save work when the standalone MCP process is launched directly
  • verified the generated fork diff only changes src/cli/connect/codex.ts and adds a Codex adapter test
  • updated my local ~/.codex/config.toml to include type = "stdio" for mcp_servers.agentmemory as a runtime workaround

I was not able to run the full upstream test suite in this environment because getting a clean local checkout of the full repo stalled repeatedly, so this PR focuses on the minimal config change plus regression coverage.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Codex adapter configuration for Agentmemory MCP server setup with proper stdio server type specification.
  • Tests

    • Added test suite for Codex adapter, verifying environment detection, configuration installation, and backup creation.

Copilot AI review requested due to automatic review settings June 4, 2026 11:24
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

@jinzheng8115 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds type = "stdio" to the Agentmemory Codex MCP server TOML configuration block and introduces a comprehensive test suite for the Codex adapter that validates the configuration change with mock filesystem operations and environment handling.

Changes

Codex adapter stdio configuration

Layer / File(s) Summary
TOML configuration update
src/cli/connect/codex.ts
The MCP server configuration [mcp_servers.agentmemory] block now includes type = "stdio" in the TOML_BLOCK constant.
Codex adapter test suite
test/codex-connect.test.ts
New test suite with mock HOME directory setup verifies detect() returns false when Codex config missing, install() writes correct TOML config with stdio type and npx command, and install() backs up existing config.toml files with a defined backup path.

🎯 2 (Simple) | ⏱️ ~12 minutes

A config whisker here, a test there,
The Codex adapter, oh so fair!
Type stdio declared with care,
Coverage blessed with tests to share. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the primary change: adding the type = "stdio" declaration to the agentmemory MCP server configuration in the Codex adapter, which is the core fix addressed in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds explicit type = "stdio" to the Codex MCP server TOML block and introduces a Vitest suite that validates Codex adapter detection, install wiring, and backup behavior using a temporary home directory.

Changes:

  • Update Codex TOML wiring block to include type = "stdio".
  • Add Vitest coverage for Codex adapter detect() and install() including backup creation.
  • Use a temp HOME/USERPROFILE to isolate filesystem writes in tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
test/codex-connect.test.ts Adds integration-style tests for Codex connect adapter behavior using a temp home dir.
src/cli/connect/codex.ts Updates TOML wiring block to include an explicit stdio type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


it("install() writes a stdio MCP server block for Codex", async () => {
const codexDir = join(tmpHome, ".codex");
require("node:fs").mkdirSync(codexDir, { recursive: true });

it("install() creates a backup when rewriting an existing Codex config", async () => {
const codexDir = join(tmpHome, ".codex");
require("node:fs").mkdirSync(codexDir, { recursive: true });
Comment on lines +14 to +21
beforeEach(() => {
tmpHome = mkdtempSync(join(tmpdir(), "am-connect-codex-"));
originalHome = process.env["HOME"];
originalUserprofile = process.env["USERPROFILE"];
process.env["HOME"] = tmpHome;
process.env["USERPROFILE"] = tmpHome;
vi.resetModules();
});
Comment on lines +34 to +36
const mod = await import(
"../src/cli/connect/codex.js?t=" + Date.now() + "-" + importCounter++
);
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
test/codex-connect.test.ts (1)

8-78: ⚡ Quick win

Consider adding test coverage for the "already-wired" case.

The test suite provides focused regression coverage for the stdio config change, but doesn't test the scenario where config.toml already contains [mcp_servers.agentmemory] and force: false is used. This case returns { kind: "already-wired" } (lines 80-83 in codex.ts) and is an important code path for idempotent installations.

📋 Suggested test case
it("install() returns already-wired when config exists and force is false", async () => {
  const codexDir = join(tmpHome, ".codex");
  mkdirSync(codexDir, { recursive: true });
  const existingBlock = `[mcp_servers.agentmemory]
type = "stdio"
command = "npx"
args = ["-y", "`@agentmemory/mcp`"]

[mcp_servers.agentmemory.env]
AGENTMEMORY_URL = "http://localhost:3111"
`;
  writeFileSync(join(codexDir, "config.toml"), existingBlock);

  const a = await loadAdapter();
  const result = await a.install({ dryRun: false, force: false });
  expect(result.kind).toBe("already-wired");
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/codex-connect.test.ts` around lines 8 - 78, Add a test that covers the
"already-wired" path by creating ~/.codex/config.toml containing an existing
[mcp_servers.agentmemory] stdio block, then calling the adapter's install({
dryRun: false, force: false }) and asserting the result.kind ===
"already-wired"; locate the ConnectAdapter via the existing loadAdapter helper
(adapter exported from codex.js) and reuse the tmpHome setup in the test file so
the test mirrors the other cases that create ~/.codex and call a.install().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/codex-connect.test.ts`:
- Line 67: The call currently uses CommonJS require to get mkdirSync; replace
require("node:fs").mkdirSync(codexDir, { recursive: true }) with the
already-imported mkdirSync(codexDir, { recursive: true }) to avoid mixing ESM
imports and CommonJS—update the invocation in the test (same pattern as the
earlier fix around line 47) so it uses the imported mkdirSync symbol and
preserves the codexDir and options.
- Line 47: Replace the CommonJS require call with the already imported ESM
symbol: remove require("node:fs").mkdirSync(...) and call the top-level imported
mkdirSync directly (e.g., mkdirSync(codexDir, { recursive: true })), ensuring
you use the existing imported mkdirSync from the file and keep the codexDir as
the first argument.

---

Nitpick comments:
In `@test/codex-connect.test.ts`:
- Around line 8-78: Add a test that covers the "already-wired" path by creating
~/.codex/config.toml containing an existing [mcp_servers.agentmemory] stdio
block, then calling the adapter's install({ dryRun: false, force: false }) and
asserting the result.kind === "already-wired"; locate the ConnectAdapter via the
existing loadAdapter helper (adapter exported from codex.js) and reuse the
tmpHome setup in the test file so the test mirrors the other cases that create
~/.codex and call a.install().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68eb8ca6-15b2-49f8-ab11-c6a83ec7a513

📥 Commits

Reviewing files that changed from the base of the PR and between 334e5ad and 3e30b4a.

📒 Files selected for processing (2)
  • src/cli/connect/codex.ts
  • test/codex-connect.test.ts


it("install() writes a stdio MCP server block for Codex", async () => {
const codexDir = join(tmpHome, ".codex");
require("node:fs").mkdirSync(codexDir, { recursive: true });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the imported mkdirSync instead of require().

The test file imports mkdirSync from node:fs at line 2 but then uses require("node:fs").mkdirSync(...) here. This mixes ESM and CommonJS and violates the coding guideline: "Use TypeScript and ESM only (type: module in package.json)". As per coding guidelines, ESM should be used consistently throughout the codebase.

♻️ Proposed fix
-    require("node:fs").mkdirSync(codexDir, { recursive: true });
+    mkdirSync(codexDir, { recursive: true });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
require("node:fs").mkdirSync(codexDir, { recursive: true });
mkdirSync(codexDir, { recursive: true });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/codex-connect.test.ts` at line 47, Replace the CommonJS require call
with the already imported ESM symbol: remove require("node:fs").mkdirSync(...)
and call the top-level imported mkdirSync directly (e.g., mkdirSync(codexDir, {
recursive: true })), ensuring you use the existing imported mkdirSync from the
file and keep the codexDir as the first argument.


it("install() creates a backup when rewriting an existing Codex config", async () => {
const codexDir = join(tmpHome, ".codex");
require("node:fs").mkdirSync(codexDir, { recursive: true });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the imported mkdirSync instead of require().

Same issue as line 47: the file imports mkdirSync from node:fs at line 2, but this line uses require("node:fs").mkdirSync(...). This violates the ESM-only coding guideline. As per coding guidelines, avoid mixing ESM imports with CommonJS require().

♻️ Proposed fix
-    require("node:fs").mkdirSync(codexDir, { recursive: true });
+    mkdirSync(codexDir, { recursive: true });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
require("node:fs").mkdirSync(codexDir, { recursive: true });
mkdirSync(codexDir, { recursive: true });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/codex-connect.test.ts` at line 67, The call currently uses CommonJS
require to get mkdirSync; replace require("node:fs").mkdirSync(codexDir, {
recursive: true }) with the already-imported mkdirSync(codexDir, { recursive:
true }) to avoid mixing ESM imports and CommonJS—update the invocation in the
test (same pattern as the earlier fix around line 47) so it uses the imported
mkdirSync symbol and preserves the codexDir and options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants