Commit c0af6b0
feat: add optional Langfuse tracing for MCP tool calls (#37)
* feat: add optional Langfuse tracing for MCP tool calls and HTTP requests
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>
* test: add comprehensive E2E tests for MCP server
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>
* Fix ruff linting issues in test_tracing_e2e.py
- Use single quotes for jsonpath argument containing double quotes
- Remove unused f-string prefix
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix ruff linting issues in test_server_e2e.py
Remove unused AsyncMock import, extra blank line, and fix multi-line
call formatting.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix import path for pylogger in tracing.py
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>
* refactor: enhance E2E tests with better mocking and edge cases
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 failures and implementation bug
- 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>
* Fix ruff formatting in test_server_e2e.py
Combine multi-line statements that ruff prefers on single lines.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Ambient Code Bot <bot@ambient-code.local>
Co-authored-by: Jeremy Eder <jeder@redhat.com>1 parent 0bc57bf commit c0af6b0
8 files changed
Lines changed: 1164 additions & 286 deletions
File tree
- scripts
- src/mcp_acp
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
183 | 169 | | |
184 | | - | |
185 | | - | |
186 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
187 | 174 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
| |||
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
224 | | - | |
225 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
226 | 231 | | |
227 | | - | |
228 | | - | |
| 232 | + | |
| 233 | + | |
229 | 234 | | |
230 | | - | |
| 235 | + | |
231 | 236 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
238 | 243 | | |
239 | 244 | | |
240 | 245 | | |
| |||
544 | 549 | | |
545 | 550 | | |
546 | 551 | | |
| 552 | + | |
547 | 553 | | |
548 | 554 | | |
549 | 555 | | |
| |||
0 commit comments