memos/server/router/mcp
Johnny 803d488a5f feat(mcp): refactor MCP server to standard protocol structure
- Replace PAT-only auth with optional auth supporting both PAT and JWT
  via auth.Authenticator.Authenticate(); unauthenticated requests see
  only public memos, matching REST API visibility semantics
- Inline auth middleware into mcp.go following fileserver pattern;
  remove auth_middleware.go
- Introduce memoJSON response type that correctly serialises store.Memo
  (including Payload.Tags and Payload.Property) without proto marshalling
- Add tools: list_memo_comments, create_memo_comment, list_tags
- Extend list_memos with state (NORMAL/ARCHIVED), order_by_pinned, and
  page parameters
- Extend update_memo with pinned and state parameters
- Extract #tags from content on create/update via regex to pre-populate
  Payload.Tags without requiring a full markdown service rebuild
- Add MCP Resources: memo://memos/{uid} template returns memo as
  Markdown with YAML frontmatter, allowing clients to read memos by URI
- Add MCP Prompts: capture (save a thought) and review (search + summarise)
2026-03-01 23:10:23 +08:00
..
README.md feat: add MCP server with PAT authentication 2026-02-24 22:54:51 +08:00
mcp.go feat(mcp): refactor MCP server to standard protocol structure 2026-03-01 23:10:23 +08:00
prompts.go feat(mcp): refactor MCP server to standard protocol structure 2026-03-01 23:10:23 +08:00
resources_memo.go feat(mcp): refactor MCP server to standard protocol structure 2026-03-01 23:10:23 +08:00
tools_memo.go feat(mcp): refactor MCP server to standard protocol structure 2026-03-01 23:10:23 +08:00
tools_tag.go feat(mcp): refactor MCP server to standard protocol structure 2026-03-01 23:10:23 +08:00

README.md

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)

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

Authentication

Every request must include a Personal Access Token (PAT):

Authorization: Bearer <your-PAT>

PATs are long-lived tokens created in Settings → My Account → Access Tokens. Short-lived JWT session tokens are not accepted. Requests without a valid PAT receive HTTP 401.

Tools

All tools are scoped to the authenticated user's memos.

Tool Description Required params Optional params
list_memos List memos page_size (int, max 100), filter (CEL expression)
get_memo Get a single memo name
search_memos Full-text search query
create_memo Create a memo content visibility
update_memo Update content or visibility name content, visibility
delete_memo Delete a memo name

name is the memo resource name, e.g. memos/abc123.

visibility accepts PRIVATE (default), PROTECTED, or PUBLIC.

filter accepts CEL expressions supported by the memo filter engine, e.g.:

  • content.contains("keyword")
  • visibility == "PUBLIC"
  • has_task_list

Connecting Claude Code

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:

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

Package Structure

File Responsibility
mcp.go MCPService struct, constructor, route registration
auth_middleware.go Echo middleware — validates Bearer token, sets user ID in context
tools_memo.go Tool registration and six memo tool handlers