matrix-mcp-server

matrix-mcp-server

A standalone MCP tool server that exposes Matrix chat operations as callable tools, enabling messaging, room management, user management, and ID resolution for MCP-compatible clients.

Category
访问服务器

README

@guan-tends/matrix-mcp-server

npm version License: MIT Node.js Version

A standalone MCP (Model Context Protocol) tool server that exposes Matrix chat operations as callable tools. Any MCP-compatible client — AI agents, automation pipelines, developer tools — can use these tools to send messages, manage rooms, resolve names, and interact with the Matrix protocol.

Built on @vector-im/matrix-bot-sdk with full E2EE (end-to-end encryption) support.

Features

  • 15 MCP tools — messaging, room management, user management, and intelligent ID resolution
  • E2EE support — full Megolm encryption via Rust crypto backend
  • Human-friendly name resolution — refer to rooms and users by name, not opaque IDs
  • Alias system — teach the server custom shortcuts (e.g., "eng" → "!abc123:matrix.org")
  • Standalone HTTP server — runs independently, connect any MCP client via HTTP
  • Zero-cron, zero-LLM — pure tool server. Scheduling and intelligence live in the agent layer

Install

npm install @guan-tends/matrix-mcp-server

Requirements

  • Node.js >= 22.0.0
  • A Matrix account with an access token

Quick Start

1. Clone and configure

git clone https://github.com/guan-tends/matrix-mcp-server.git
cd matrix-mcp-server
npm install
cp config.example.json5 config.json5

Edit config.json5 with your Matrix credentials:

{
  homeserverUrl: "https://matrix.org",
  accessToken: "syt_...",
  serverName: "matrix.org",
  port: 3456,
  host: "0.0.0.0",
  storePath: "./data/store.json",
  cryptoPath: "./data/crypto",
}

2. Run

npm start

The server listens on http://0.0.0.0:3456 and accepts MCP protocol requests over HTTP.

3. Connect your MCP client

Point any MCP-compatible client at the server:

{
  "mcpServers": {
    "matrix": {
      "url": "http://localhost:3456"
    }
  }
}

Or use with @guan-tends/mcp-ai aggregator for multi-server tool composition.

Configuration

File-based

Edit config.json5 (see config.example.json5 for all options).

Environment variables

All config values can be set via environment variables (highest precedence):

Variable Config Key
MATRIX_MCP_HOMESERVER_URL homeserverUrl
MATRIX_MCP_ACCESS_TOKEN accessToken
MATRIX_MCP_PORT port
MATRIX_MCP_HOST host
MATRIX_MCP_SERVER_NAME serverName
MATRIX_MCP_STORE_PATH storePath
MATRIX_MCP_CRYPTO_PATH cryptoPath

Tools (15)

Messaging

Tool Description
send_message Send text to a room (by ID or resolved name)
send_html_message Send HTML-formatted message
send_reaction React to a message with emoji
send_dm Send a direct message (creates encrypted DM if needed)

Room Management

Tool Description
join_room Join a room by ID or alias
leave_room Leave a room
get_joined_rooms List all joined rooms
get_room_messages Get recent messages from a room

User Management

Tool Description
get_presence Get presence status for a user
invite_user Invite a user to a room
kick_user Kick a user from a room

ID Resolution

Tool Description
set_room_alias Teach the server a room alias (e.g., "eng" → "!abc:matrix.org")
set_user_alias Teach the server a user alias (e.g., "alice" → "@alice:matrix.org")
resolve_room Resolve a room name to its Matrix ID with confidence score
resolve_user Resolve a user name to their Matrix ID with confidence score

Resolution Strategy

The resolver uses a hybrid approach with confidence scoring:

  1. User aliases (confidence: 1.0) — User-defined mappings
  2. Exact match (confidence: 0.9) — Exact display name or canonical alias
  3. Partial match (confidence: 0.7) — Partial name match
  4. Ambiguity (confidence: 0.5) — Multiple matches, returns candidates

Architecture

                    ┌─────────────────────────┐
                    │      index.js            │
                    │   (composition root)     │
                    └──────────┬──────────────┘
                               │ wires
              ┌────────────────┼────────────────┐
              ▼                ▼                 ▼
     ┌──────────────┐  ┌──────────────┐  ┌──────────────┐
     │ MatrixClient │  │  AliasStore  │  │ McpDataStore │
     │ (bot-sdk)    │  │ (aliases)    │  │ (DM cache)   │
     └──────┬───────┘  └──────┬───────┘  └──────┬───────┘
            │                 │                  │
            └────────┬────────┘                  │
                     ▼                           │
            ┌──────────────────┐                 │
            │ MatrixIdResolver  │◄────────────────┘
            └────────┬─────────┘
                     │
                     ▼
            ┌──────────────────┐
            │   mcp-server.js   │── MCP SDK SimpleServer
            │   (15 tools)      │── HTTP transport
            └──────────────────┘

Composition-Root IoC: index.js wires all dependencies. No module imports another's deps. Each module is independently testable.

Design Decisions

  1. Composition-Root IoC — index.js wires all dependencies. Modules don't cross-import.
  2. Minimal AliasStore — Only 4 methods needed for room/user alias management.
  3. Simple JSON persistence — persist.js handles load/save. Two data files.
  4. withErrorHandling wrapper — DRYs the repeated try/catch in every tool.
  5. No cron, no LLM, no bot — Pure MCP tool server. Agents handle their own scheduling.

Testing

# All tests (unit + E2E)
npm test

# Watch mode
npm run test:watch

# With coverage
npm run test:coverage

65 tests across 6 files (5 unit, 1 E2E).

Project Structure

src/
├── index.js              — Composition root: config → Matrix client → wire → start
├── mcp-server.js          — 15 MCP tools + helpers (withErrorHandling, resolveRoomInput, etc.)
├── matrix-id-resolver.js  — Room/user name → Matrix ID resolution
├── alias-store.js         — Minimal per-user alias storage
├── mcp-data-store.js      — DM room ID cache
└── persist.js             — Simple JSON load/save utility

__tests__/
├── unit/                  — Unit tests (alias-store, mcp-data-store, resolver, mcp-server, persist)
├── e2e/                   — E2E test (full server start → MCP client → tool calls)
├── mocks/                 — Mock MatrixClient for testing
└── vitest.config.js

Sponsors

If this project is useful to you, consider supporting its development:

  • GitHub Sponsors
  • Solana: Eu8wQcW68TKMs1a6eqzZu8znzU52QLqQugAMG8uCD6y6
  • EVM (Ethereum / Base / Arbitrum / Optimism / Polygon): 0x2733ff7c865C56d565a99BE1DC11B81cc76850A5
  • XRP Ledger: r4X6e7McAQj7e8vBCeued1RYu4mCJrREDG

License

MIT © 2026 Guan

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选