内容
# devto-mcp
Go 命令行工具和 MCP 标准输入/输出服务器,用于 [dev.to](https://dev.to) / [Forem API v1](https://developers.forem.com/api/v1)。
标准库仅支持。使用 `--base` / `DEVTO_BASE` 支持替代 Forem 实例。
## 安装
```bash
make install
# 或本地构建
make build
```
## 快速入门
```bash
# 构建两个命令。
make build
# 将 API 密钥存储在 ~/.config/devto/default.json(0600)中。
./bin/devto login --api-key "$DEVTO_API_KEY"
# 确认身份验证并检查文章。
./bin/devto whoami
./bin/devto articles me --per-page 20
```
对于非交互式环境,请跳过本地存储:
```bash
export DEVTO_API_KEY='...'
./bin/devto whoami
```
## 身份验证
`devto login` 每个配置文件存储一个密钥。使用 `--profile work` 来维护单独的 Forem 帐户。
环境变量:
- `DEVTO_API_KEY` — API 密钥。优先于存储的配置文件。
- `DEVTO_BASE` — Forem 基本 URL。默认:`https://dev.to`。
- `DEVTO_PROFILE` — 存储的凭证配置文件。默认:`default`。
- `DEVTO_CONFIG_DIR` — 凭证目录覆盖。
- `DEVTO_TIMEOUT` — HTTP 超时。默认:`30s`。
## 命令行工具
```bash
devto whoami
devto articles me --per-page 100
devto articles drafts --per-page 100
devto articles list --tag go --top 7
devto articles search --q "模型上下文协议"
devto articles get 123
# --draft 是安全的默认设置。它会创建一个私有的 DEV 草稿。
devto articles create --title "草稿" --file post.md --tags go,api --draft
# 显式公共操作:发布现有的文章。
devto articles update --id 123 --title "新标题" --published
# 添加或替换封面图片,网址为公共绝对 URL。
devto articles update --id 123 --main-image 'https://example.com/cover.png'
devto comments list --article 123
devto comments create --article 123 --body "很好的帖子"
devto users username ben
devto analytics totals --article 123
devto analytics historical --start 2026-01-01 --end 2026-01-31
devto tags
devto api --method GET --path '/api/articles?tag=go'
```
## MCP 配置
Claude Desktop / 兼容主机:
```json
{
"mcpServers": {
"devto": {
"command": "/绝对路径/to/devto-mcp/bin/devto-mcp",
"env": {
"DEVTO_API_KEY": "您的 Forem API 密钥"
}
}
}
}
```
或使用 `devto login` 进行一次身份验证;然后省略 `env`。
## MCP 工具
| 组 | 工具 |
| --- | --- |
| 账户 | `devto_whoami`, `devto_user_get`, `devto_user_by_username`, `devto_followers` |
| 文章 | `devto_articles_list`, `devto_articles_latest`, `devto_articles_search`, `devto_article_get`, `devto_article_by_path`, `devto_articles_me`, `devto_articles_me_published`, `devto_articles_me_unpublished`, `devto_article_create`, `devto_article_update` |
| 评论 / 反应 | `devto_comments_list`, `devto_comment_get`, `devto_comment_create`, `devto_reaction_create` |
| 分析 | `devto_analytics_totals`, `devto_analytics_historical`, `devto_analytics_past_day`, `devto_analytics_referrers`, `devto_analytics_dashboard`, `devto_analytics_heatmap` |
| 其他 | `devto_tags`, `devto_readinglist`, `devto_api_call` |
`devto_api_call` 返回不支持的端点的状态/正文/错误。
## 版本发布
从 [GitHub Releases](https://github.com/igun997/devto-mcp/releases) 安装预构建的二进制文件:
```bash
curl -LO https://github.com/igun997/devto-mcp/releases/download/v0.1.0/devto-mcp_v0.1.0_linux_amd64.tar.gz
tar -xzf devto-mcp_v0.1.0_linux_amd64.tar.gz
```
维护者:合并到 `main`,等待 CI,然后推送语义标签。标签 CI 测试,构建 Linux/macOS 存档,并创建 GitHub Release。
```bash
git tag v0.1.0
git push origin v0.1.0
```
## API
使用 Forem API v1 头部:
```text
accept: application/vnd.forem.api-v1+json
api-key: <密钥>
```