Skip to content

Commit 8f93dd8

Browse files
committed
Deprecate _meta in favor of meta, add alternative constructors in prompts.
1 parent 2169dc4 commit 8f93dd8

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed
Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.modelcontextprotocol.kotlin.sdk.shared
22

33
import io.modelcontextprotocol.kotlin.sdk.types.JSONRPCMessage
4-
import kotlinx.coroutines.CompletableDeferred
54

65
/**
76
* Describes the minimal contract for MCP transport that a client or server can communicate over.
@@ -47,53 +46,3 @@ public interface Transport {
4746
*/
4847
public fun onMessage(block: suspend (JSONRPCMessage) -> Unit)
4948
}
50-
51-
/**
52-
* Implements [onClose], [onError] and [onMessage] functions of [Transport] providing
53-
* corresponding [_onClose], [_onError] and [_onMessage] properties to use for an implementation.
54-
*/
55-
@Suppress("PropertyName")
56-
public abstract class AbstractTransport : Transport {
57-
protected var _onClose: (() -> Unit) = {}
58-
private set
59-
protected var _onError: ((Throwable) -> Unit) = {}
60-
private set
61-
62-
// to not skip messages
63-
private val _onMessageInitialized = CompletableDeferred<Unit>()
64-
protected var _onMessage: (suspend ((JSONRPCMessage) -> Unit)) = {
65-
_onMessageInitialized.await()
66-
_onMessage.invoke(it)
67-
}
68-
private set
69-
70-
override fun onClose(block: () -> Unit) {
71-
val old = _onClose
72-
_onClose = {
73-
old()
74-
block()
75-
}
76-
}
77-
78-
override fun onError(block: (Throwable) -> Unit) {
79-
val old = _onError
80-
_onError = { e ->
81-
old(e)
82-
block(e)
83-
}
84-
}
85-
86-
override fun onMessage(block: suspend (JSONRPCMessage) -> Unit) {
87-
val old: suspend (JSONRPCMessage) -> Unit = when (_onMessageInitialized.isCompleted) {
88-
true -> _onMessage
89-
false -> { _ -> }
90-
}
91-
92-
_onMessage = { message ->
93-
old(message)
94-
block(message)
95-
}
96-
97-
_onMessageInitialized.complete(Unit)
98-
}
99-
}

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/prompts.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ public data class GetPromptRequest(override val params: GetPromptRequestParams)
113113
@EncodeDefault
114114
override val method: Method = Method.Defined.PromptsGet
115115

116+
@Deprecated(
117+
message = "Use constructor with GetPromptRequestParams instead",
118+
replaceWith = ReplaceWith("GetPromptRequest(GetPromptRequestParams(name, arguments, meta))"),
119+
)
120+
public constructor(
121+
name: String,
122+
arguments: Map<String, String>? = null,
123+
meta: RequestMeta? = null,
124+
) : this(
125+
GetPromptRequestParams(
126+
name = name,
127+
arguments = arguments,
128+
meta = meta,
129+
),
130+
)
131+
116132
/**
117133
* The name of the prompt or prompt template to retrieve.
118134
*/
@@ -221,4 +237,13 @@ public data class ListPromptsResult(
221237
@SerialName("_meta")
222238
override val meta: JsonObject? = null,
223239
) : ServerResult,
224-
PaginatedResult
240+
PaginatedResult {
241+
242+
@Deprecated(
243+
message = "Use 'meta' instead.",
244+
replaceWith = ReplaceWith("meta"),
245+
)
246+
@Suppress("PropertyName", "VariableNaming")
247+
public val _meta: JsonObject?
248+
get() = meta
249+
}

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/resources.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ public data class ListResourcesResult(
223223
@SerialName("_meta")
224224
override val meta: JsonObject? = null,
225225
) : ServerResult,
226-
PaginatedResult
226+
PaginatedResult {
227+
228+
@Deprecated(
229+
message = "Use 'meta' instead.",
230+
replaceWith = ReplaceWith("meta"),
231+
)
232+
@Suppress("PropertyName", "VariableNaming")
233+
public val _meta: JsonObject?
234+
get() = meta
235+
}
227236

228237
// ============================================================================
229238
// resources/read
@@ -433,4 +442,13 @@ public data class ListResourceTemplatesResult(
433442
@SerialName("_meta")
434443
override val meta: JsonObject? = null,
435444
) : ServerResult,
436-
PaginatedResult
445+
PaginatedResult {
446+
447+
@Deprecated(
448+
message = "Use 'meta' instead.",
449+
replaceWith = ReplaceWith("meta"),
450+
)
451+
@Suppress("PropertyName", "VariableNaming")
452+
public val _meta: JsonObject?
453+
get() = meta
454+
}

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/tools.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,13 @@ public data class ListToolsResult(
259259
@SerialName("_meta")
260260
override val meta: JsonObject? = null,
261261
) : ServerResult,
262-
PaginatedResult
262+
PaginatedResult {
263+
264+
@Deprecated(
265+
message = "Use 'meta' instead.",
266+
replaceWith = ReplaceWith("meta"),
267+
)
268+
@Suppress("PropertyName", "VariableNaming")
269+
public val _meta: JsonObject?
270+
get() = meta
271+
}

0 commit comments

Comments
 (0)