-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Mcp all in #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FrankXMX
wants to merge
5
commits into
imsyy:master
Choose a base branch
from
FrankXMX:mcp-all-in
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mcp all in #137
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
261470d
feat: add MCP server for DailyHotApi
FrankXMX ffb4345
docs: update MCP README with OpenClaw/OpenCode/Claude Code integration
FrankXMX 2eac9cf
chore: 更新 .gitignore 忽略文件
FrankXMX a482d92
feat: 合并 MCP 与爬虫代码,实现独立运行
FrankXMX 583ee51
refactor: 移除 HTTP API,改为 MCP 服务
FrankXMX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # DailyHotApi URL (optional, defaults to http://localhost:6688) | ||
| DAILYHOT_API_URL=http://localhost:6688 | ||
|
|
||
| # API Key for authentication (optional, leave empty to disable auth) | ||
| DAILYHOT_API_KEY=your-secret-api-key-here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| # DailyHotApi MCP Server | ||
|
|
||
| Model Context Protocol (MCP) 服务器,为 DailyHotApi 提供工具,可通过 Claude Desktop 或 OpenClaw 访问 60+ 平台的热榜数据。 | ||
|
|
||
| ## 功能特性 | ||
|
|
||
| - 列出所有可用的热榜平台 | ||
| - 获取任意支持平台的热榜数据 | ||
| - 内置 API 密钥认证 | ||
| - 路由发现缓存(1小时) | ||
| - 可配置的 API 端点 | ||
|
|
||
| ## 快速部署 | ||
|
|
||
| 无需手动构建,直接使用 npx 运行: | ||
|
|
||
| ```bash | ||
| npx -y @frankxia/dailyhot-mcp | ||
| ``` | ||
|
|
||
| 或指定参数: | ||
|
|
||
| ```bash | ||
| npx -y @frankxia/dailyhot-mcp --api-url http://localhost:6688 --api-key your-key | ||
| ``` | ||
|
|
||
| ### 命令行参数 | ||
|
|
||
| | 参数 | 说明 | 默认值 | | ||
| |------|------|--------| | ||
| | `--api-url` | DailyHotApi 服务器地址 | `http://localhost:6688` | | ||
| | `--api-key` | API 密钥 | (无) | | ||
| | `--port` | MCP 服务端口 | `3000` | | ||
|
|
||
| ## 本地开发 | ||
|
|
||
| ```bash | ||
| cd mcp | ||
| npm install | ||
| npm run build | ||
| npm run dev | ||
| ``` | ||
|
|
||
| ## 配置 | ||
|
|
||
| 复制 `.env.example` 为 `.env`: | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| 环境变量: | ||
|
|
||
| | 变量 | 说明 | 默认值 | | ||
| |------|------|--------| | ||
| | `DAILYHOT_API_URL` | DailyHotApi 服务器地址 | `http://localhost:6688` | | ||
| | `DAILYHOT_API_KEY` | API 密钥 | (无) | | ||
|
|
||
| ## 可用工具 | ||
|
|
||
| ### list_hot_platforms | ||
|
|
||
| 列出所有可用的热榜平台。 | ||
|
|
||
| **参数:** | ||
|
|
||
| - `api_key` (必填):认证用 API 密钥 | ||
|
|
||
| **返回:** 平台对象数组,包含 name、path、title、description。 | ||
|
|
||
| ### get_hot_list | ||
|
|
||
| 获取指定平台的热榜数据。 | ||
|
|
||
| **参数:** | ||
|
|
||
| - `api_key` (必填):认证用 API 密钥 | ||
| - `platform` (必填):平台名称(如 bilibili、weibo、zhihu、github) | ||
| - `limit` (可选):返回最大条目数(1-100) | ||
| - `no_cache` (可选):跳过缓存获取最新数据 | ||
|
|
||
| **返回:** 热榜数据,包含标题、总数和条目数组(标题、链接、热值等)。 | ||
|
|
||
| ## 支持平台 | ||
|
|
||
| 部分热门平台: | ||
|
|
||
| - `bilibili` - B站热门视频 | ||
| - `weibo` - 微博热搜 | ||
| - `zhihu` - 知乎热榜 | ||
| - `douyin` - 抖音热点 | ||
| - `baidu` - 百度热搜 | ||
| - `github` - GitHub Trending | ||
| - `juejin` - 稀土掘金 | ||
| - `v2ex` - V2EX | ||
| - `csdn` - CSDN排行榜 | ||
| - `toutiao` - 今日头条 | ||
| - 等等 40+ 平台... | ||
|
|
||
| 使用 `list_hot_platforms` 获取完整列表。 | ||
|
|
||
| ## 客户端集成 | ||
|
|
||
| ### OpenClaw 集成 | ||
|
|
||
| **配置文件路径:** | ||
|
|
||
| - **Linux**: `~/.openclaw/openclaw.json` | ||
| - **macOS**: `~/.openclaw/openclaw.json` | ||
| - **Windows**: `%USERPROFILE%\.openclaw\openclaw.json` | ||
|
|
||
| **配置示例:** | ||
|
|
||
| 在 `mcp` 节点下添加: | ||
|
|
||
| ```json | ||
| { | ||
| "mcp": { | ||
| "servers": { | ||
| "dailyhot": { | ||
| "command": "npx", | ||
| "args": ["-y", "@frankxia/dailyhot-mcp"] | ||
| }, | ||
| "env": { | ||
| "DAILYHOT_API_URL": "http://localhost:6688", | ||
| "DAILYHOT_API_KEY": "" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 验证:重启 OpenClaw 后提问"有哪些热榜平台?" | ||
|
|
||
| --- | ||
|
|
||
| ### OpenCode 集成 | ||
|
|
||
| **配置文件路径:** | ||
|
|
||
| - **Linux**: `~/.config/opencode/opencode.json` | ||
| - **macOS**: `~/Library/Application Support/opencode/opencode.json` | ||
| - **Windows**: `%APPDATA%\opencode\opencode.json` | ||
|
|
||
| **配置示例:** | ||
|
|
||
| 在 `mcp` 节点下添加: | ||
|
|
||
| ```json | ||
| { | ||
| "mcp": { | ||
| "dailyhot": { | ||
| "type": "local", | ||
| "command": ["npx", "-y", "@frankxia/dailyhot-mcp"], | ||
| "environment": { | ||
| "DAILYHOT_API_URL": "http://localhost:6688", | ||
| "DAILYHOT_API_KEY": "" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 验证:重启 OpenCode 后提问"有哪些热榜平台?" | ||
|
|
||
| --- | ||
|
|
||
| ### Claude Code 集成 | ||
|
|
||
| Claude Code 是 VSCode 插件版本,配置文件位于 `~/.claude/settings.json`。 | ||
|
|
||
| **配置文件路径:** | ||
|
|
||
| - **Linux/macOS**: `~/.claude/settings.json` | ||
| - **Windows**: `%USERPROFILE%\.claude\settings.json` | ||
|
|
||
| **配置示例:** | ||
|
|
||
| 在 `mcpServers` 节点下添加: | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "dailyhot": { | ||
| "command": "npx", | ||
| "args": ["-y", "@frankxia/dailyhot-mcp"], | ||
| "env": { | ||
| "DAILYHOT_API_URL": "http://localhost:6688", | ||
| "DAILYHOT_API_KEY": "your-api-key" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 验证:重启 VSCode 后提问"有哪些热榜平台?" | ||
|
|
||
| --- | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { | ||
| "name": "@frankxia/dailyhot-mcp", | ||
| "version": "1.0.1", | ||
| "description": "MCP Server for DailyHotApi - 今日热榜 MCP 封装", | ||
| "main": "dist/index.js", | ||
| "bin": { | ||
| "dailyhot-mcp": "./dist/cli.js" | ||
| }, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "tsc --project tsconfig.json && node -e \"const fs=require('fs');const p='dist/index.js';const c=fs.readFileSync(p,'utf8');if(!c.startsWith('#!'))fs.writeFileSync(p,'#!/usr/bin/env node\\n'+c)\"", | ||
| "dev": "tsx watch src/index.ts", | ||
| "start": "node dist/index.js", | ||
| "prepublishOnly": "npm run build" | ||
| }, | ||
| "keywords": [ | ||
| "mcp", | ||
| "model-context-protocol", | ||
| "dailyhot", | ||
| "hotlist", | ||
| "claude", | ||
| "claude-desktop" | ||
| ], | ||
| "author": "frankxia", | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/FrankXMX/DailyHotApi.git", | ||
| "directory": "mcp" | ||
| }, | ||
| "dependencies": { | ||
| "@modelcontextprotocol/sdk": "^1.0.0", | ||
| "axios": "^1.11.0", | ||
| "dotenv": "^17.2.1", | ||
| "zod": "^3.24.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^22.16.5", | ||
| "esbuild": "^0.27.4", | ||
| "tsx": "^4.20.3", | ||
| "typescript": "^5.8.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { z } from "zod"; | ||
| import { config } from "dotenv"; | ||
|
|
||
| // Load environment variables | ||
| config(); | ||
|
|
||
| const API_KEY_ENV = "DAILYHOT_API_KEY"; | ||
|
|
||
| const apiKeySchema = z.string().min(1, "API key cannot be empty"); | ||
|
|
||
| /** | ||
| * Get the configured API key from environment variable | ||
| */ | ||
| function getConfiguredApiKey(): string | undefined { | ||
| return process.env[API_KEY_ENV]; | ||
| } | ||
|
|
||
| /** | ||
| * Validate an API key | ||
| * @param apiKey - The API key to validate | ||
| * @returns true if valid, false otherwise | ||
| */ | ||
| export function validateApiKey(apiKey: string | undefined): boolean { | ||
| const configuredKey = getConfiguredApiKey(); | ||
|
|
||
| // If no API key is configured, all requests are allowed | ||
| if (!configuredKey) { | ||
| return true; | ||
| } | ||
|
|
||
| // If API key is required but not provided | ||
| if (!apiKey) { | ||
| return false; | ||
| } | ||
|
|
||
| // Validate the input using Zod | ||
| const result = apiKeySchema.safeParse(apiKey); | ||
| if (!result.success) { | ||
| return false; | ||
| } | ||
|
|
||
| // Compare with configured key | ||
| return apiKey === configuredKey; | ||
| } | ||
|
|
||
| /** | ||
| * Require a valid API key - throws error if invalid | ||
| * @param apiKey - The API key to validate | ||
| * @throws {Error} with { error: "API key is required" } or { error: "Invalid API key" } | ||
| */ | ||
| export function requireApiKey(apiKey: string | undefined): void { | ||
| const configuredKey = getConfiguredApiKey(); | ||
|
|
||
| // If no API key is configured, allow all requests | ||
| if (!configuredKey) { | ||
| return; | ||
| } | ||
|
|
||
| // If API key is required but not provided | ||
| if (!apiKey) { | ||
| const error = new Error("API key is required"); | ||
| (error as any).error = "API key is required"; | ||
| throw error; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| // Validate the input using Zod | ||
| const result = apiKeySchema.safeParse(apiKey); | ||
| if (!result.success) { | ||
| const error = new Error("Invalid API key"); | ||
| (error as any).error = "Invalid API key"; | ||
| throw error; | ||
| } | ||
|
|
||
| // Compare with configured key | ||
| if (apiKey !== configuredKey) { | ||
| const error = new Error("Invalid API key"); | ||
| (error as any).error = "Invalid API key"; | ||
| throw error; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DAILYHOT_API_KEY 的占位符在命令行参数和客户端集成示例中不一致。建议统一使用
your-api-key以提高文档清晰度。