MCPcopy
hub / github.com/googleapis/mcp-toolbox / TestExtractMeta

Function TestExtractMeta

internal/server/mcp_test.go:1619–1736  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1617}
1618
1619func TestExtractMeta(t *testing.T) {
1620 // withTraceContextPropagator registers the W3C trace-context propagator globally
1621 // for the duration of the test. extractMeta delegates to otel.GetTextMapPropagator,
1622 // and the default global propagator is a no-op — so without this helper the
1623 // "extracted" trace context would always be invalid.
1624 t.Helper()
1625 prev := otel.GetTextMapPropagator()
1626 otel.SetTextMapPropagator(propagation.TraceContext{})
1627 t.Cleanup(func() { otel.SetTextMapPropagator(prev) })
1628
1629 testCases := []struct {
1630 name string
1631 body []byte
1632 wantEmptyCtx bool
1633 wantValidSpanContext bool
1634 wantTraceId string
1635 wantProtocolVersion string
1636 wantTelemetryAttr *util.TelemetryAttributes
1637 wantClientName string
1638 wantClientVersion string
1639 }{
1640 {
1641 name: "empty meta",
1642 body: []byte(""),
1643 wantEmptyCtx: true,
1644 },
1645 {
1646 name: "not json meta",
1647 body: []byte("not json"),
1648 wantEmptyCtx: true,
1649 },
1650 {
1651 name: "no _meta",
1652 body: []byte(`{"params":{}}`),
1653 wantEmptyCtx: true,
1654 },
1655 {
1656 name: "no params",
1657 body: []byte(`{"method":"tools/call"}`),
1658 wantEmptyCtx: true,
1659 },
1660 {
1661 name: "empty meta",
1662 body: []byte(`{"params":{"_meta":{}}}`),
1663 wantEmptyCtx: true,
1664 },
1665 {
1666 name: "traceparent only",
1667 body: []byte(`{"params":{"_meta":{"traceparent":"00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"}}}`),
1668 wantValidSpanContext: true,
1669 wantEmptyCtx: true,
1670 },
1671 {
1672 name: "telemetry attributes only",
1673 body: []byte(`{"params":{"_meta":{"dev.mcp-toolbox/telemetry":{` +
1674 `"client.name":"toolbox-langchain-python",` +
1675 `"client.version":"v0.1.0",` +
1676 `"client.model":"gemini-2.5-flash",` +

Callers

nothing calls this directly

Calls 3

extractMetaFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected