Tool Call Context Mcp Meta Converter
Converts a ToolCallContext into MCP _meta metadata for outbound MCP tool calls.
This is the gateway filter that controls what context entries cross the process boundary when Embabel calls tools on remote MCP servers. Think of it like an HTTP header filter on a reverse proxy: the converter decides which entries are safe and relevant to propagate to a third-party server, and which should stay local.
Why This Matters
A ToolCallContext may carry sensitive entries (API keys, auth tokens, tenant secrets) alongside benign metadata (tenant IDs, correlation IDs, user preferences). Without filtering, all entries would be sent as MCP _meta to every MCP server — including untrusted third-party servers that should never see secrets.
Usage
The converter is used by com.embabel.agent.spi.support.springai.SpringToolCallbackWrapper when bridging Embabel tools to Spring AI MCP callbacks.
Default behavior
The passThrough converter propagates all entries. Use this only when all MCP servers are trusted (e.g., internal infrastructure).
Allowlist approach (recommended for production)
val converter = ToolCallContextMcpMetaConverter.allowKeys("tenantId", "correlationId", "locale")Denylist approach
val converter = ToolCallContextMcpMetaConverter.denyKeys("apiKey", "secretToken", "authHeader")Custom logic
val converter = ToolCallContextMcpMetaConverter { context ->
mapOf(
"tenantId" to (context.get<String>("tenantId") ?: "unknown"),
"requestedAt" to Instant.now().toString(),
)
}Spring Bean (applied globally)
@Bean
fun toolCallContextMcpMetaConverter() =
ToolCallContextMcpMetaConverter.allowKeys("tenantId", "correlationId")If no bean is defined, the framework defaults to passThrough for backward compatibility.
See also
Functions
Convert a ToolCallContext to a metadata map suitable for MCP _meta.