这是一个用于与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助手的连接。默认情况下,它在localhost:8000上运行,使用Server-Sent Events(SSE)传输协议。
当在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进行交互。
这些工具可以用来:
导航到Cline MCP设置文件:
%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扩展)添加你的Hashnode MCP服务器配置:
{
"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 MCP服务器配置。
如果你遇到连接问题:
HASHNODE_PERSONAL_ACCESS_TOKEN: 你的Hashnode个人访问令牌HASHNODE_API_URL: Hashnode GraphQL API URL(默认值:https://gql.hashnode.com)欢迎贡献!请随时提交Pull Request。
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查询和突变定义为常量,便于维护和更新。
计划的未来发展包括: