MCP Connector

Access Matrix Homeserver via OAuth 2.0

MCP server for Matrix homeservers with 15 tools across read-only and action tiers, OAuth 2.0, and ephemeral clients.

Works with matrix

Maintainer of this project? Claim this page to edit the listing.


91
Spark score
out of 100
Updated 11 months ago
Version 0.1.0
Models
universal

Add to Favorites

Why it matters

Securely interact with Matrix homeserver functionalities, including rooms, messages, and users, using OAuth 2.0 authentication. This connector provides a robust API for managing Matrix interactions.

Outcomes

What it gets done

01

Authenticate and manage access to Matrix homeserver using OAuth 2.0.

02

Retrieve room and user information, including messages and profiles.

03

Send messages and create new rooms within the Matrix environment.

04

Monitor notification counts and manage direct message conversations.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-matrix | bash

Capabilities

Tools your agent gets

list-joined-rooms

Get all rooms the user has joined

get-room-info

Get detailed information about a room

get-room-members

Show all members of a room

get-room-messages

Get recent messages from a room

get-messages-by-date

Filter messages by date range

identify-active-users

Find most active users by message count

get-user-profile

Get profile information for any user

get-my-profile

Get your own profile information

+7 tools

Overview

Matrix MCP Server

An MCP server exposing 15 Matrix homeserver tools across read-only and action tiers, with OAuth 2.0 authentication and ephemeral client management. Use when an AI assistant needs to read or manage a Matrix homeserver's rooms, messages, and users via a secure MCP interface.

What it does

This is a comprehensive Model Context Protocol (MCP) server, built with TypeScript, providing secure access to Matrix homeserver functionality - rooms, messages, users, and more - through a standardized interface. Features include OAuth 2.0 authentication with token exchange, 15 Matrix tools organized into functionality tiers, multi-homeserver support with configurable endpoints, real-time operations via ephemeral client management, comprehensive error handling, and rich, detailed Matrix data in responses.

When to use - and when NOT to

Use this connector when an AI assistant needs to read from or act on a Matrix homeserver - checking rooms and messages, sending messages, or managing room membership and settings. Two authentication modes are supported: OAuth mode (ENABLE_OAUTH=true), with full OAuth 2.0 integration and token exchange for Matrix authentication, recommended for production; and development mode (ENABLE_OAUTH=false), direct access via Matrix access tokens as headers, simplified for testing but explicitly not recommended for production.

Capabilities

Tier 0 read-only tools cover rooms (list-joined-rooms, get-room-info, get-room-members), messages (get-room-messages with a configurable limit, get-messages-by-date filtering by ISO 8601 date range, identify-active-users ranking by message count), users (get-user-profile for any user, get-my-profile, get-all-users from client cache), search (search-public-rooms by name/topic/server), and notifications (get-notification-counts for unread/mentions, get-direct-messages listing DM conversations). Tier 1 action tools cover messaging (send-message with text/HTML/emote formatting and optional reply-to, send-direct-message auto-creating a DM room if needed), room management (create-room with privacy/topic/invite/alias options, join-room by ID or alias, leave-room with an optional reason, invite-user respecting room permissions), and room administration (set-room-name, set-room-topic, both requiring appropriate permissions).

How to install

Requires Node.js 20+, access to a Matrix homeserver (Synapse, Dendrite, etc.), and an MCP client. Clone the repo, npm install, npm run build, copy .env.example to .env and configure it, then npm start; for development, npm run dev (OAuth disabled by default, or ENABLE_OAUTH=true npm run dev). Key environment variables: PORT, ENABLE_OAUTH, ENABLE_TOKEN_EXCHANGE, CORS_ALLOWED_ORIGINS, optional HTTPS settings (SSL_KEY_PATH/SSL_CERT_PATH), identity-provider URLs for OAuth mode (IDP_ISSUER_URL, IDP_AUTHORIZATION_URL, IDP_TOKEN_URL, OAUTH_CALLBACK_URL), and Matrix settings (MATRIX_HOMESERVER_URL, MATRIX_DOMAIN, MATRIX_CLIENT_ID, MATRIX_CLIENT_SECRET). For Claude Code, add via claude mcp add --transport http matrix-server http://localhost:3000/mcp with matrix_user_id/matrix_homeserver_url/matrix_access_token headers and a Bearer MATRIX_MCP_TOKEN (obtainable from MCP Inspector; the matrix_access_token header is optional once token exchange works). For VS Code, configure the same headers in mcp.json with a promptString input for the access token. Test with the MCP Inspector (npx @modelcontextprotocol/inspector) against http://localhost:3000/mcp.

Integrations

The server implements a three-layer architecture: an HTTP layer (http-server.ts, Express with OAuth integration), an MCP layer (server.ts, tool registration and routing), and a Matrix layer (tools/, split into tier0/tier1 tool implementations) that communicates with the homeserver. Each tool creates an ephemeral Matrix client that authenticates, performs the operation, and cleans up automatically. Security measures include ephemeral token management, OAuth proxying to avoid direct Matrix token exposure, respect for Matrix room power levels and permissions, Zod-schema input validation, and configurable CORS origin restrictions. This project is MIT-licensed.

Who it's for

Teams running a Matrix homeserver who want an AI assistant to read room activity, send messages, and manage rooms through a secure, OAuth-integrated MCP interface rather than direct, unmanaged Matrix token access.

Source README

Matrix MCP Server

A comprehensive Model Context Protocol (MCP) server that provides secure access to Matrix homeserver functionality. Built with TypeScript, this server enables MCP clients to interact with Matrix rooms, messages, users, and more through a standardized interface.

Features

  • ๐Ÿ” OAuth 2.0 Authentication with token exchange support
  • ๐Ÿ“ฑ 15 Matrix Tools organized by functionality tiers
  • ๐Ÿ  Multi-homeserver Support with configurable endpoints
  • ๐Ÿ”„ Real-time Operations with ephemeral client management
  • ๐Ÿš€ Production Ready with comprehensive error handling
  • ๐Ÿ“Š Rich Responses with detailed Matrix data

Quick Start

Prerequisites

  • Node.js 20+ and npm
  • Matrix homeserver access (Synapse, Dendrite, etc.)
  • MCP client (Claude Desktop, VS Code with MCP extension, etc.)

Installation

# Clone the repository
git clone <repository-url>
cd matrix-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

# Configure environment
cp .env.example .env
# Edit .env with your settings

# Start the server
npm start

Development Mode

# Start with hot reload (OAuth disabled for easier testing)
npm run dev

# Or start with OAuth enabled
ENABLE_OAUTH=true npm run dev

Available Tools

๐Ÿ“– Tier 0: Read-Only Tools

Room Tools
  • list-joined-rooms - Get all rooms the user has joined

    • No parameters required
    • Returns room names, IDs, and member counts
  • get-room-info - Get detailed room information

    • roomId (string): Matrix room ID (e.g., !roomid:domain.com)
    • Returns name, topic, settings, creator, and member count
  • get-room-members - List all members in a room

    • roomId (string): Matrix room ID
    • Returns display names and user IDs of joined members
Message Tools
  • get-room-messages - Retrieve recent messages from a room

    • roomId (string): Matrix room ID
    • limit (number, default: 20): Maximum messages to retrieve
    • Returns formatted message content including text and images
  • get-messages-by-date - Filter messages by date range

    • roomId (string): Matrix room ID
    • startDate (string): ISO 8601 format (e.g., 2024-01-01T00:00:00Z)
    • endDate (string): ISO 8601 format
    • Returns messages within the specified timeframe
  • identify-active-users - Find most active users by message count

    • roomId (string): Matrix room ID
    • limit (number, default: 10): Maximum users to return
    • Returns users ranked by message activity
User Tools
  • get-user-profile - Get profile information for any user

    • targetUserId (string): Target user's Matrix ID (e.g., @user:domain.com)
    • Returns display name, avatar, presence, and shared rooms
  • get-my-profile - Get your own profile information

    • No parameters required
    • Returns your profile, device info, and room statistics
  • get-all-users - List all users known to your client

    • No parameters required
    • Returns display names and user IDs from client cache
Search Tools
  • search-public-rooms - Discover public rooms to join
    • searchTerm (string, optional): Filter by name or topic
    • server (string, optional): Specific server to search
    • limit (number, default: 20): Maximum rooms to return
    • Returns room details, topics, and member counts
Notification Tools
  • get-notification-counts - Check unread messages and mentions

    • roomFilter (string, optional): Specific room ID to check
    • Returns unread counts, mentions, and recent activity
  • get-direct-messages - List all DM conversations

    • includeEmpty (boolean, default: false): Include DMs with no recent messages
    • Returns DM partners, last messages, and unread status

โœ๏ธ Tier 1: Action Tools

Messaging Tools
  • send-message - Send messages to rooms

    • roomId (string): Matrix room ID
    • message (string): Message content
    • messageType (enum: "text" | "html" | "emote", default: "text"): Message formatting
    • replyToEventId (string, optional): Event ID to reply to
    • Supports plain text, HTML formatting, and emote actions
  • send-direct-message - Send private messages to users

    • targetUserId (string): Target user's Matrix ID
    • message (string): Message content
    • Automatically creates DM rooms if needed
Room Management Tools
  • create-room - Create new Matrix rooms

    • roomName (string): Name for the new room
    • isPrivate (boolean, default: false): Room privacy setting
    • topic (string, optional): Room topic/description
    • inviteUsers (array, optional): User IDs to invite initially
    • roomAlias (string, optional): Human-readable room alias
    • Creates rooms with appropriate security settings
  • join-room - Join rooms by ID or alias

    • roomIdOrAlias (string): Room ID or alias to join
    • Works with invitations and public rooms
  • leave-room - Leave Matrix rooms

    • roomId (string): Room ID to leave
    • reason (string, optional): Reason for leaving
    • Cleanly exits rooms with optional reason
  • invite-user - Invite users to rooms

    • roomId (string): Room to invite user to
    • targetUserId (string): User ID to invite
    • Respects room permissions and power levels
Room Administration Tools
  • set-room-name - Update room display names

    • roomId (string): Room to modify
    • roomName (string): New room name
    • Requires appropriate room permissions
  • set-room-topic - Update room topics/descriptions

    • roomId (string): Room to modify
    • topic (string): New room topic
    • Requires appropriate room permissions

Authentication & Configuration

Authentication Modes

The server supports two authentication modes:

OAuth Mode (ENABLE_OAUTH=true)
  • Full OAuth 2.0 integration with your identity provider
  • Supports token exchange for Matrix homeserver authentication
  • Secure multi-user access with proper token management
  • Recommended for production deployments
Development Mode (ENABLE_OAUTH=false)
  • Direct access without OAuth authentication
  • Requires Matrix access tokens as headers
  • Simplified setup for testing and development
  • Not recommended for production

Environment Variables

Create a .env file with your configuration:

# Core Configuration
PORT=3000
ENABLE_OAUTH=true                    # Enable OAuth authentication
ENABLE_TOKEN_EXCHANGE=true           # Exchange OAuth tokens for Matrix tokens
CORS_ALLOWED_ORIGINS=""              # Comma-separated allowed origins (empty = allow all)

# HTTPS Configuration (optional)
ENABLE_HTTPS=false
SSL_KEY_PATH="/path/to/private.key"
SSL_CERT_PATH="/path/to/certificate.crt"

# Identity Provider (OAuth mode)
IDP_ISSUER_URL="https://keycloak.example.com/realms/matrix"
IDP_AUTHORIZATION_URL="https://keycloak.example.com/realms/matrix/protocol/openid-connect/auth"
IDP_TOKEN_URL="https://keycloak.example.com/realms/matrix/protocol/openid-connect/token"
OAUTH_CALLBACK_URL="http://localhost:3000/callback"

