Skip to content

fix: pass LOGFIRE_BASE_URL to MCP configurations for self-hosted instances#1626

Open
mythral wants to merge 3 commits intopydantic:mainfrom
mythral:mythral-fix-mcp-base-url
Open

fix: pass LOGFIRE_BASE_URL to MCP configurations for self-hosted instances#1626
mythral wants to merge 3 commits intopydantic:mainfrom
mythral:mythral-fix-mcp-base-url

Conversation

@mythral
Copy link

@mythral mythral commented Jan 13, 2026

Summary

  • Fixes MCP server configuration to include LOGFIRE_BASE_URL when using --base-url flag
  • Without this fix, self-hosted Logfire instances couldn't use the prompt command with --claude, --codex, or --opencode flags because the MCP server would default to the standard Logfire URL

Problem

When running:

logfire --base-url https://logfire.example.com prompt \
  --project org/project issue:123 --claude

The CLI correctly used the custom URL for API calls (authentication, token creation, prompt retrieval), but when configuring the MCP server, only LOGFIRE_READ_TOKEN was passed. The LOGFIRE_BASE_URL environment variable was not included, causing the MCP server to connect to the wrong Logfire instance.

Changes

  • Updated configure_claude() to include -e LOGFIRE_BASE_URL=<url> in the claude mcp add command
  • Updated configure_codex() to include LOGFIRE_BASE_URL in the TOML configuration
  • Updated configure_opencode() to include LOGFIRE_BASE_URL in the JSON configuration
  • Added tests to verify base URL is passed correctly for all three integrations

Test plan

  • All existing prompt-related tests pass
  • New tests verify LOGFIRE_BASE_URL is included in Claude, Codex, and OpenCode configurations
  • Format and lint checks pass

🤖 Generated with Claude Code

…ances

When using the `--base-url` (or deprecated `--logfire-url`) flag to point
to a self-hosted Logfire instance, the MCP server configuration was only
receiving `LOGFIRE_READ_TOKEN`. This caused the MCP server to default to
the standard Logfire URL instead of the self-hosted instance.

Example of the issue:
```bash
logfire --base-url https://logfire.example.com prompt \
  --project org/project issue:123 --claude
```

The CLI correctly used the custom URL for API calls (authentication,
token creation, prompt retrieval), but when configuring the MCP server
for Claude/Codex/OpenCode, the `LOGFIRE_BASE_URL` environment variable
was not included.

This fix:
- Updates `configure_claude()` to include `-e LOGFIRE_BASE_URL=<url>`
  when a custom base URL is provided
- Updates `configure_codex()` to include `LOGFIRE_BASE_URL` in the
  TOML configuration
- Updates `configure_opencode()` to include `LOGFIRE_BASE_URL` in the
  JSON configuration
- Adds tests to verify the base URL is passed correctly for all three
  integrations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alexmojaki alexmojaki requested a review from Kludex January 13, 2026 18:11
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mythral mythral marked this pull request as ready for review January 13, 2026 18:17
mythral and others added 2 commits January 13, 2026 13:28
The `_opencode_mcp_json` function was returning a structure wrapped in
`{'mcp': {'logfire-mcp': {...}}}`, but the caller in `configure_opencode`
was wrapping it again, creating an invalid double-nested structure:
`{'mcp': {'logfire-mcp': {'mcp': {'logfire-mcp': {...}}}}}`

This also caused silent data loss of existing MCP server configurations
when merging with an existing opencode.jsonc file.

Changes:
- Renamed `_opencode_mcp_json` to `_opencode_mcp_entry` and changed it
  to return only the inner config (without mcp wrapper)
- Updated `configure_opencode` to properly construct the full structure
  when writing to empty files and properly merge when existing config
- Updated existing test to verify JSON structure is correct
- Added new test for merging with existing config + base_url that
  verifies both existing config preservation and correct structure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Improved test coverage to verify the exact output schemas for all three
MCP integrations match their official documentation:

- Claude: Verify full command format with `-e KEY=VALUE` flags
- Codex: Already had full TOML schema verification
- OpenCode: Added JSON schema verification for empty file case

All schemas verified against official docs:
- Claude: https://code.claude.com/docs/en/mcp
- Codex: https://developers.openai.com/codex/mcp/
- OpenCode: https://opencode.ai/docs/mcp-servers/

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mythral
Copy link
Author

mythral commented Jan 13, 2026

FYI: I updated this with tests for fully validating the schema format's against the docs from the various providers.

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.

1 participant