fix(contrib/mark3labs/mcp-go): avoid map race when normalizing RawInputSchema#4940
Conversation
|
BenchmarksBenchmark execution time: 2026-07-01 16:35:45 Comparing candidate commit fe6b3cb in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 321 metrics, 2 unstable metrics, 1 flaky benchmarks without significant changes.
|
…utSchema Follow-up to the previous commit. Unmarshalling RawInputSchema directly into &t.InputSchema left shared nested map references from server-reused tool definitions. Under concurrent tools/list requests this could cause 'fatal error: concurrent map writes' in production. Unmarshal into a fresh local mcp.ToolInputSchema value, then assign it to t.InputSchema. The existing maps.Clone of InputSchema.Properties remains as defense in depth. Ported from internal dd-source PR #469693.
a164286 to
f53b282
Compare
b88a735 to
fe6b3cb
Compare
Config Audit |
2993eeb to
a164286
Compare
a164286 to
fe6b3cb
Compare
74e067c
into
main
…tent injection (#4946) ## Summary `mcp.ToolInputSchema` only models `type`, `properties`, `required`, and `$defs`. Tools registered via `NewToolWithRawSchema` may declare other JSON Schema keywords (`additionalProperties`, `oneOf`, `patternProperties`, `pattern`, `enum`, `minimum`, `$schema`, …) — the previous round-trip through `ToolInputSchema` dropped all of them, so enabling intent capture quietly relaxed every raw-schema tool. Fix: inject telemetry into the raw JSON as a generic `map[string]any` and re-marshal. Unknown keys pass through verbatim. Same bug exists in the dd-source copy (not fixed there). Found by codex-connector on #4939. ## Test plan - [x] `TestIntentCaptureRawInputSchemaPreservesUnknownFields` — raw schema with `additionalProperties: false` and `oneOf` survives injection. - [x] All existing intent-capture tests still pass. Stacked on #4940. Co-authored-by: jboolean <julian.boilen@datadoghq.com>
…rs via context (#4941) This PR stack ports functionality added in the clone of this contrib in dd-source back to dd-trace-go so that the clone can be removed. ## Summary The intent-capture middleware annotates the LLMObs span with the client-supplied `telemetry.intent`, but tool handlers had no way to read it without re-parsing the telemetry blob — which the same middleware strips before the handler runs. This change: - Stashes the captured intent on `context.Context` alongside the existing LLMObs annotation. - Exports `IntentFromContext(ctx) (string, bool)` and `ContextWithIntent(ctx, intent) context.Context` so tool handlers can forward the intent downstream (e.g. to a search API for retrieval/ranking experiments). - Refactors the previous `processTelemetry` into `extractIntent` + `annotateIntentOnSpan` for clarity; behavior is otherwise unchanged. Ported from internal dd-source PR [#443664](DataDog/dd-source#443664). ## Test plan - [x] `TestIntentFromContext` — round-trip + empty-intent + missing-key behavior. - [x] `TestIntentCaptureStashesIntentOnContext` — end-to-end: a `tools/call` with `telemetry.intent` makes the value visible to the handler via `IntentFromContext`. - [x] Existing intent-capture tests still pass. Stacked on #4940. Co-authored-by: jboolean <julian.boilen@datadoghq.com>

This PR stack ports functionality added in the clone of this contrib in dd-source back to dd-trace-go.
Summary
Follow-up to #4939. That change unmarshalled
RawInputSchemadirectly into&t.InputSchema, which could leave shared nested map references from server-reused tool definitions. Under true parallelism, concurrenttools/listrequests could write the same map and crash withfatal error: concurrent map writes.This change unmarshals into a fresh local
mcp.ToolInputSchemavalue, then assigns it tot.InputSchema. The existingmaps.CloneofInputSchema.Propertiesremains as defense in depth.Ported from internal dd-source PR #469693.
Test plan
TestIntentCaptureConcurrentListToolsRawInputSchema— 10 goroutines × 100tools/listcalls against a raw-schema tool, run under-race.go test -race ./...incontrib/mark3labs/mcp-go/v2is green.Stacked on #4939.