# Matrix Configuration
MATRIX_HOMESERVER_URL="https://matrix.example.com"
MATRIX_DOMAIN="matrix.example.com"
MATRIX_CLIENT_ID="your-matrix-client-id"
MATRIX_CLIENT_SECRET="your-matrix-client-secret"

Client Integration

Claude Code

Remember, the MATRIX_ACCESS_TOKEN header is an optional header. You should delete it if you have token exchange working. Obtain MATRIX_MCP_TOKEN from MCP Inspector.

claude mcp add --transport http matrix-server http://localhost:3000/mcp -H "matrix_user_id:  @user1:matrix.example.com" -H "matrix_homeserver_url: https://localhost:8008" -H "matrix_access_token: ${MATRIX_ACCESS_TOKEN}" -H "Authorization: Bearer ${MATRIX_MCP_TOKEN}"

VS Code

Remember, the matrix_access_token header is an optional header. You should delete it if you have token exchange working.

In mcp.json:

{
  "servers": {
    "matrix-mcp": {
      "url": "http://localhost:3000/mcp",
      "type": "http",
      "headers": {
        "matrix_access_token": "${input:matrix-access-token}",
        "matrix_user_id": "@<your-matrix-username>:<your-homeserver-domain>",
        "matrix_homeserver_url": "<your-homeserver-url>"
      }
    }
  },
  "inputs": [
    {
      "id": "matrix-access-token",
      "type": "promptString",
      "description": "Your OAuth access token"
    }
  ]
}

Testing with MCP Inspector

# Start the server
npm run dev

# In another terminal, run the inspector
npx @modelcontextprotocol/inspector

Connect to http://localhost:3000/mcp to authenticate and test all available tools.

Development

Available Scripts

npm run build      # Build TypeScript to dist/
npm run dev        # Development server with hot reload
npm run start      # Production server
npm run lint       # Run ESLint
npm run test       # Run tests

Project Structure

src/
โ”œโ”€โ”€ http-server.ts           # Main HTTP server entry point
โ”œโ”€โ”€ server.ts               # MCP server configuration
โ”œโ”€โ”€ tools/                  # Tool implementations
โ”‚   โ”œโ”€โ”€ tier0/             # Read-only tools
โ”‚   โ”‚   โ”œโ”€โ”€ rooms.ts       # Room information tools
โ”‚   โ”‚   โ”œโ”€โ”€ messages.ts    # Message retrieval tools
โ”‚   โ”‚   โ”œโ”€โ”€ users.ts       # User profile tools
โ”‚   โ”‚   โ”œโ”€โ”€ search.ts      # Room search tools
โ”‚   โ”‚   โ””โ”€โ”€ notifications.ts # Notification tools
โ”‚   โ””โ”€โ”€ tier1/             # Action tools
โ”‚       โ”œโ”€โ”€ messaging.ts   # Message sending tools
โ”‚       โ”œโ”€โ”€ room-management.ts # Room lifecycle tools
โ”‚       โ””โ”€โ”€ room-admin.ts  # Room administration tools
โ”œโ”€โ”€ matrix/                # Matrix client management
โ”œโ”€โ”€ utils/                 # Helper utilities
โ””โ”€โ”€ types/                 # TypeScript type definitions

Security Considerations

  • ๐Ÿ” Token Management: All Matrix clients are ephemeral and cleaned up after operations
  • ๐Ÿ›ก๏ธ OAuth Integration: Prevents direct Matrix token exposure through OAuth proxy
  • ๐Ÿ” Permission Checks: Respects Matrix room power levels and permissions
  • ๐Ÿšซ Input Validation: Comprehensive parameter validation using Zod schemas
  • ๐ŸŒ CORS Support: Configurable origin restrictions for web clients

Architecture

The server implements a three-layer architecture:

  1. HTTP Layer (http-server.ts): Express server with OAuth integration
  2. MCP Layer (server.ts): Tool registration and request routing
  3. Matrix Layer (tools/): Matrix homeserver communication

Each tool creates ephemeral Matrix clients that authenticate via your configured method, perform the requested operation, and clean up automatically.

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.