Repository avatar
AI Tools
v1.1.1
active

mastodon-mcp

io.github.richarvey/mastodon-mcp

Give Claude and other AI assistants a Mastodon account: 95 tools for posting, timelines and search

Documentation

mastodon-mcp

CI status Security checks npm version npm downloads Unpacked size Node.js version Mastodon 5.0 Model Context Protocol License: MIT

Give your AI assistant a Mastodon account. mastodon-mcp is a Model Context Protocol server that lets Claude, or any other MCP client, read timelines, post, search, manage notifications and curate your profile on any Mastodon 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
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

You need Node.js 22.12 or newer.

The server is published on npm as @ric_/mastodon-mcp. The simplest way to run it is to let your MCP client start it with npx:

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:

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

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

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):

{
  "mcpServers": {
    "mastodon": {
      "command": "npx",
      "args": ["-y", "@ric_/mastodon-mcp"]
    }
  }
}

Streamable HTTP

Start the server yourself and connect clients to its /mcp endpoint:

npx -y @ric_/mastodon-mcp --transport http --port 3000
# listening on http://localhost:3000/mcp
claude mcp add --transport http mastodon http://localhost:3000/mcp

The HTTP transport has no authentication of its own. Read 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

OptionDefaultDescription
--transport <stdio|http>stdioHow clients connect to the server.
--port <number>3000Port for the HTTP transport.
--passphrase <text>built-in defaultPassphrase used to encrypt stored credentials. See 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.

Every tool also carries MCP tool annotations: a readable title, and hints saying whether it only reads, whether it deletes or overwrites something, whether repeating it is harmless, and whether it contacts a Mastodon instance. They are listed in src/lib/tool-annotations.ts.

Account management (4): connect and disconnect accounts
ToolWhat it does
mastodon_add_accountStart the OAuth flow for an instance (signup: true to create a new account, Mastodon 5.0+)
mastodon_complete_authFinish the OAuth flow with the authorization code
mastodon_list_accountsList configured accounts
mastodon_remove_accountRevoke the token and remove an account
Statuses (16): post, edit, interact, quote
ToolWhat it does
mastodon_create_statusPost a status: text, media, polls, content warnings, scheduling, replies and quotes
mastodon_get_statusGet a status by ID
mastodon_edit_statusEdit a status
mastodon_delete_statusDelete a status, optionally with its media
mastodon_get_status_contextGet the thread around a status
mastodon_boost_status / mastodon_unboost_statusBoost or undo a boost
mastodon_favourite_status / mastodon_unfavourite_statusFavourite or undo a favourite
mastodon_bookmark_status / mastodon_unbookmark_statusBookmark or remove a bookmark
mastodon_list_scheduled_statusesList scheduled statuses
mastodon_cancel_scheduled_statusCancel a scheduled status
mastodon_get_status_quotesList statuses quoting one of yours (4.5+)
mastodon_revoke_status_quoteDetach someone's quote from your status (4.5+)
mastodon_set_status_quote_policyChange who may quote a status (4.5+)
Timelines (4): read feeds
ToolWhat it does
mastodon_get_timeline_homeHome timeline, with server-side filters for boosts, replies, quotes and direct posts (5.0+)
mastodon_get_timeline_publicLocal or federated public timeline
mastodon_get_timeline_hashtagPosts for a hashtag
mastodon_get_timeline_listPosts from a list
Accounts (13): look people up and manage relationships
ToolWhat it does
mastodon_get_own_accountThe authenticated account, including its state on 5.0+
mastodon_get_accountGet an account by ID
mastodon_lookup_accountFind an account by handle
mastodon_get_account_statusesPosts by an account
mastodon_get_followers / mastodon_get_followingWho follows an account, and who it follows
mastodon_get_relationshipsYour relationship to one or more accounts
mastodon_follow_account / mastodon_unfollow_accountFollow or unfollow
mastodon_mute_account / mastodon_unmute_accountMute or unmute
mastodon_block_account / mastodon_unblock_accountBlock or unblock
Profile (10): edit your profile and what it features
ToolWhat it does
mastodon_get_profileYour profile as raw text, ready for editing (4.6+)
mastodon_update_profileUpdate name, bio, fields, avatar, header and profile settings (4.6+)
mastodon_delete_profile_avatar / mastodon_delete_profile_headerRemove the avatar or header (4.6+)
mastodon_get_endorsementsAccounts featured on a profile
mastodon_endorse_account / mastodon_unendorse_accountFeature an account on your profile, or stop (4.4+)
mastodon_get_featured_tagsHashtags featured on your profile
mastodon_feature_tag / mastodon_unfeature_tagFeature a hashtag on your profile, or stop (4.4+)
Notifications (9): individual and grouped
ToolWhat it does
mastodon_get_notificationsList notifications, filtered by type
mastodon_get_notificationGet one notification
mastodon_dismiss_notificationDismiss one notification
mastodon_clear_notificationsClear all notifications
mastodon_get_grouped_notificationsNotifications grouped as the web interface shows them (4.3+)
mastodon_get_notification_groupGet one group (4.3+)
mastodon_get_notification_group_accountsEveryone behind a group (4.3+)
mastodon_dismiss_notification_groupDismiss a whole group (4.3+)
mastodon_get_unread_notification_countNumber of unread notification groups (4.3+)
Collections (9): public, curated lists of accounts (4.6+)
ToolWhat it does
mastodon_get_account_collectionsCollections created by an account
mastodon_get_account_in_collectionsCollections an account is featured in
mastodon_get_collectionA collection with its accounts
mastodon_create_collection / mastodon_update_collection / mastodon_delete_collectionManage your collections
mastodon_add_collection_item / mastodon_remove_collection_itemAdd or remove an account
mastodon_revoke_collection_itemTake yourself out of someone else's collection
Lists (8): private lists for your own timelines
ToolWhat it does
mastodon_get_lists / mastodon_get_listList your lists, or get one
mastodon_create_list / mastodon_update_list / mastodon_delete_listManage lists
mastodon_get_list_accountsAccounts in a list
mastodon_add_list_accounts / mastodon_remove_list_accountsAdd or remove accounts
Search, media, filters, conversations (13)
ToolWhat it does
mastodon_searchSearch accounts, statuses and hashtags
mastodon_upload_mediaUpload a local file, with alt text and focal point
mastodon_update_media / mastodon_get_media / mastodon_delete_mediaManage an uploaded attachment
mastodon_get_filters / mastodon_get_filterList content filters, or get one
mastodon_create_filter / mastodon_update_filter / mastodon_delete_filterManage filters that warn, hide or blur
mastodon_get_conversationsDirect message conversations
mastodon_mark_conversation_read / mastodon_delete_conversationMark a conversation read, or remove it
Instance and annual reports (9)
ToolWhat it does
mastodon_get_instanceInstance details, limits and API version
mastodon_get_trending_tags / mastodon_get_trending_statusesWhat is trending
mastodon_get_custom_emojisThe instance's custom emoji
mastodon_get_announcementsAnnouncements from the admins
mastodon_get_directoryThe profile directory
mastodon_get_annual_report_stateWhether a year-in-review report exists or can be generated (4.6+)
mastodon_generate_annual_reportRequest generation of a report (4.6+)
mastodon_get_annual_reportGet a generated report (4.6+)

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. Every tool tells your client whether it only reads or changes something, and whether the change deletes or overwrites anything, so clients that support MCP tool annotations can let reads through and ask before destructive actions. 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

npm install
npm run dev      # recompile on change
npm run build    # one-off build into dist/
npm start        # run the built server on stdio
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. It also needs a title and behaviour hints in src/lib/tool-annotations.ts, or the server refuses to start. The test suite fails until the new tool has a request test and an entry in this README.

Testing

CommandWhat it checks
npm run lintESLint over the source, tests and scripts
npm run typecheckTypeScript, including the tests
npm testUnit and tool tests: every tool's request to Mastodon, the OAuth flow, the encrypted store, error handling
npm run test:coverageThe same, failing if coverage drops below the thresholds in vitest.config.ts
npm run test:e2eBuilds 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:packagePacks the npm tarball, checks its contents, installs it in an empty project and runs the installed command
npm run test:securityLockfile sources, npm audit, and registry signatures
npm run test:allEverything above

No test talks to a real Mastodon instance or touches your real ~/.mastodon-mcp.

The same checks run in Forgejo Actions 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.

Changes are recorded in the changelog.

Releasing

Releases are published to npm from GitHub, because npm's trusted publishing 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:

    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, where .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 as io.github.richarvey/mastodon-mcp.

  4. If the npm or registry step fails, fix the cause on main and run the workflow from GitHub's Actions tab (Publish to npm and the MCP Registry → Run workflow). It skips whatever is already published and finishes the rest.

License

MIT

Mastodon and the Mastodon logo are trade marks of Mastodon GmbH. This project is not affiliated with or endorsed by Mastodon GmbH.

NPM
@ric_/mastodon-mcp
Install Command
npm install @ric_/mastodon-mcp