这是一个用于与 Hashnode API 交互的模型上下文协议(MCP)服务器。该服务器提供了以编程方式访问和搜索 Hashnode 内容的工具。
git clone https://github.com/sbmagar13/hashnode-mcp-server.git
cd hashnode-mcp-server
python -m venv .venv
source .venv/bin/activate # 在 Windows 上使用:.venv\Scripts\activate
pip install -r requirements.txt
.env 文件,并填入你的 Hashnode API 凭证:HASHNODE_PERSONAL_ACCESS_TOKEN=your_personal_access_token
HASHNODE_API_URL=https://gql.hashnode.com
你有两种方式来运行服务器:
python run_server.py
或者直接使用根文件:
python mcp_server.py
服务器将启动并监听来自 AI 助手的连接。默认情况下,它使用服务器发送事件(SSE)传输协议在 localhost:8000 上运行。
当在 Claude Desktop 或 Cline VSCode 扩展中正确配置后,MCP 集成将自动为你启动和管理服务器进程。
当在 Claude Desktop 或 Cline VSCode 扩展中配置你的 MCP 服务器时,你应该直接使用根 mcp_server.py 文件,而不是 hashnode_mcp 目录中的文件。hashnode_mcp 目录主要用于打包。
服务器提供以下工具:
test_api_connection():测试与 Hashnode API 的连接create_article(title, body_markdown, tags="", published=False):在 Hashnode 上创建并发布新文章update_article(article_id, title=None, body_markdown=None, tags=None, published=None):更新 Hashnode 上的现有文章get_latest_articles(hostname, limit=10):按主机名从 Hashnode 出版物中获取最新文章search_articles(query, page=1):在 Hashnode 上搜索文章get_article_details(article_id):获取特定文章的详细信息get_user_info(username):获取 Hashnode 用户的信息服务器启动后,你可以将其与支持模型上下文协议(MCP)的 AI 助手(如 Claude)一起使用。助手将能够使用服务器提供的工具与 Hashnode API 进行交互。 这些工具可用于:
%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings\cline_mcp_settings.json截至目前,Claude Desktop 暂不支持 Linux(你可以使用 Cline 扩展代替){
"mcpServers": {
"hashnode": {
"command": "/path/to/your/venv/bin/python",
"args": [
"/path/to/your/hashnode-mcp-server/mcp_server.py"
],
"env": {
"HASHNODE_PERSONAL_ACCESS_TOKEN": "your-personal-access-token"
}
}
}
}
%APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.json如果你遇到连接问题:
HASHNODE_PERSONAL_ACCESS_TOKEN:你的 Hashnode 个人访问令牌HASHNODE_API_URL:Hashnode GraphQL API 的 URL(默认:https://gql.hashnode.com)欢迎贡献代码!请随时提交拉取请求。
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。
本项目的源代码可在 GitHub 上获取: https://github.com/sbmagar13/hashnode-mcp-server
该项目采用了简洁、模块化的结构:
mcp_server.py:可直接运行的根服务器实现hashnode_mcp/:包含模块化功能的核心包
mcp_server.py:包版本的服务器实现utils.py:用于格式化响应和 GraphQL 查询的实用函数run_server.py:使用包版本运行服务器的入口点服务器使用 Python 的 asyncio 和 httpx 库进行异步编程,以实现高效的 API 通信。GraphQL 查询和突变被定义为常量,便于维护和更新。
计划中的未来开发包括: