Skip to content

Mark MCP chat posts with a fixed connected-app metadata key #336

Description

@HMarzban

Parent

#328. Related: #230, #344

What to build

post_chat_message posts in a heading chat as the document owner. Nothing in the stored row says a connected app wrote it. Past posts can never be marked, because no record ties a chat row to MCP.

After this change, every MCP chat post stores metadata.via = 'connected_app'. read_chat_thread reads the key back and tags those posts. So a connected app can tell its own posts from the owner's. The visible label in the pad is #344.

Acceptance criteria

  • A message posted with post_chat_message has metadata equal to {"via":"connected_app"} in public.messages.
  • The value is one fixed constant, CONNECTED_APP_VIA, in apps/hocuspocus.server/src/modules/mcp/types.ts. No client_id or app name is stored.
  • read_chat_thread shows via connected app in the head line of such a post.
  • From metadata, readThread selects only named paths, never the whole object.
  • Composer messages have no via key. The pad renders an MCP post as before.
  • After pin, unpin and a reply, metadata.via is still there.
  • apps/hocuspocus.server/API.md §MCP connector, docs/mcp/reference.md and the MCP entry under ## [Unreleased] in apps/hocuspocus.server/CHANGELOG.md each state the key in one line.

Blocked by

None — can start now.

Agent brief

Type: AFK.

  1. postMessage in apps/hocuspocus.server/src/modules/mcp/infra/chatStore.ts adds metadata: { via: CONNECTED_APP_VIA }. The store owns the constant, so no tool can pass another value.
  2. readThread adds the path via:metadata->>via. ChatMessage gets a viaConnectedApp flag. renderChatMessage adds the tag inside frameChatText.
  3. No migration and no apps/webapp/src/types/supabase.ts change: messages.metadata is an existing jsonb column. No insert trigger rewrites NEW.metadata.

Rules: apps/hocuspocus.server/CLAUDE.md §MCP Connector. AGENTS.md §Test Policy: no new test.

Verify: typecheck, bun test src/modules/mcp, lint and format. On the local stack, post with post_chat_message and check the row in Supabase Studio. Pin, unpin and reply, then call read_chat_thread.

Out of scope

Activity

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

    ChatRelated to chat featuresenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions