Skip to content

fix(mcp): gaia mcp engineering and code-index print their refusal, not a traceback - #7536

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
lakshyab20:fix/7335-mcp-refusal-no-traceback
Nov 13, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
lakshyab20:fix/7335-mcp-refusal-no-traceback

Conversation

@lakshyab20

Copy link
Copy Markdown
Contributor

Summary

gaia mcp engineering without --developer-mode and gaia mcp code-index from the home directory refuse to start for a stated reason. They now print that reason on stderr and exit 1, with no traceback.

Why

Both servers let the exception escape (PermissionError, ValueError). An MCP client that launches them shows the user whatever the server printed, so a refusal that's meant to be read arrived as a Python crash.

Linked issue

Closes #7335

Changes

  • mcp/servers/engineering_mcp.py main(): catches the PermissionError from building the server and exits with gaia mcp engineering: <reason>. That covers the missing developer-mode flag and a rejected credential.
  • mcp/servers/code_index_mcp.py main(): asks _refuse_home_directory directly and exits with gaia mcp code-index: <reason>. The service still refuses on its own, so library callers are unchanged, and no other ValueError is caught.
  • The fix sits in each server's main(), so gaia mcp … and python -m gaia.mcp.servers.… behave the same. create_engineering_mcp and CodeIndexService still raise, so their existing tests are untouched.

Test plan

  • pytest tests/mcp/test_engineering_mcp.py tests/mcp/test_code_index_mcp.py tests/unit/test_code_index_mcp_service.py: 36 passed, 1 skipped (includes the existing launch-failure test, which still sees "home directory" in stderr)
  • 2 new tests run the real gaia mcp … as a subprocess and assert exit 1, the reason on stderr and no Traceback. Both fail on main.
  • python util/lint.py --black --isort: pass
  • Note: the mcp extra (mcp>=2.0.0,<3.0) has to be installed for these test files to collect.

Evidence

The real CLI (gaia.cli.main), an empty profile, code-index run from the home directory:

## BEFORE (main)
$ gaia mcp engineering --backend claude
  File "gaia/engineering/service.py", line 36, in __init__
    raise PermissionError(
PermissionError: Engineering is only available in developer mode; explicitly enable --developer-mode
>>> exit code: 1
$ gaia mcp code-index
  File "gaia/mcp/servers/code_index_mcp.py", line 43, in _refuse_home_directory
    raise ValueError(
ValueError: Refusing to serve a code index for your home directory (…): it would embed every repo, …
>>> exit code: 1

## AFTER (this branch)
$ gaia mcp engineering --backend claude
gaia mcp engineering: Engineering is only available in developer mode; explicitly enable --developer-mode
>>> exit code: 1
$ gaia mcp code-index
gaia mcp code-index: Refusing to serve a code index for your home directory (…): it would embed every repo, … Pass the repository instead, e.g. `gaia mcp code-index --repo ~/src/myrepo`.
>>> exit code: 1
  • MCP: the refusal path above is the surface; the servers' working paths are unchanged and covered by the existing stdio tests.
  • Agent UI / HTTP: N/A.

Checklist

  • I have linked a GitHub issue above (Closes #N / Fixes #N / Refs #N).
  • I have described why this change is being made, not just what changed.
  • I have run linting and tests locally.
  • I have attached real-world evidence matched to the surface I changed (see Evidence above), or marked each surface N/A.
  • I have updated documentation if user-visible behavior changed (no docs describe this error).

@github-actions github-actions Bot added mcp MCP integration changes tests Test changes labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

When gaia mcp engineering is run without developer mode, or gaia mcp code-index is run from the home directory, each server now prints its one-line reason and exits 1 instead of crashing with a Python traceback. The fix is narrow: only those two refusals are caught, and the code underneath still raises the same errors for library callers. Two new tests run the real gaia mcp … command and are in the CI MCP lane.

Real-world evidence

N/A here: no evidence bundle was produced for this run. The PR description has before and after output from the real CLI for both commands (traceback before; one line and exit 1 after), and that matches the code. The working paths of both servers are unchanged and already covered by the existing stdio tests.

🔍 Technical details

Issues found: none blocking.

  • 🟢 The engineering except PermissionError in src/gaia/mcp/servers/engineering_mcp.py:115 also catches an OS-level EACCES from JobStore(root) creating its directory. That case still prints [Errno 13] Permission denied: <path> and exits 1, so it stays loud, just as one line with no stack. Fine as is; mentioned so it's a deliberate choice.

Checked

  • gaia/cli.py sends both commands to these main() functions, so gaia mcp … and python -m … behave the same. The code-index ImportError handler in the CLI is unaffected.
  • Code-index runs _refuse_home_directory on the same expanded path the service checks, so the early check matches the service's own refusal and no other ValueError is caught.
  • Both test files are listed in test_unit.yml's MCP lane, so the new tests run in CI.
  • No doc quotes these errors, so no docs need updating.

Strengths

  • The tests drive the real CLI in a subprocess with an isolated HOME and check the exit code, the message on stderr and that no Traceback appears. That proves the exact behaviour a user's MCP client would show.
  • The refusal is checked by name in code-index rather than with a broad except ValueError, so unrelated errors still surface in full.

@lakshyab20
lakshyab20 force-pushed the fix/7335-mcp-refusal-no-traceback branch from 1fe35f3 to 9ef75c4 Compare November 12, 2026 16:40
@github-actions github-actions Bot added the installer Installer changes label Nov 12, 2026
@kovtcharov-amd kovtcharov-amd added bug Something isn't working cli CLI changes labels Nov 12, 2026
…t a traceback

Both servers refuse to start for a stated reason (no --developer-mode; the
home directory as the repo) and let the exception escape. Print the reason on
stderr and exit 1, which is what an MCP client shows the user.

Closes amd#7335
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 13, 2026
Merged via the queue into amd:main with commit 7a233cd Nov 13, 2026
129 checks passed
@kovtcharov-amd kovtcharov-amd mentioned this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli CLI changes installer Installer changes mcp MCP integration changes p2 low priority tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: gaia mcp engineering and gaia mcp code-index show their refusal as a traceback

2 participants