# Tencent Docs: the connector row (composer menu, QR authorization, document
# picker, `@` source) and the MCP client row the model's tools come from.
#
# One bundle carries both rows because neither half is useful alone: the
# connector authorizes and puts a document's *title* into the draft, and the MCP
# row is what lets the model act on it — `mcp__tencent-docs__*` turns that title
# back into the file ids the read tools take.
- insert:
    - id: tencent-docs-connector
      name: '@szhl/dsh-tencent-docs'

    # Official Tencent Docs MCP server (https://docs.qq.com/open/document/mcp/).
    # Configuration-only: it inserts the already-installed MCP client and no
    # plugin code of its own.
    #
    # The personal access token is read from a file rather than written here, so
    # no secret ever lands in a tracked patch, a package, or a transcript:
    #
    #   printf '%s' '<TOKEN>' > ~/.dsh/tencent-docs-token && chmod 600 ~/.dsh/tencent-docs-token
    #
    # Get one at https://docs.qq.com/open/auth/mcp.html (login required; the free
    # tier allows 2000 MCP calls a day). The connector writes the same file, so a
    # QR authorization is the normal way to fill it.
    - id: tencent-docs-mcp
      name: '@deepseek-ai/dsh-mcp-client'
      config:
        serverName: tencent-docs
        transport: streamable-http
        url: https://docs.qq.com/openapi/mcp

        # Tencent's docs are explicit that the header key must be exactly
        # `Authorization` — `token`, `auth` or `X-Token` all fail as 400006.
        #
        # Two details make this expression safe to leave in place before the
        # token exists. `!!js` is evaluated by `new Function`, so it has no
        # module scope and no reliable `require`; `process.getBuiltinModule`
        # (Node 22+) is the intended way to reach `node:fs` from there. And the
        # expression swallows a missing file, because a throw during config
        # interpolation would fail entry activation — which fails the whole Web
        # boot, and the recovery path answers that by disabling every
        # third-party bundle, not just this one.
        headers:
          Authorization: !!js (() => { try { return process.getBuiltinModule('node:fs').readFileSync(dshHomePath('tencent-docs-token'), 'utf8').trim() } catch { return '' } })()

        # Deliberately `false`, unlike the shipped template. A wrong or expired
        # token should cost the tools, never the application: with `true` a bad
        # token fails activation and takes the sidebar and balance plugins down
        # with it through the recovery path above.
        failOnStartupError: false
