parent
772195b5e6
commit
be6e47391f
2 changed files with 19 additions and 22 deletions
|
|
@ -26,7 +26,7 @@ public class ClientOptions(
|
|||
* An MCP client on top of a pluggable transport.
|
||||
*
|
||||
* The client automatically performs the initialization handshake with the server when [connect] is called.
|
||||
* After initialization, [getServerCapabilities] and [getServerVersion] provide details about the connected server.
|
||||
* After initialization, [severCapabilities] and [serverVersion] provide details about the connected server.
|
||||
*
|
||||
* You can extend this class with custom request/notification/result types if needed.
|
||||
*
|
||||
|
|
@ -38,8 +38,22 @@ public open class Client(
|
|||
options: ClientOptions = ClientOptions(),
|
||||
) : Protocol(options) {
|
||||
|
||||
private var serverCapabilities: ServerCapabilities? = null
|
||||
private var serverVersion: Implementation? = null
|
||||
/**
|
||||
* Retrieves the server's reported capabilities after the initialization process completes.
|
||||
*
|
||||
* @return The server's capabilities, or `null` if initialization is not yet complete.
|
||||
*/
|
||||
public var serverCapabilities: ServerCapabilities? = null
|
||||
private set
|
||||
|
||||
/**
|
||||
* Retrieves the server's reported version information after initialization.
|
||||
*
|
||||
* @return Information about the server's implementation, or `null` if initialization is not yet complete.
|
||||
*/
|
||||
public var serverVersion: Implementation? = null
|
||||
private set
|
||||
|
||||
private val capabilities: ClientCapabilities = options.capabilities
|
||||
|
||||
protected fun assertCapability(capability: String, method: String) {
|
||||
|
|
@ -90,23 +104,6 @@ public open class Client(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the server's reported capabilities after the initialization process completes.
|
||||
*
|
||||
* @return The server's capabilities, or `null` if initialization is not yet complete.
|
||||
*/
|
||||
public fun getServerCapabilities(): ServerCapabilities? {
|
||||
return serverCapabilities
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the server's reported version information after initialization.
|
||||
*
|
||||
* @return Information about the server's implementation, or `null` if initialization is not yet complete.
|
||||
*/
|
||||
public fun getServerVersion(): Implementation? {
|
||||
return serverVersion
|
||||
}
|
||||
|
||||
override fun assertCapabilityForMethod(method: Method) {
|
||||
when (method) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class ClientTest {
|
|||
client.connect(clientTransport)
|
||||
assertEquals(
|
||||
Implementation("test", "1.0"),
|
||||
client.getServerVersion()
|
||||
client.serverVersion
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ class ClientTest {
|
|||
).joinAll()
|
||||
|
||||
// Server supports resources and tools, but not prompts
|
||||
val caps = client.getServerCapabilities()
|
||||
val caps = client.serverCapabilities
|
||||
assertEquals(ServerCapabilities.Resources(null, null), caps?.resources)
|
||||
assertEquals(ServerCapabilities.Tools(null), caps?.tools)
|
||||
assertTrue(caps?.prompts == null) // or check that prompts are absent
|
||||
|
|
|
|||
Loading…
Reference in a new issue