记录类 McpMeta
java.lang.Object
java.lang.Record
io.agentscope.core.tool.mcp.McpMeta
Type-namespace marker for MCP (Model Context Protocol) request metadata.
Register an instance of this class in a RuntimeContext (via
RuntimeContext or RuntimeContext) to have its
entries automatically included as the meta field of every MCP
McpSchema.CallToolRequest sent through McpTool.
Only objects registered under the McpMeta.class type key are extracted — other
context objects (DI beans, configs, etc.) are never leaked into MCP meta.
Usage examples:
1) Via RuntimeContext:
RuntimeContext rtCtx = RuntimeContext.builder()
.put(McpMeta.class, new McpMeta(Map.of("traceId", "abc-123")))
.build();
2) Merging multiple meta sources (later entries override earlier ones for the same key):
McpMeta base = new McpMeta(Map.of("traceId", "abc-123"));
McpMeta extra = new McpMeta(Map.of("callbackUrl", "https://hook.example.com"));
McpMeta merged = McpMeta.merge(base, extra);
- 另请参阅:
-
构造器概要
构造器 -
方法概要
-
构造器详细资料
-
McpMeta
Creates an McpMeta with the given entries.- 参数:
entries- the metadata entries (may be null or empty); the map is defensively copied
-
-
方法详细资料
-
entries
Returns the metadata entries as an unmodifiable map.- 返回:
- the entries, never null (may be empty)
-
isEmpty
public boolean isEmpty()Returns whether this meta contains no entries.- 返回:
- true if empty, false otherwise
-
merge
Merges multipleMcpMetainstances into one.Entries from later instances override earlier ones for the same key (last-wins).
- 参数:
metas- the meta instances to merge (nulls are silently skipped)- 返回:
- a new merged McpMeta, or an empty one if all inputs are null/empty
-
equals
指示某个其他对象是否“等于”此对象。如果两个对象属于同一个类,而且所有记录组件都相等,则这两个对象相等。 此记录类中的所有组件都使用Objects::equals(Object,Object)进行比较。 -
toString
返回此记录类的字符串表示形式。此表示形式包含类的名称,后跟每个记录组件的名称和值。 -
hashCode
public final int hashCode()返回此对象的哈希代码值。此值派生自每个记录组件的哈希代码。
-