记录类 McpMeta

java.lang.Object
java.lang.Record
io.agentscope.core.tool.mcp.McpMeta

public record McpMeta(Map<String,Object> entries) extends Record
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

      public McpMeta(Map<String,Object> entries)
      Creates an McpMeta with the given entries.
      参数:
      entries - the metadata entries (may be null or empty); the map is defensively copied
  • 方法详细资料

    • entries

      public Map<String,Object> 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

      public static McpMeta merge(McpMeta... metas)
      Merges multiple McpMeta instances 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

      public boolean equals(Object o)
      指示某个其他对象是否“等于”此对象。如果两个对象属于同一个类,而且所有记录组件都相等,则这两个对象相等。 此记录类中的所有组件都使用 Objects::equals(Object,Object) 进行比较。
      指定者:
      equals 在类中 Record
      参数:
      o - 要与之进行比较的对象
      返回:
      如果此对象与 o 参数相同,则为 true;否则为 false。
    • toString

      public String toString()
      返回此记录类的字符串表示形式。此表示形式包含类的名称,后跟每个记录组件的名称和值。
      指定者:
      toString 在类中 Record
      返回:
      此对象的字符串表示形式
    • hashCode

      public final int hashCode()
      返回此对象的哈希代码值。此值派生自每个记录组件的哈希代码。
      指定者:
      hashCode 在类中 Record
      返回:
      此对象的哈希代码值