feat: add optional Langfuse tracing for MCP tool calls#37
Merged
jeremyeder merged 9 commits intomainfrom Mar 6, 2026
Merged
Conversation
Add observability to the mcp-acp server via Langfuse integration. Every MCP tool call produces a trace with tool name, filtered args, duration, and success/error status. HTTP requests to the ACP public API appear as nested child spans with method, path, and status code. Tracing is opt-in and silently no-ops when unconfigured: - Reads LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL - MCP_ACP_TRACING_ENABLED env var (default: true) serves as kill switch - SDK init failures are caught and logged, never break tool execution - tracing.py: Langfuse v3 SDK client singleton, trace_tool_call and trace_http_request async context managers, no-op fallbacks, lifecycle - server.py: wrap call_tool() dispatch in trace_tool_call, flush on exit - client.py: wrap _request() and _request_text() in trace_http_request - settings.py: add missing _acpctl_config_path() (pre-existing bug fix) - test_tracing.py: 25 unit tests covering all tracing paths - scripts/test_tracing_e2e.py: e2e test against live ACP cluster Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Resolve conflict in client.py imports: - Keep tracing import from feature branch - Use corrected logger path from main (mcp_acp.utils.pylogger) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
thanks for posting the test results |
Add test_server_e2e.py with full coverage of all 26 MCP tools: - Session management (list, get, create, delete, restart, clone, update) - Observability (logs, transcript, metrics) - Labels (add, remove, list by label, bulk operations) - Bulk operations (delete, stop, restart - by name and by label) - Cluster management (list, whoami, switch, login) Tests use mocked HTTP transport to verify the complete flow from tool call through client to HTTP requests. Includes: - Success and error path testing - Dry-run mode verification - Confirmation requirement enforcement for destructive operations - Input validation testing - Complete workflow simulation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use single quotes for jsonpath argument containing double quotes - Remove unused f-string prefix Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove unused AsyncMock import, extra blank line, and fix multi-line call formatting. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use mcp_acp.utils.pylogger instead of utils.pylogger to match other modules in the package. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Improvements to MockHTTPClient: - Move to module level class with comprehensive docstrings - Add get_calls_for() to retrieve calls matching method/path - Add assert_called_with() for HTTP call verification - Sort responses by path length for better specificity matching New test cases: - test_create_session_with_repos: verify repos parameter handling - test_invalid_template_name: validation for unknown templates - test_update_session_no_fields: error when no update fields provided - test_bulk_by_label_no_matches: graceful empty results handling - test_empty_sessions_list: empty list display - test_delete_verifies_http_call: HTTP call verification example Other improvements: - Move json import to module level (remove local import) - Add detailed docstrings with test categories Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix test_client.py: Update test expectations to match actual API schema (use 'task' instead of 'initialPrompt', 'model' instead of 'llmConfig.model') - Fix clone_session: Add displayName to clone_data (was missing) - Fix test_tracing.py: Correct patch location for Langfuse module - Remove non-existent 'timeout' parameter from create_session tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Combine multi-line statements that ruff prefers on single lines. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
jeremyeder
approved these changes
Mar 6, 2026
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
MCP_ACP_TRACING_ENABLED=falseChanges
pyproject.tomllangfuse>=2.0.0dependencysrc/mcp_acp/tracing.pytrace_tool_call+trace_http_requestasync context managers, no-op fallbacks, flush/shutdown lifecyclesrc/mcp_acp/server.pycall_tool()intrace_tool_call, flush tracing on shutdownsrc/mcp_acp/client.py_request()and_request_text()intrace_http_requestsrc/mcp_acp/settings.py_acpctl_config_path()(pre-existing bug fix)tests/test_tracing.pyscripts/test_tracing_e2e.pyConfiguration
Opt-in via environment variables (Langfuse SDK reads these automatically):
Kill switch:
MCP_ACP_TRACING_ENABLED=falsedisables tracing even with credentials present.Test plan
uv run pytest tests/test_tracing.py)uv run pytest tests/)🤖 Generated with Claude Code