Skip to content

Use mcp tool from "dashscope.aliyuncs.com" #1370

@1006245347

Description

@1006245347
//"https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse"


bailian_web_search
搜索可用于查询百科知识、时事新闻、天气等信息
query
(string)
*
user query in the format of string
count
(integer)
number of search results

suspend fun searchSSE3(): ToolRegistry {
        val mcpKey = getCacheString(DATA_MCP_KEY)
        //1.构建mcpClient,可以用默认的
        val client = createKtorHttpClient(15000, builder = {
            //放这里没用
        })
        //2.mcp工具的sse接口
        val transport: SseClientTransport = SseClientTransport(
            client = client,
            urlString = null
        ) {
            headers { append(HttpHeaders.Authorization, "Bearer $mcpKey") }
            url {
                protocol = URLProtocol.HTTPS
                host = "dashscope.aliyuncs.com"
                encodedPath = "/api/v1/mcps/WebSearch/sse"
            }

        }

        val toolRegistry =
            McpToolRegistryProvider.fromTransport(transport, name = "Search from internet")
        toolRegistry.tools.forEach {
            printD(it.name + ":" + it.descriptor, "tool>")
        }
        return toolRegistry
    }

log>>>
REQUEST: https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse?sessionId=9eabe6c3073749158b32a9256db120b5
METHOD: POST
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
-> Authorization: Bearer sk-xxxxxx
CONTENT HEADERS
-> Content-Length: 202
-> Content-Type: application/json
BODY Content-Type: application/json
BODY START
{"id":"24588e059c6345358a5481da592fd83a","method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"Search from internet","version":"1.0.0"}},"jsonrpc":"2.0"}
BODY END
RESPONSE: 200 OK
METHOD: POST
FROM: https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse?sessionId=9eabe6c3073749158b32a9256db120b5
COMMON HEADERS
-> content-length: 0
-> date: Mon, 19 Jan 2026 08:45:36 GMT
-> req-arrive-time: 1768812336600
-> req-cost-time: 9
-> resp-start-time: 1768812336610
-> server: istio-envoy
-> x-envoy-upstream-service-time: 1
BODY Content-Type: null
BODY START

BODY END

something wrong , toolRegistry is null,I can' t make it.  can you help .  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions