Back to Memos

MCP Server

server/router/mcp/README.md

0.28.05.9 KB
Original Source

MCP Server

This package implements a Model Context Protocol (MCP) server embedded in the Memos HTTP process. It exposes memo operations as MCP tools, making Memos accessible to any MCP-compatible AI client (Claude Desktop, Cursor, Zed, etc.).

Endpoint

POST /mcp   (tool calls, initialize)
GET  /mcp   (optional SSE stream for server-to-client messages)
DELETE /mcp (optional session termination)

Transport: Streamable HTTP (single endpoint, MCP spec 2025-03-26).

Tool Filtering

The default /mcp endpoint exposes all tools. Clients can opt into a smaller tool surface with GitHub-style headers or route aliases:

ControlDescription
X-MCP-Readonly: trueHide and block mutating tools
X-MCP-Toolsets: memos,tags,attachments,relations,reactionsLimit the default tool list to selected toolsets
X-MCP-Tools: list_tags,get_memoAdd specific tools to the selected toolset list
X-MCP-Exclude-Tools: delete_memoRemove specific tools

Equivalent aliases:

text
/mcp/readonly
/mcp/x/{toolsets}
/mcp/x/{toolsets}/readonly

Examples:

text
/mcp/x/memos,tags/readonly
X-MCP-Toolsets: memos
X-MCP-Tools: list_tags
X-MCP-Exclude-Tools: delete_memo

Capabilities

The server advertises the following MCP capabilities:

CapabilityEnabledDetails
ToolsYesList changed notifications supported
ResourcesYesSubscribe + list changed supported
PromptsYesList changed notifications supported
LoggingYesStructured log events

Authentication

Public reads can be used without authentication. Personal Access Tokens (PATs) or short-lived JWT session tokens are required for:

  • Reading non-public memos or attachments
  • Any tool that mutates data

When authenticating, send a Bearer token:

Authorization: Bearer <your-PAT>

PATs are long-lived tokens created in Settings → My Account → Access Tokens. Short-lived JWT session tokens are also accepted. Requests with an invalid token receive HTTP 401.

Origin Validation

For Streamable HTTP safety, requests with an Origin header must be same-origin with the current request host or match the configured instance-url. Requests without an Origin header, such as desktop MCP clients and CLI tools, are allowed.

Tools

Memo Tools

ToolDescriptionRequired paramsOptional params
list_memosList memospage_size, page, state, order_by_pinned, filter (supported subset of standard CEL syntax)
get_memoGet a single memoname
search_memosFull-text searchquery
create_memoCreate a memocontentvisibility
update_memoUpdate a memonamecontent, visibility, pinned, state
delete_memoDelete a memoname
list_memo_commentsList commentsname
create_memo_commentAdd a commentname, content

Tag Tools

ToolDescriptionRequired params
list_tagsList all tags with counts

Attachment Tools

ToolDescriptionRequired paramsOptional params
list_attachmentsList user's attachmentspage_size, page, memo
get_attachmentGet attachment metadataname
delete_attachmentDelete an attachmentname
link_attachment_to_memoLink attachment to a memo you ownname, memo

Relation Tools

ToolDescriptionRequired paramsOptional params
list_memo_relationsList relations (refs + comments)nametype
create_memo_relationCreate a reference relation from a memo you own to a memo you can readname, related_memo
delete_memo_relationDelete a reference relation from a memo you ownname, related_memo

Reaction Tools

ToolDescriptionRequired params
list_reactionsList reactions on a memoname
upsert_reactionAdd a reaction emojiname, reaction_type
delete_reactionRemove a reactionid

Resources

URI TemplateDescriptionMIME Type
memo://memos/{uid}Memo content with YAML frontmattertext/markdown

Prompts

PromptDescriptionArguments
captureQuick-save a thought as a memocontent (required), tags, visibility
reviewSearch and summarize memos on a topictopic (required)
daily_digestSummarize recent memo activitydays
organizeSuggest tags/relations for unorganized memosscope

Resource Names

  • Memos: memos/<uid> (e.g. memos/abc123)
  • Attachments: attachments/<uid> (e.g. attachments/def456)

Connecting Claude Code

bash
claude mcp add --transport http memos http://localhost:5230/mcp \
  --header "Authorization: Bearer <your-PAT>"

Use --scope user to make it available across all projects:

bash
claude mcp add --scope user --transport http memos http://localhost:5230/mcp \
  --header "Authorization: Bearer <your-PAT>"

Package Structure

FileResponsibility
mcp.goMCPService struct, constructor, route registration, auth middleware, tool filtering
tool_metadata.goToolsets, read-only metadata, annotations, structured result helpers
api_helpers.goConversion helpers for calling API service methods from MCP tools
tools_memo.goMemo CRUD tools + helpers (JSON types, visibility/access checks)
tools_tag.goTag listing tool
tools_attachment.goAttachment listing, metadata, deletion, linking tools
tools_relation.goMemo relation (reference) tools
tools_reaction.goReaction (emoji) tools
resources_memo.goMemo resource template handler
prompts.goPrompt handlers (capture, review, daily_digest, organize)