Priyanshu Jain
05/31/2025, 7:10 AMPriyanshu Jain
05/31/2025, 7:24 AMexample/mcp/PlaywrightMcpClient.kt
, I tried setting up a similar toolsRegistry but instead of launching the Process locally, I tried to connect with a hosted MCP Server.
Here's my ViewModel code:
class MainViewModel : ViewModel() {
private val _uiState = MutableStateFlow(ChatScreenUiState())
val uiState = _uiState.asStateFlow()
private val systemMessage = """
You are Beacon, an AI companion.
"""
private val promptExecutor = simpleOllamaAIExecutor(baseUrl = "<http://10.0.2.2:11434>")
private var history = prompt("history", LLMParams()) { system(systemMessage) }
private fun runQuery() {
viewModelScope.launch {
val toolsRegistry = McpToolRegistryProvider.fromTransport(
transport = McpToolRegistryProvider.defaultSseTransport("<https://mcp.kite.trade>")
)
val response = promptExecutor.execute(
prompt = history,
model = OllamaModels.Meta.LLAMA_3_2,
tools = toolsRegistry.tools.map { it.descriptor }
)
val agentMessage = ChatMessage(
id = UUID.randomUUID().toString(),
text = response[0].content,
senderType = SenderType.BOT
)
history = prompt(history) {
system(response[0].content)
}
_uiState.update {
it.copy(isLoading = false, messages = it.messages + agentMessage)
}
}
}
fun onAction(action: ChatScreenAction) {
when (action) {
is ChatScreenAction.OnMessageInput -> {
_uiState.update { it.copy(currentMessage = action.inputMessage) }
}
is ChatScreenAction.SendMessage -> {
history = prompt(history) {
user(action.message)
}
val chatMessage = ChatMessage(
id = UUID.randomUUID().toString(),
text = action.message,
senderType = SenderType.USER
)
_uiState.update {
it.copy(isLoading = true, messages = it.messages + chatMessage)
}
runQuery()
}
}
}
}
The app crashed when sending the first message with this log:
FATAL EXCEPTION: main (Ask Gemini)
Process: <http://com.example.app|com.example.app>, PID: 15682
java.lang.IllegalStateException: Error connecting to transport: Server's protocol version is not supported: 2025-03-26
at io.modelcontextprotocol.kotlin.sdk.client.Client.connect$suspendImpl(Client.kt:105)
at io.modelcontextprotocol.kotlin.sdk.client.Client$connect$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8705)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@dc9d687, Dispatchers.Main.immediate]
To get more details, I created a custom SSE transport instance with logging enabled and this is what I got:
HTTP Client: REQUEST: <https://mcp.kite.trade/sse>
METHOD: HttpMethod(value=GET)
COMMON HEADERS
-> Accept: */*
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 0
-> Accept: text/event-stream
-> Cache-Control: no-store
BODY Content-Type: null
BODY START
BODY END
HTTP Client: RESPONSE: 200 OK
METHOD: HttpMethod(value=GET)
FROM: <https://mcp.kite.trade/sse>
COMMON HEADERS
-> CF-RAY: <>
-> Cache-Control: no-cache
-> Connection: keep-alive
-> Content-Type: text/event-stream
-> Date: Sat, 31 May 2025 07:07:51 GMT
-> Server: cloudflare
-> Set-Cookie: <set-cookie-data>
-> Strict-Transport-Security: max-age=15552000; includeSubDomains
-> Transfer-Encoding: chunked
-> access-control-allow-origin: *
-> alt-svc: h3=":443"; ma=86400
-> cf-cache-status: DYNAMIC
BODY Content-Type: text/event-stream
BODY START
BODY END
HTTP Client: REQUEST: <https://mcp.kite.trade/message?sessionId=><session-id>
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: */*
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 227
-> Content-Type: application/json
BODY Content-Type: application/json
BODY START
{"id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"experimental":{},"sampling":{}},"clientInfo":{"name":"mcp-client-cli","version":"1.0.0"},"_meta":{},"method":"initialize"},"jsonrpc":"2.0"}
BODY END
app_time_stats: avg=1.63ms min=0.79ms max=4.16ms count=61
HTTP Client: RESPONSE: 202 Accepted
METHOD: HttpMethod(value=POST)
FROM: <https://mcp.kite.trade/message?sessionId=><session-id>
COMMON HEADERS
-> CF-RAY: <>
-> Connection: keep-alive
-> Content-Length: 0
-> Date: Sat, 31 May 2025 07:07:51 GMT
-> Server: cloudflare
-> Set-Cookie:<set-cookie-data>
-> Strict-Transport-Security: max-age=15552000; includeSubDomains
-> alt-svc: h3=":443"; ma=86400
-> cf-cache-status: DYNAMIC
BODY Content-Type: null
BODY START
BODY END
And then, it fails with the exception detailed above.Vadim Briliantov
05/31/2025, 10:59 AMMaria Tigina
06/02/2025, 9:28 AMPriyanshu Jain
06/05/2025, 11:28 AM