fix: pass LOGFIRE_BASE_URL to MCP configurations for self-hosted instances#1626
Open
mythral wants to merge 3 commits intopydantic:mainfrom
Open
fix: pass LOGFIRE_BASE_URL to MCP configurations for self-hosted instances#1626mythral wants to merge 3 commits intopydantic:mainfrom
mythral wants to merge 3 commits intopydantic:mainfrom
Conversation
…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>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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>
Author
|
FYI: I updated this with tests for fully validating the schema format's against the docs from the various providers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LOGFIRE_BASE_URLwhen using--base-urlflagpromptcommand with--claude,--codex, or--opencodeflags because the MCP server would default to the standard Logfire URLProblem
When running:
The CLI correctly used the custom URL for API calls (authentication, token creation, prompt retrieval), but when configuring the MCP server, only
LOGFIRE_READ_TOKENwas passed. TheLOGFIRE_BASE_URLenvironment variable was not included, causing the MCP server to connect to the wrong Logfire instance.Changes
configure_claude()to include-e LOGFIRE_BASE_URL=<url>in the claude mcp add commandconfigure_codex()to includeLOGFIRE_BASE_URLin the TOML configurationconfigure_opencode()to includeLOGFIRE_BASE_URLin the JSON configurationTest plan
LOGFIRE_BASE_URLis included in Claude, Codex, and OpenCode configurations🤖 Generated with Claude Code