mastodon-mcp
by richarvey
README.md
<h1 align="center">
<img alt="mastodon-mcp" src="assets/logo.svg" width="433">
</h1>
<p align="center">
<a href="https://code.squarecows.com/ric/mastodon-mcp/actions?workflow=ci.yml"><img alt="CI status" src="https://code.squarecows.com/ric/mastodon-mcp/badges/workflows/ci.yml/badge.svg?branch=main&label=CI"></a> <a href="https://code.squarecows.com/ric/mastodon-mcp/actions?workflow=security.yml"><img alt="Security checks" src="https://code.squarecows.com/ric/mastodon-mcp/badges/workflows/security.yml/badge.svg?branch=main&label=security"></a> <a href="https://www.npmjs.com/package/@ric_/mastodon-mcp"><img alt="npm version" src="https://img.shields.io/npm/v/@ric_/mastodon-mcp?logo=npm&logoColor=white&color=cb3837"></a> <a href="https://www.npmjs.com/package/@ric_/mastodon-mcp"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@ric_/mastodon-mcp?logo=npm&logoColor=white"></a> <a href="https://www.npmjs.com/package/@ric_/mastodon-mcp"><img alt="Unpacked size" src="https://img.shields.io/npm/unpacked-size/@ric_/mastodon-mcp"></a> <a href="https://nodejs.org"><img alt="Node.js version" src="https://img.shields.io/node/v/@ric_/mastodon-mcp?logo=node.js&logoColor=white"></a> <a href="https://joinmastodon.org"><img alt="Mastodon 5.0" src="https://img.shields.io/badge/mastodon-5.0-6364FF?logo=mastodon&logoColor=white"></a> <a href="https://modelcontextprotocol.io"><img alt="Model Context Protocol" src="https://img.shields.io/badge/MCP-server-000000?logo=modelcontextprotocol&logoColor=white"></a> <a href="https://code.squarecows.com/ric/mastodon-mcp/src/branch/main/LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green"></a>
</p>
**Give your AI assistant a Mastodon account.** `mastodon-mcp` is a [Model Context Protocol](https://modelcontextprotocol.io) server that lets Claude, or any other MCP client, read timelines, post, search, manage notifications and curate your profile on any [Mastodon](https://joinmastodon.org) instance.
- **95 tools** covering the Mastodon client API, up to date with **Mastodon 5.0**
- **Multiple accounts** across different instances, side by side
- **stdio and streamable HTTP** transports
- **No API keys to paste**: accounts are added through Mastodon's own OAuth flow
- **One runtime dependency**: the official MCP SDK
```text
You: What have I missed on Mastodon this morning? Skip the boosts.
Claude: (calls mastodon_get_timeline_home with exclude_reblogs)
Here's a summary of the 23 new posts on your home timeline…
You: Reply to the one about the Forgejo release and say thanks.
Claude: (calls mastodon_create_status with in_reply_to_id)
Posted: https://mastodon.social/@you/1155…
```
## Contents
- [Quick start](#quick-start)
- [Connecting to an MCP client](#connecting-to-an-mcp-client)
- [Adding a Mastodon account](#adding-a-mastodon-account)
- [Things to try](#things-to-try)
- [Using several accounts](#using-several-accounts)
- [Command-line options](#command-line-options)
- [Tool reference](#tool-reference)
- [Mastodon compatibility](#mastodon-compatibility)
- [Security](#security)
- [Development](#development)
- [License](#license)
## Quick start
You need [Node.js](https://nodejs.org) 22.12 or newer.
The server is published on npm as [`@ric_/mastodon-mcp`](https://www.npmjs.com/package/@ric_/mastodon-mcp). The simplest way to run it is to let your MCP client start it with `npx`:
```bash
npx -y @ric_/mastodon-mcp
```
Or install it once, which gives you a `mastodon-mcp` command to use in place of `npx -y @ric_/mastodon-mcp`:
```bash
npm install -g @ric_/mastodon-mcp
```
Then point your MCP client at it (next section) and ask the assistant to add your Mastodon account.
### From source
```bash
git clone https://code.squarecows.com/ric/mastodon-mcp.git
cd mastodon-mcp
npm install
npm run build
```
That produces `dist/index.js`, which is the server. In the examples below, use `node /path/to/mastodon-mcp/dist/index.js` in place of `npx -y @ric_/mastodon-mcp`.
## Connecting to an MCP client
### Claude Code
```bash
claude mcp add mastodon -- npx -y @ric_/mastodon-mcp
```
### Claude Desktop and other stdio clients
Add the server to the client's MCP configuration (for Claude Desktop, `claude_desktop_config.json`):
```json
{
"mcpServers": {
"mastodon": {
"command": "npx",
"args": ["-y", "@ric_/mastodon-mcp"]
}
}
}
```
### Streamable HTTP
Start the server yourself and connect clients to its `/mcp` endpoint:
```bash
npx -y @ric_/mastodon-mcp --transport http --port 3000
# listening on http://localhost:3000/mcp
```
```bash
claude mcp add --transport http mastodon http://localhost:3000/mcp
```
The HTTP transport has no authentication of its own. Read [Security](#security) before exposing it beyond your own machine.
## Adding a Mastodon account
Accounts are added from inside the conversation. Ask your assistant something like *"add my Mastodon account on mastodon.social"* and it will walk through these steps:
1. **`mastodon_add_account`** registers the app on your instance and returns an authorization link.
2. **You open the link**, log in, approve access, and copy the code Mastodon shows you.
3. **`mastodon_complete_auth`** exchanges that code for an access token and stores the account.
After that the account is remembered between sessions. `mastodon_list_accounts` shows what is configured, and `mastodon_remove_account` revokes the token and forgets the account.
Don't have an account yet? On Mastodon 5.0+ instances, `mastodon_add_account` with `signup: true` sends you to the instance's sign-up page instead of the log-in page. The account can be added straight away, and the server tells you if it is still waiting for e-mail confirmation or moderator approval.
The app requests the `read`, `write`, `follow` and `push` scopes.
## Things to try
- *"Summarise my home timeline since yesterday, without boosts or replies."*
- *"Who mentioned me this week? Group the notifications."*
- *"Post this photo with alt text describing it, visible to followers only."*
- *"Quote that post and add my thoughts, but only let followers quote mine."*
- *"Find people posting about #selfhosting and put the interesting ones in a list."*
- *"Create a collection called 'Rust folks' with these five accounts."*
- *"Mute any post that mentions the election for the next 7 days."*
- *"Update my bio and add my blog to my profile fields."*
- *"Schedule this announcement for 9am on Monday."*
## Using several accounts
Every tool that talks to Mastodon accepts an optional `account` parameter in `username@instance` form, for example `ric@mastodon.social`.
- With **one** account configured, it is used automatically.
- With **several**, a call without `account` returns an error listing the available handles, so the assistant can ask you which one you mean rather than guess.
Accounts can live on any Mastodon-compatible instance; nothing is tied to a particular server.
## Command-line options
| Option | Default | Description |
| --- | --- | --- |
| `--transport <stdio\|http>` | `stdio` | How clients connect to the server. |
| `--port <number>` | `3000` | Port for the HTTP transport. |
| `--passphrase <text>` | built-in default | Passphrase used to encrypt stored credentials. See [Security](#security). |
## Tool reference
All 95 tools, grouped by area. Each returns the Mastodon API's JSON response, so entity fields are the ones in the [Mastodon API documentation](https://docs.joinmastodon.org/api/).
<details>
<summary><strong>Account management</strong> (4): connect and disconnect accounts</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_add_account` | Start the OAuth flow for an instance (`signup: true` to create a new account, Mastodon 5.0+) |
| `mastodon_complete_auth` | Finish the OAuth flow with the authorization code |
| `mastodon_list_accounts` | List configured accounts |
| `mastodon_remove_account` | Revoke the token and remove an account |
</details>
<details>
<summary><strong>Statuses</strong> (16): post, edit, interact, quote</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_create_status` | Post a status: text, media, polls, content warnings, scheduling, replies and quotes |
| `mastodon_get_status` | Get a status by ID |
| `mastodon_edit_status` | Edit a status |
| `mastodon_delete_status` | Delete a status, optionally with its media |
| `mastodon_get_status_context` | Get the thread around a status |
| `mastodon_boost_status` / `mastodon_unboost_status` | Boost or undo a boost |
| `mastodon_favourite_status` / `mastodon_unfavourite_status` | Favourite or undo a favourite |
| `mastodon_bookmark_status` / `mastodon_unbookmark_status` | Bookmark or remove a bookmark |
| `mastodon_list_scheduled_statuses` | List scheduled statuses |
| `mastodon_cancel_scheduled_status` | Cancel a scheduled status |
| `mastodon_get_status_quotes` | List statuses quoting one of yours (4.5+) |
| `mastodon_revoke_status_quote` | Detach someone's quote from your status (4.5+) |
| `mastodon_set_status_quote_policy` | Change who may quote a status (4.5+) |
</details>
<details>
<summary><strong>Timelines</strong> (4): read feeds</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_timeline_home` | Home timeline, with server-side filters for boosts, replies, quotes and direct posts (5.0+) |
| `mastodon_get_timeline_public` | Local or federated public timeline |
| `mastodon_get_timeline_hashtag` | Posts for a hashtag |
| `mastodon_get_timeline_list` | Posts from a list |
</details>
<details>
<summary><strong>Accounts</strong> (13): look people up and manage relationships</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_own_account` | The authenticated account, including its state on 5.0+ |
| `mastodon_get_account` | Get an account by ID |
| `mastodon_lookup_account` | Find an account by handle |
| `mastodon_get_account_statuses` | Posts by an account |
| `mastodon_get_followers` / `mastodon_get_following` | Who follows an account, and who it follows |
| `mastodon_get_relationships` | Your relationship to one or more accounts |
| `mastodon_follow_account` / `mastodon_unfollow_account` | Follow or unfollow |
| `mastodon_mute_account` / `mastodon_unmute_account` | Mute or unmute |
| `mastodon_block_account` / `mastodon_unblock_account` | Block or unblock |
</details>
<details>
<summary><strong>Profile</strong> (10): edit your profile and what it features</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_profile` | Your profile as raw text, ready for editing (4.6+) |
| `mastodon_update_profile` | Update name, bio, fields, avatar, header and profile settings (4.6+) |
| `mastodon_delete_profile_avatar` / `mastodon_delete_profile_header` | Remove the avatar or header (4.6+) |
| `mastodon_get_endorsements` | Accounts featured on a profile |
| `mastodon_endorse_account` / `mastodon_unendorse_account` | Feature an account on your profile, or stop (4.4+) |
| `mastodon_get_featured_tags` | Hashtags featured on your profile |
| `mastodon_feature_tag` / `mastodon_unfeature_tag` | Feature a hashtag on your profile, or stop (4.4+) |
</details>
<details>
<summary><strong>Notifications</strong> (9): individual and grouped</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_notifications` | List notifications, filtered by type |
| `mastodon_get_notification` | Get one notification |
| `mastodon_dismiss_notification` | Dismiss one notification |
| `mastodon_clear_notifications` | Clear all notifications |
| `mastodon_get_grouped_notifications` | Notifications grouped as the web interface shows them (4.3+) |
| `mastodon_get_notification_group` | Get one group (4.3+) |
| `mastodon_get_notification_group_accounts` | Everyone behind a group (4.3+) |
| `mastodon_dismiss_notification_group` | Dismiss a whole group (4.3+) |
| `mastodon_get_unread_notification_count` | Number of unread notification groups (4.3+) |
</details>
<details>
<summary><strong>Collections</strong> (9): public, curated lists of accounts (4.6+)</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_account_collections` | Collections created by an account |
| `mastodon_get_account_in_collections` | Collections an account is featured in |
| `mastodon_get_collection` | A collection with its accounts |
| `mastodon_create_collection` / `mastodon_update_collection` / `mastodon_delete_collection` | Manage your collections |
| `mastodon_add_collection_item` / `mastodon_remove_collection_item` | Add or remove an account |
| `mastodon_revoke_collection_item` | Take yourself out of someone else's collection |
</details>
<details>
<summary><strong>Lists</strong> (8): private lists for your own timelines</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_lists` / `mastodon_get_list` | List your lists, or get one |
| `mastodon_create_list` / `mastodon_update_list` / `mastodon_delete_list` | Manage lists |
| `mastodon_get_list_accounts` | Accounts in a list |
| `mastodon_add_list_accounts` / `mastodon_remove_list_accounts` | Add or remove accounts |
</details>
<details>
<summary><strong>Search, media, filters, conversations</strong> (13)</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_search` | Search accounts, statuses and hashtags |
| `mastodon_upload_media` | Upload a local file, with alt text and focal point |
| `mastodon_update_media` / `mastodon_get_media` / `mastodon_delete_media` | Manage an uploaded attachment |
| `mastodon_get_filters` / `mastodon_get_filter` | List content filters, or get one |
| `mastodon_create_filter` / `mastodon_update_filter` / `mastodon_delete_filter` | Manage filters that warn, hide or blur |
| `mastodon_get_conversations` | Direct message conversations |
| `mastodon_mark_conversation_read` / `mastodon_delete_conversation` | Mark a conversation read, or remove it |
</details>
<details>
<summary><strong>Instance and annual reports</strong> (9)</summary>
| Tool | What it does |
| --- | --- |
| `mastodon_get_instance` | Instance details, limits and API version |
| `mastodon_get_trending_tags` / `mastodon_get_trending_statuses` | What is trending |
| `mastodon_get_custom_emojis` | The instance's custom emoji |
| `mastodon_get_announcements` | Announcements from the admins |
| `mastodon_get_directory` | The profile directory |
| `mastodon_get_annual_report_state` | Whether a year-in-review report exists or can be generated (4.6+) |
| `mastodon_generate_annual_report` | Request generation of a report (4.6+) |
| `mastodon_get_annual_report` | Get a generated report (4.6+) |
</details>
## Mastodon compatibility
The server targets the **Mastodon 5.0.0** API (API version 12) and stays usable on older 4.x instances:
- Parameters marked with a minimum version are ignored by older servers.
- Tools marked with a minimum version return the instance's own error there, usually a 404.
- Accounts added with an earlier version of this server keep working. The scopes they were granted already cover the newer endpoints.
Other software that implements the Mastodon API should work for the endpoints it supports.
Not covered: the admin API, the streaming API, and push subscriptions.
## Security
**Stored credentials.** OAuth tokens and app credentials are kept in `~/.mastodon-mcp/accounts.json`, readable only by your user and encrypted with AES-256-GCM using a key derived from the passphrase.
> [!IMPORTANT]
> Without `--passphrase`, the file is encrypted with a default passphrase that is in this repository's source code. That keeps tokens out of plain text but does not protect them from anyone who can read the file. Set your own passphrase if that matters to you, and use the same one every time: the store cannot be read with a different one.
A passphrase given on the command line is visible in the process list and in your client's configuration file.
**HTTP transport.** The HTTP server has no authentication and listens on all network interfaces. Anyone who can reach the port can act as every configured Mastodon account. Keep it on a trusted machine, or put it behind a firewall or an authenticating reverse proxy.
**What the assistant can do.** Once an account is connected, the assistant can post, follow, block and delete on your behalf. Use your client's tool-approval settings if you want to confirm those actions.
**Revoking access.** `mastodon_remove_account` revokes the token. You can also revoke it yourself under *Preferences → Account → Authorized apps* on your instance.
## Development
```bash
npm install
npm run dev # recompile on change
npm run build # one-off build into dist/
npm start # run the built server on stdio
```
```text
src/
├── index.ts entry point
├── cli.ts command-line options and transports
├── server.ts builds the MCP server and registers the tools
├── auth/store.ts encrypted account storage
├── lib/
│ ├── mastodon-client.ts HTTP client for the Mastodon API
│ ├── account-resolver.ts picks the account for each tool call
│ └── tool-result.ts helpers for building tool results
└── tools/ one file per group of tools
```
Adding a tool means registering it with `server.tool(...)` in the matching file under `src/tools/`; a new group also needs registering in `src/server.ts`. The test suite fails until the new tool has a request test and an entry in this README.
### Testing
| Command | What it checks |
| --- | --- |
| `npm run lint` | ESLint over the source, tests and scripts |
| `npm run typecheck` | TypeScript, including the tests |
| `npm test` | Unit and tool tests: every tool's request to Mastodon, the OAuth flow, the encrypted store, error handling |
| `npm run test:coverage` | The same, failing if coverage drops below the thresholds in `vitest.config.ts` |
| `npm run test:e2e` | Builds the server, runs it as a real process and talks MCP to it over stdio and HTTP, against a mock Mastodon instance |
| `npm run test:package` | Packs the npm tarball, checks its contents, installs it in an empty project and runs the installed command |
| `npm run test:security` | Lockfile sources, `npm audit`, and registry signatures |
| `npm run test:all` | Everything above |
No test talks to a real Mastodon instance or touches your real `~/.mastodon-mcp`.
The same checks run in [Forgejo Actions](.forgejo/workflows) on every push and pull request, on Node 22 and 24. A separate security workflow also runs weekly and scans the git history for committed secrets with [gitleaks](https://github.com/gitleaks/gitleaks).
Changes are recorded in the [changelog](CHANGELOG.md).
### Releasing
Releases are published to npm from GitHub, because npm's [trusted publishing](https://docs.npmjs.com/trusted-publishers/) only accepts GitHub, GitLab and CircleCI's hosted runners. No npm token is stored anywhere: the publish job proves who it is to npm with a short-lived OIDC token, and npm attaches a provenance attestation to each release.
1. Bump the version in `package.json`, `package-lock.json` (`npm version --no-git-tag-version <version>`), `SERVER_VERSION` in `src/server.ts` and both versions in `server.json`, and add a `CHANGELOG.md` entry. The tests fail if these disagree.
2. Commit, then tag and push the tag to code.squarecows.com:
```bash
git tag v1.2.0
git push origin main v1.2.0
```
3. The push mirror copies the tag to [github.com/richarvey/mastodon-mcp](https://github.com/richarvey/mastodon-mcp), where [`.github/workflows/publish.yml`](.github/workflows/publish.yml) checks the tag matches the version, runs `npm run test:all`, publishes to npm, then lists the new version in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.richarvey/mastodon-mcp`.
## License
[MIT](LICENSE)
Mastodon and the Mastodon logo are trade marks of Mastodon GmbH. This project is not affiliated with or endorsed by Mastodon GmbH.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues