@@ -1668,16 +1668,107 @@ private static JsonSchema parseSchema(McpJsonMapper jsonMapper, String schema) {
16681668 }
16691669 }
16701670
1671- /**
1672- * Metadata about a task.
1673- * */
1674- @ JsonInclude (JsonInclude .Include .NON_ABSENT )
1675- @ JsonIgnoreProperties (ignoreUnknown = true )
1676- public record TaskMetaData (@ JsonProperty ("ttl" ) long ttl ,
1677- @ JsonProperty ("extensions" ) Object extensions ,
1678- @ JsonProperty ("bizContext" ) Object bizContext ) {
1671+ /**
1672+ * Metadata about a task.
1673+ */
1674+ @ JsonInclude (JsonInclude .Include .NON_ABSENT )
1675+ @ JsonIgnoreProperties (ignoreUnknown = true )
1676+ public record TaskMetaData (@ JsonProperty ("ttl" ) long ttl , @ JsonProperty ("extensions" ) Object extensions ,
1677+ @ JsonProperty ("bizContext" ) Object bizContext ) {
1678+
1679+ public TaskMetaData (long ttl ) {
1680+ this (ttl , null , null );
1681+ }
1682+ }
1683+
1684+ /**
1685+ * The server's response to a tools/call request from the client when invoked as a
1686+ * task.
1687+ */
1688+ @ JsonInclude (JsonInclude .Include .NON_ABSENT )
1689+ @ JsonIgnoreProperties (ignoreUnknown = true )
1690+ public record Task ( //@formatter:off
1691+ @ JsonProperty ("taskId" ) String taskId ,
1692+ @ JsonProperty ("status" ) String status ,
1693+ @ JsonProperty ("statusMessage" ) String statusMessage ,
1694+ @ JsonProperty ("createdAt" ) String createdAt ,
1695+ @ JsonProperty ("ttl" ) long ttl ,
1696+ @ JsonProperty ("pollInterval" ) long pollInterval ,
1697+ @ JsonProperty ("extensions" ) Object extensions ,
1698+ @ JsonProperty ("bizContext" ) Object bizContext ) { // @formatter:on
1699+
1700+ public Task (String taskId , String status , String statusMessage , String createdAt , long ttl ) {
1701+ this (taskId , status , statusMessage , createdAt , ttl , 0L , null , null );
1702+ }
1703+
1704+ public static Builder builder () {
1705+ return new Builder ();
1706+ }
1707+
1708+ public static class Builder {
1709+
1710+ private String taskId ;
1711+
1712+ private String status ;
1713+
1714+ private String statusMessage ;
1715+
1716+ private String createdAt ;
1717+
1718+ private long ttl ;
1719+
1720+ private long pollInterval ;
1721+
1722+ private Object extensions ;
1723+
1724+ private Object bizContext ;
1725+
1726+ public Builder taskId (String taskId ) {
1727+ this .taskId = taskId ;
1728+ return this ;
1729+ }
1730+
1731+ public Builder status (String status ) {
1732+ this .status = status ;
1733+ return this ;
1734+ }
1735+
1736+ public Builder statusMessage (String statusMessage ) {
1737+ this .statusMessage = statusMessage ;
1738+ return this ;
1739+ }
1740+
1741+ public Builder createdAt (String createdAt ) {
1742+ this .createdAt = createdAt ;
1743+ return this ;
1744+ }
1745+
1746+ public Builder ttl (long ttl ) {
1747+ this .ttl = ttl ;
1748+ return this ;
1749+ }
1750+
1751+ public Builder pollInterval (long pollInterval ) {
1752+ this .pollInterval = pollInterval ;
1753+ return this ;
1754+ }
1755+
1756+ public Builder extensions (Object extensions ) {
1757+ this .extensions = extensions ;
1758+ return this ;
1759+ }
16791760
1680- }
1761+ public Builder bizContext (Object bizContext ) {
1762+ this .bizContext = bizContext ;
1763+ return this ;
1764+ }
1765+
1766+ public Task build () {
1767+ return new Task (taskId , status , statusMessage , createdAt , ttl , pollInterval , extensions , bizContext );
1768+ }
1769+
1770+ }
1771+ }
16811772
16821773 /**
16831774 * Used by the client to call a tool provided by the server.
@@ -1724,7 +1815,7 @@ public static class Builder {
17241815
17251816 private Map <String , Object > arguments ;
17261817
1727- private TaskMetaData task ;
1818+ private TaskMetaData task ;
17281819
17291820 private Map <String , Object > meta ;
17301821
@@ -1756,10 +1847,10 @@ public Builder progressToken(Object progressToken) {
17561847 return this ;
17571848 }
17581849
1759- public Builder task (TaskMetaData task ) {
1760- this .task = task ;
1761- return this ;
1762- }
1850+ public Builder task (TaskMetaData task ) {
1851+ this .task = task ;
1852+ return this ;
1853+ }
17631854
17641855 public CallToolRequest build () {
17651856 Assert .hasText (name , "name must not be empty" );
@@ -1815,22 +1906,23 @@ public record CallToolResult( // @formatter:off
18151906 @ JsonProperty ("content" ) List <Content > content ,
18161907 @ JsonProperty ("isError" ) Boolean isError ,
18171908 @ JsonProperty ("structuredContent" ) Object structuredContent ,
1909+ @ JsonProperty ("task" ) Task task ,
18181910 @ JsonProperty ("_meta" ) Map <String , Object > meta ) implements Result { // @formatter:on
18191911
18201912 /**
18211913 * @deprecated use the builder instead.
18221914 */
18231915 @ Deprecated
18241916 public CallToolResult (List <Content > content , Boolean isError ) {
1825- this (content , isError , (Object ) null , null );
1917+ this (content , isError , (Object ) null , null , null );
18261918 }
18271919
18281920 /**
18291921 * @deprecated use the builder instead.
18301922 */
18311923 @ Deprecated
18321924 public CallToolResult (List <Content > content , Boolean isError , Map <String , Object > structuredContent ) {
1833- this (content , isError , structuredContent , null );
1925+ this (content , isError , structuredContent , null , null );
18341926 }
18351927
18361928 /**
@@ -1846,6 +1938,23 @@ public CallToolResult(String content, Boolean isError) {
18461938 this (List .of (new TextContent (content )), isError , null );
18471939 }
18481940
1941+ /**
1942+ * Create a new instance of {@link CallToolResult} with a task.
1943+ * @param task The task metadata.
1944+ */
1945+ public CallToolResult (Task task ) {
1946+ this (null , false , null , task , null );
1947+ }
1948+
1949+ /**
1950+ * Create a new instance of {@link CallToolResult} with a task.
1951+ * @param task The task metadata.
1952+ * @param meta Optional metadata about the result.
1953+ */
1954+ public CallToolResult (Task task , Map <String , Object > meta ) {
1955+ this (null , false , null , task , meta );
1956+ }
1957+
18491958 /**
18501959 * Creates a builder for {@link CallToolResult}.
18511960 * @return a new builder instance
@@ -1865,6 +1974,8 @@ public static class Builder {
18651974
18661975 private Object structuredContent ;
18671976
1977+ private Task task ;
1978+
18681979 private Map <String , Object > meta ;
18691980
18701981 /**
@@ -1951,12 +2062,17 @@ public Builder meta(Map<String, Object> meta) {
19512062 return this ;
19522063 }
19532064
2065+ public Builder task (Task task ) {
2066+ this .task = task ;
2067+ return this ;
2068+ }
2069+
19542070 /**
19552071 * Builds a new {@link CallToolResult} instance.
19562072 * @return a new CallToolResult instance
19572073 */
19582074 public CallToolResult build () {
1959- return new CallToolResult (content , isError , (Object ) structuredContent , meta );
2075+ return new CallToolResult (content , isError , (Object ) structuredContent , task , meta );
19602076 }
19612077
19622078 }
0 commit comments