Skip to content

Add optional Streamable HTTP MCP support to znserver #56

Closed

Description

@lewxdev

Problem

I self-host ZenNotes with Docker Compose and connect its MCP tools through OpenAI’s tunnel-client.

Currently, my tunnel container needs a custom image that extends ghcr.io/openai/tunnel-client, downloads a pinned zn release, and runs zn mcp against the ZenNotes server API. This works, but requires maintaining a custom build and a separate CLI version alongside the server.

Related to my Docker deployment feedback in #49, it would be helpful if the official server could also provide MCP directly.

Proposal

Would you consider adding an optional authenticated Streamable HTTP MCP endpoint to znserver?

Ideally, it would:

  • Be disabled by default and enabled through configuration.
  • Use the server’s existing bearer-token authentication.
  • Expose the existing MCP tools against the server’s active vault.
  • Keep tool names and schemas consistent with zn mcp.

For illustration, the configuration could look like this; the ZenNotes flag and endpoint are proposed names:

services:
  zennotes:
    image: adibhanna/zennotes:<release-with-mcp>
    environment:
      - ZENNOTES_AUTH_TOKEN=${ZENNOTES_AUTH_TOKEN:?}
      - ZENNOTES_MCP_ENABLED=1
    volumes:
      - /data/zennotes/vault:/workspace
      - /data/zennotes/data:/data

  zennotes-mcp:
    image: ghcr.io/openai/tunnel-client:v0.0.18
    environment:
      - CONTROL_PLANE_API_KEY=${CONTROL_PLANE_API_KEY:?}
      - CONTROL_PLANE_TUNNEL_ID=${CONTROL_PLANE_TUNNEL_ID:?}
      - MCP_SERVER_URL=http://zennotes:7878/mcp
      - MCP_EXTRA_HEADERS=Authorization: Bearer ${ZENNOTES_AUTH_TOKEN:?}

This would let me keep the tunnel as a separate, stock container while removing the custom image build and CLI download. It would also support other HTTP-capable MCP clients.

Open to alternative approaches that provide the same deployment simplicity.

Activity

  1. lewxdev commented on Oct 30, 2026

    @lewxdev
    Author

    One related requirement I missed in the original proposal: the scoped MCP access from my issue ZenNotes/tui#21, now shipped in zn 0.13.0.

    The HTTP endpoint should support the same policy as the existing launch flags:

    • Repeated --allow-path and --deny-path restrictions.
    • --read-only / --access read|comment|write.
    • The same enforcement across tool discovery and execution, listings, search, references, assets, comments, and errors, including the existing fail-closed behavior.

    With stdio these are configured in the zn mcp command. With a stock tunnel-client connecting to HTTP, there is no zn launch command to attach them to. How would you prefer to expose these and other MCP-specific options in znserver?

    Two possible approaches:

    1. One configured scope for the MCP endpoint, supplied through server configuration/environment. This would cover a single-agent deployment without any custom tunnel image.
    2. Named scopes/profiles bound to separate MCP credentials, so multiple agents can use the same server with different permissions. This could align with the planned per-vault profiles described in the scoped-access design, rather than introducing a separate policy format. I understand profiles have not shipped yet.

    The second approach would be particularly useful: for example, one agent could read only Projects, while another can comment on a different folder. The credential should determine the allowed profile; a caller-supplied profile name or tool argument should never widen access. Any endpoint-wide restrictions and profile restrictions could combine by intersection, as in the existing design.

    This also qualifies my original suggestion to reuse the server's existing bearer token. If that token still grants unrestricted REST API access, it should not be handed to a restricted agent as its credential. A dedicated MCP credential should be limited to its configured scope and should not authenticate unrestricted API requests.

    My preference would be to preserve the current scope semantics and shared contract tests across stdio and HTTP, while leaving the exact configuration surface open. The tunnel container would only need the endpoint URL and appropriate credential; ZenNotes would own the MCP policy and other server options.

  2. adibhanna commented on Nov 4, 2026

    @adibhanna
    Contributor

    Thank you for this, and for the follow-up comment. The point about not handing a restricted agent the server's unrestricted token shaped the whole design.

    I'd like to build this into znserver, as you proposed, off by default. Here's how it would look:

    services:
      zennotes:
        image: adibhanna/zennotes:<release-with-mcp>
        environment:
          - ZENNOTES_AUTH_TOKEN=${ZENNOTES_AUTH_TOKEN:?}
          - ZENNOTES_VAULT_PATH=/workspace
          - ZENNOTES_MCP_ENABLED=1
          - ZENNOTES_MCP_TOKEN=${ZENNOTES_MCP_TOKEN:?}
          - ZENNOTES_MCP_ACCESS=read
          - 'ZENNOTES_MCP_ALLOW_PATHS=["Projects"]'
        volumes:
          - /data/zennotes/vault:/workspace
          - /data/zennotes/data:/data
    
      zennotes-mcp:
        image: ghcr.io/openai/tunnel-client:v0.0.19
        environment:
          - CONTROL_PLANE_API_KEY=${CONTROL_PLANE_API_KEY:?}
          - CONTROL_PLANE_TUNNEL_ID=${CONTROL_PLANE_TUNNEL_ID:?}
          - MCP_SERVER_URL=http://zennotes:7878/mcp
          - "MCP_EXTRA_HEADERS=Authorization: Bearer ${ZENNOTES_MCP_TOKEN:?}"

    (The quotes on that last line matter. Without them, the : makes it invalid YAML.)

    On what you asked for:

    • No custom image or separate zn version. The server carries the tools, so there's one image to pin.
    • The same scope code. It's the code behind zn mcp, not a copy, with the shared contract tests run through /mcp as well.
    • A dedicated credential. An MCP token only works on /mcp, and the server's token and browser logins don't work there at all. In my testing, an MCP token got a 401 on the REST API.
    • Both of your options. The environment variables above cover one scope. A credentials file binds several tokens to their own scopes, and the token alone decides which scope applies. Nothing a caller sends can widen it. Named profiles can plug into that file once they ship.

    Two limits you should know about, both the same as your setup today, since zn mcp goes through the server API now:

    • An assistant restricted to certain paths can't rename notes yet, because the server rewrites links in every note, including ones it can't see.
    • Edits made over MCP won't appear in agent edit review yet.

    And one difference from your proposal: because each request is stateless, /mcp won't issue MCP session IDs.

    A few questions, if you have a moment:

    1. Does this cover your setup, or is anything missing?
    2. Do you need the two limits above lifted early, or can they wait?
    3. Would you be willing to try a test build with tunnel-client when it's ready? I can't test that hop from here.

    This should also cover zennotes#965, with one change from what it asks: agents would use an MCP token rather than the server's own.

  3. lewxdev commented on Nov 5, 2026

    @lewxdev
    Author

    Thanks, this covers the deployment and credential separation we were hoping for. Using the same scope implementation and running the shared contracts through /mcp sounds ideal.

    Our current setup uses zn mcp --allow-path memory with write access. The equivalent environment configuration would cover our immediate needs, and the credentials file gives us a good path toward separate scopes for different agents.

    One compatibility check for the test build: our current MCP setup can discover and read existing Markdown record pages under .base folders. We’d like to verify that those remain accessible through /mcp with the same scopes. Broader database support (including explicit support for editing record page bodies) can be tracked separately and doesn’t need to block this endpoint.

    The scoped-renaming and agent-edit-review limitations can wait for our initial adoption. Preserving the existing scope behavior, including deny paths and fail-closed handling, is the priority.

    Not issuing session IDs is fine provided the tunnel/client handshake and subsequent calls work reliably.

    I’d be happy to try a test build with the stock tunnel-client image and report back. We can test in an isolated, disposable Docker Compose stack and/or against a copy of our actual vault data to validate our use case. A linux/arm64 test image would be useful. We can check authentication, scope isolation, database record-page access, and recovery after restarting the test services.

  4. lewxdev commented on Nov 5, 2026

    @lewxdev
    Author

    I tried the HTTP MCP setup with adibhanna/zennotes:2.83.0 and ghcr.io/openai/tunnel-client:v0.0.19, using the dedicated MCP token and MCP_SERVER_URL=http://zennotes:7878/mcp. The tunnel stays unhealthy and repeatedly logs:

    WARN OAuth discovery failed; retrying component=oauth error="oauth discovery invalid metadata from http://zennotes:7878: decode protected resource metadata: invalid character '<' looking for beginning of value" retry_in=30s
    

    The likely cause is the SPA fallback. Tunnel-client probes these OAuth protected-resource metadata URLs:

    • /.well-known/oauth-protected-resource/mcp
    • /.well-known/oauth-protected-resource

    In 2.83.0, unknown GET paths reach serveStatic, which serves index.html with HTTP 200. Tunnel-client interprets a successful response containing invalid metadata as retryable, so discovery never settles and startup polling/readiness remains blocked.

    This behavior is present in both tunnel-client v0.0.18 and v0.0.19, based on inspecting their tagged source; I have observed the failure with v0.0.19, rather than separately retesting v0.0.18. Downgrading the image alone therefore appears unlikely to help. Our earlier stdio setup avoided HTTP OAuth discovery entirely.

    Could ZenNotes exclude the unsupported OAuth protected-resource metadata URLs, including path-specific variants, from the SPA fallback and return 404 Not Found instead? Tunnel-client explicitly treats absent metadata returning 404 as optional discovery failure and allows a plain/static-token MCP server to proceed. This should not require implementing OAuth.

    A regression test for both URLs returning 404 while ordinary browser routes retain their SPA fallback would help cover this integration case. Happy to retest the tunnel connection with a fix.

    Relevant source:

  5. lewxdev commented on Nov 6, 2026

    @lewxdev
    Author

    Follow-up: with a temporary Traefik route explicitly returning 404 for both OAuth protected-resource metadata URLs, the stock tunnel-client:v0.0.19 now becomes healthy and appears stable with ZenNotes 2.83.0.

    We’ve also verified calls through the connected integration:

    • vault_info reports write access scoped to memory.
    • Reading an existing database record page succeeds, including its Markdown body and frontmatter.

    There is an initial discovery warning about the missing metadata, but discovery settles and the tunnel proceeds normally. Read operations have been verified; editing has not yet been tested.

    This supports the proposed server-side 404 fix. The proxy route is only a temporary workaround—we’d be happy to remove it and retest direct server connectivity once the fix ships.

  6. adibhanna commented on Nov 16, 2026

    @adibhanna
    Contributor

    Thanks for tracking this down so precisely, and for testing the Traefik workaround. That made the fix easy to confirm.

    Server 2.84.1 now answers 404 for every /.well-known/ URL it has no file for, so OAuth discovery settles instead of retrying on the app page. That covers both protected-resource URLs, plus the authorization server ones (oauth-authorization-server, openid-configuration) in case a client probes those too. App routes still get the page, and it works under a base path. A regression test covers both.

    The image is multi-arch, so adibhanna/zennotes:2.84.1 has a linux/arm64 build.

    When you get a chance, could you drop the Traefik route and retest against the server directly? An edit or two through the tunnel would help as well, since only reads have been tried so far. Once that works, I'll close this issue. The scoped rename and edit review limits can get issues of their own.

  7. adibhanna commented on Nov 16, 2026

    @adibhanna
    Contributor

    Closing this now that the fix has shipped in server 2.84.1 (Docker adibhanna/zennotes:2.84.1). If your tunnel still has trouble after updating without the Traefik route, reopen this and we will look again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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