- Go 99.7%
- Dockerfile 0.2%
| .woodpecker | ||
| cmd/mastodon-mcp | ||
| docs | ||
| internal | ||
| .dockerignore | ||
| .gitignore | ||
| .golangci.yml | ||
| .goreleaser.yml | ||
| AGENTS.md | ||
| config.example.yaml | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| Makefile | ||
| README.md | ||
Mastodon MCP
A typed, transport-agnostic MCP server for Mastodon-compatible instances. It exposes instance metadata, accounts, timelines, notifications, statuses (read + post/reply/delete), follower removal, and aggregated account inspection.
The binary speaks MCP over STDIO or Streamable HTTP against any Mastodon-API endpoint. Access tokens are resolved from configuration or by the configured Streamable HTTP request header — never accepted from tool input.
Requirements
- Go 1.26 or newer.
- A Mastodon-compatible instance (Mastodon 3.x/4.x or GoToSocial).
- A valid access token for the configured instance.
Quick start
go mod tidy
go test ./...
go build ./cmd/mastodon-mcp
export MASTODON_MCP_MASTODON__BASE_URL=https://social.example
export MASTODON_MCP_AUTH__MODE=static
export MASTODON_MCP_AUTH__TOKEN='...'
./mastodon-mcp --transport.type=streamable-http --transport.listen=127.0.0.1:8080
The Streamable HTTP endpoint is /mcp; the health endpoint is /healthz.
Both paths are configurable; see Configuration.
Releases
Tagged releases publish a Linux/amd64 binary archive and its checksum to
Forgejo. The archive
contains the single mastodon-mcp executable, which defaults to STDIO and
can also be started with the Streamable HTTP flags shown above.
Docker
The HTTP deployment image is published to Docker Hub:
docker run --rm -p 8080:8080 \
-e MASTODON_MCP_MASTODON__BASE_URL=https://social.example \
-e MASTODON_MCP_AUTH__TOKEN_FILE=/run/secrets/mastodon-token \
-v /absolute/path/to/mastodon-token:/run/secrets/mastodon-token:ro \
skobkin/mastodon-mcp:latest
It runs as a non-root user on 0.0.0.0:8080 with the MCP and health
endpoints at /mcp and /healthz. For any other option, consult the
Configuration reference.
Add to an agent
The examples below assume the binary is at /absolute/path/to/mastodon-mcp
and the Mastodon access token is at /absolute/path/to/mastodon-token.
Replace those and https://social.example with your values.
The HTTP examples intentionally bind to loopback. Do not expose an unencrypted, unauthenticated MCP endpoint on a network.
Claude Code
STDIO:
claude mcp add --scope user --transport stdio mastodon \
--env MASTODON_MCP_MASTODON__BASE_URL=https://social.example \
--env MASTODON_MCP_AUTH__TOKEN_FILE=/absolute/path/to/mastodon-token \
-- /absolute/path/to/mastodon-mcp
HTTP (server already running):
claude mcp add --scope user --transport http \
mastodon http://127.0.0.1:8080/mcp
Codex
STDIO:
codex mcp add mastodon \
--env MASTODON_MCP_MASTODON__BASE_URL=https://social.example \
--env MASTODON_MCP_AUTH__TOKEN_FILE=/absolute/path/to/mastodon-token \
-- /absolute/path/to/mastodon-mcp
HTTP (server already running):
codex mcp add mastodon --url http://127.0.0.1:8080/mcp
OpenCode
Add a mastodon entry under mcp in opencode.json (project scope) or
~/.config/opencode/opencode.json (user scope).
STDIO:
{
"mcp": {
"mastodon": {
"type": "local",
"command": ["/absolute/path/to/mastodon-mcp"],
"environment": {
"MASTODON_MCP_MASTODON__BASE_URL": "https://social.example",
"MASTODON_MCP_AUTH__TOKEN_FILE": "/absolute/path/to/mastodon-token"
},
"enabled": true
}
}
}
HTTP (server already running):
{
"mcp": {
"mastodon": {
"type": "remote",
"url": "http://127.0.0.1:8080/mcp",
"enabled": true
}
}
}
Tool catalog
All tools are registered through tooling.RegisterTool. Reads accept a
detail selector (compact | full | raw); the default is compact for
safety. Aggregations respond per-item so a single failure does not discard
successful items.
instance (metadata)
| Tool | Path | Description |
|---|---|---|
instance_get |
GET /api/v2/instance |
Instance metadata and limits. detail=compact returns a slim shape with the description rendered as plain text; detail=raw returns the bounded original JSON plus HTTP metadata. |
instance_capabilities |
GET /api/v2/instance (probed) |
Detected software, version, and the feature map. refresh=true re-probes and overwrites the cache; otherwise the current cached snapshot is returned. |
accounts
| Tool | Path | Description |
|---|---|---|
account_verify |
GET /api/v1/accounts/verify_credentials |
Verify the authenticated account and the access token. |
account_get |
GET /api/v1/accounts/:id |
One account profile. detail is per-instance. |
account_lookup |
GET /api/v1/accounts/lookup |
Resolve a webfinger acct (user@instance) to a profile. |
account_search |
GET /api/v1/accounts/search |
Free-text search. resolve=true webfinger-resolves; following=true restricts to accounts the authenticated account follows. |
account_followers_page |
GET /api/v1/accounts/:id/followers |
One page of followers. Link-derived cursor. |
account_following_page |
GET /api/v1/accounts/:id/following |
One page of accounts the given account follows. |
account_statuses_page |
GET /api/v1/accounts/:id/statuses |
One page of an account's statuses. Supports pinned, exclude_replies, exclude_reblogs, only_media, tagged. |
account_relationships |
GET /api/v1/accounts/relationships |
Relationship bundle for one or more account IDs in a single round-trip. Capped at aggregation.maximum_accounts_per_call. |
timelines
| Tool | Path | Description |
|---|---|---|
timeline_home_page |
GET /api/v1/timelines/home |
One page of the authenticated account's home timeline. |
timeline_public_page |
GET /api/v1/timelines/public |
One page of the federated public timeline. local=true restricts to the local instance; only_media=true restricts to media attachments. |
timeline_tag_page |
GET /api/v1/timelines/tag/:tag |
One page of statuses tagged with the given hashtag. Empty tag is rejected at the tool layer. |
timeline_list_page |
GET /api/v1/timelines/list/:list_id |
One page of a list timeline; the list must be owned by the authenticated account. |
notifications
| Tool | Path | Description |
|---|---|---|
notifications_page |
GET /api/v1/notifications |
One page of notifications. types[] / exclude_types[] and account_id filters. |
notification_get |
GET /api/v1/notifications/:id |
Fetch one notification. On upstreams that do not implement this endpoint (notably GoToSocial, which returns 404), returns a structured supported: false response with endpoint, software, and status so callers can fall back to notifications_page. |
statuses
| Tool | Path | Description |
|---|---|---|
status_get |
GET /api/v1/statuses/:id |
One status by ID. |
status_context |
GET /api/v1/statuses/:id/context |
Status plus thread ancestors and descendants. |
status_create |
POST /api/v1/statuses |
Publish a new status. Pass idempotency_key for safe retries. |
status_reply |
POST /api/v1/statuses |
Reply to a status. When visibility is omitted, the parent status visibility is inherited rather than broadened. |
status_delete |
DELETE /api/v1/statuses/:id |
Delete one status owned by the authenticated account. |
followers
| Tool | Path | Description |
|---|---|---|
follower_remove |
POST /api/v1/accounts/:id/remove_from_followers |
Remove an existing follower. Uses the native endpoint first; the soft-block fallback activates only when the configured compatibility.follower_removal.fallback is soft-block and the upstream fails explicit unsupported-endpoint responses. |
inspection (aggregated)
| Tool | Path | Description |
|---|---|---|
account_inspect |
parallel sub-requests | Profile, relationship, pinned statuses, and a bounded set of recent statuses for one account. When the account lookup succeeds but a sub-call (relationship / recent / pinned) fails, the partial result is retained and the failure is surfaced in warnings[]. |
accounts_inspect_batch |
parallel sub-requests | Per-account inspection for a flat list of IDs in a single round-trip. Concurrency bounded by aggregation.concurrency. Per-item failures are reported in items[].error with partial=true. |
followers_inspect_page |
one follower page + bounded sub-requests | One bounded follower page enriched with per-account inspection. Never advances the outer follower page automatically. |
Detail modes
Every read tool accepts a detail field:
compact(default): an agent-friendly slim shape. Account and status content is rendered as plain text with HTML tags stripped and entities decoded; script and style blocks are removed entirely.full: the complete typed model as returned by the upstream.raw: the bounded original JSON plus minimal HTTP metadata (status,headers,rate_limit,endpoint). Raw never truncates; responses larger thanhttp.max_raw_bytesfail with a typedRawTooLargeError.
For aggregated tools, detail=raw returns a named raw bundle per
sub-call (account, relationship, recent_statuses, pinned_statuses)
so callers can audit each upstream response independently.
Configuration
Configuration is loaded via Koanf with this precedence:
defaults < YAML file < environment < explicitly changed CLI flags
Environment prefix: MASTODON_MCP_. Use double underscores for nesting:
export MASTODON_MCP_MASTODON__BASE_URL=https://social.example
export MASTODON_MCP_AUTH__MODE=static
export MASTODON_MCP_AUTH__TOKEN='...'
The full reference — every key, its env var, CLI flag, default, and
description — lives in docs/configuration.md.
Authentication
Three modes, selected by auth.mode:
static: token or token file from configuration.request-header: token arrives on each MCP request via the configured Streamable HTTP header. Requiresstreamable-httptransport.hybrid: request header first, then the configured static fallback.
The token is plumbed through auth.Source from request context or static
configuration. Per the safety rules in AGENTS.md, access tokens are
never part of MCP tool input or output schemas.
Pagination
Every collection method returns one page. The opaque cursor is an HMAC-SHA256 signature bound to the endpoint, the exact API path, the configured Mastodon origin, and the Link-derived query parameters. Cursors carry no credentials and cannot redirect the client to another host, path, or instance.
Callers continue by passing next_cursor back to the same tool. Never
infer a cursor from account or status IDs. See
AGENTS.md for the cursor invariant and implementation
details.
Compatibility
Mastodon is the reference implementation. GoToSocial is required and covered by fallback paths:
notification_getreturnssupported: falseon 404/405/501 so callers can fall back tonotifications_page.follower_removeuses the nativeremove_from_followersendpoint first and opts into a soft-block fallback only whencompatibility.follower_removal.fallbackissoft-block; otherwise the error propagates verbatim.instance_capabilitiesreports detected software and the feature map.compatibility.target=autoderives the target from the probe;mastodonandgotosocialforce the target.
Testing
See AGENTS.md for the three-tier test layout (HTTP contract,
HTTP client, MCP in-memory) and the MASTODON_MCP_LIVE_TEST=1 gate for
live integration tests.
Contributing
See AGENTS.md for the required workflow, the architecture
invariants, the package layout, and the test tiers. The same file also
documents the configuration-update checklist and the definition of done.