Skip to content

Commit 01e3543

Browse files
committed
feat: 新增 ALAPI 接口平台 MCP 接入文档,更新 go.mod 依赖版本,添加 LICENSE 文件,优化主程序配置加载,支持 OpenAPI 工具初始化,注册自定义工具,完善 README 使用指南。添加腾讯云开发 MCP 接入
1 parent 6ae9307 commit 01e3543

File tree

15 files changed

+433
-118
lines changed

15 files changed

+433
-118
lines changed

DOC.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ALAPI接口平台 MCP 接入
2+
3+
通过 MCP 协议提供与 ALAPI 接口平台交互,可快捷查询IP归属地、天气情况、数据热榜、文本审核、短网址缩短等操作
4+
5+
[前往云开发平台运行 MCP Server](https://tcb.cloud.tencent.com/dev#/ai?tab=mcp&p&mcp-template=mcp-alapi-cn)
6+
7+
---
8+
9+
## 环境变量
10+
11+
- 需要将 **ALAPI_TOKEN** 配置为您在 ALAPI 上创建的 [TOKEN](https://www.alapi.cn/dashboard/data/token)
12+
13+
## 🗺️ 功能清单
14+
15+
以下仅罗列部分功能,具体请以实际调用为准
16+
17+
| 命令名称 | 功能描述 | 核心参数 |
18+
|-------------------------------|-----------------------------------------------|---------------|
19+
| user_apis | 获取已申请的接口列表 | |
20+
| /api/ip | 查询IP归属地信息 | ip |
21+
| /api/tianqi | 查询国内天气详情、包含天气信息、天气预警、天气指数、AQI 等 | city |
22+
| /api/tophub | 查询今日热榜数据,包含抖音热搜、头条热榜、知乎、36k、百度热搜、搜狗热搜、微博热搜等数据 | id,type |
23+
| /api/censor/text | 查询文本是否违规,特别适合AI内容审核 | text |
24+
| /api/url | 短网址缩短,将长网址缩短为短网址,方便短信发送、二维码生成等场景 | url |
25+
| /api/qr/decode | 支持一图多码,支持数十二维码,条形码的识别 | url |
26+
| /api/eventHistory | 历史上的今天,查历史上的指定日期发生的大事 | date |
27+
| /api/exchange | 汇率查询,根据货币代码查询货币汇率和换算,支持全球170+个国家和地区货币查询 | money,from,to |
28+
| /api/enterprise/simple_search | 企业工商信息搜索,根据企业名称或统一社会信用代码查询企业基本工商信息 | keyword |
29+
| /api/kd | 快递查询V1,免费查询快递物流轨迹,支持中通、申通、顺丰、极兔、百世、圆通等 | numner,phone |
30+
| /api/star | 星座运势查询,提供星座运势查询服务,支持查询十二星座今日或明日、本周、本月、本年的运势。 | star |
31+
| /api/gold | 查询当前黄金的实时价格,最高价,最低价,品牌黄金的价格 | market |
32+
33+
## 仓库地址
34+
35+
[https://cnb.cool/alapi/mcp-alapi-cn](https://cnb.cool/alapi/mcp-alapi-cn)
36+
37+
---
38+
39+
## 🔌 使用方式
40+
41+
- [在云开发 Agent 中使用](https://docs.cloudbase.net/ai/mcp/use/agent)
42+
- [在 MCP Host 中使用](https://docs.cloudbase.net/ai/mcp/use/mcp-host)
43+
- [通过 SDK 接入](https://docs.cloudbase.net/ai/mcp/use/sdk)
44+
45+
---
46+
47+
[云开发 MCP 控制台](https://tcb.cloud.tencent.com/dev#/ai?tab=mcp)

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 ALAPI
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 85 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,117 @@
1-
# ALAPI MCP Server
1+
# 🔥 ALAPI MCP Server
22

33
[![smithery badge](https://smithery.ai/badge/@ALAPI-SDK/mcp-alapi-cn)](https://smithery.ai/server/@ALAPI-SDK/mcp-alapi-cn)
4+
![License](https://img.shields.io/badge/license-MIT-green)
45

5-
这是一个基于 [ALAPI](https://www.alapi.cn) 的 MCP (Model Control Protocol) 服务器实现,可以通过MCP协议直接调用ALAPI的接口
6+
这是一个基于 [ALAPI](https://www.alapi.cn) 的 MCP (Model Context Protocol) 服务器实现,可以通过MCP协议直接调用ALAPI的接口,轻松将ALAPI丰富的API资源集成到各类支持MCP的AI应用中。
67

7-
## 功能特点
8+
## 功能特点
89

9-
- 自动加载 ALAPI OpenAPI 规范
10-
- 支持加载全部或指定 API (短视频解析、天气查询、每天60秒读懂世界、企业查询...)
11-
- 符合 MCP 协议标准
12-
- 统一的错误处理和响应格式
13-
- 支持环境变量配置
10+
- 🔍 **丰富API资源** - 提供IP查询、天气查询、热搜榜单、企业信息等100+种常用API服务
11+
- 🧩 **MCP 协议支持** - 完全兼容 Model Context Protocol,轻松集成到各类AI应用
12+
- 🔄 **自动加载** - 自动加载 ALAPI OpenAPI 规范,无需手动配置
13+
- 🎯 **灵活调用** - 支持加载全部或指定API,按需使用(短视频解析、天气查询、每天60秒读懂世界、企业查询等)
14+
- 🛡️ **统一响应** - 提供统一的错误处理和响应格式,简化开发流程
15+
- ⚙️ **可配置性** - 支持环境变量配置,轻松适应不同使用场景
1416

15-
## 环境要求
17+
## 📖 使用指南
1618

17-
- Go 1.24.1 或更高版本
18-
- 有效的 ALAPI Token
19-
- 支持 MCP 的客户端(如 Claude Desktop、Continue、Cursor 等)
19+
首先需要了解 [MCP](https://modelcontextprotocol.io/introduction) 协议,然后按照以下配置添加 ALAPI MCP 服务。
2020

21-
## 安装
21+
## 在 MCP 客户端中使用
2222

23-
### Installing via Smithery
23+
ALAPI MCP Server 设计为与支持 MCP 协议的客户端配合使用,不支持独立的命令行配置。请按照以下步骤在您的 MCP 客户端中配置使用:
2424

25-
To install mcp-alapi-cn for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@ALAPI-SDK/mcp-alapi-cn):
25+
### 方法一:使用 Smithery 自动安装
2626

27-
```bash
28-
npx -y @smithery/cli install @ALAPI-SDK/mcp-alapi-cn --client claude
29-
```
27+
通过 [Smithery](https://smithery.ai/server/@ALAPI-SDK/mcp-alapi-cn) 安装 ALAPI MCP Server,适用于 Claude Desktop 客户端:
3028

31-
### 构建安装
3229
```bash
33-
#Github
34-
git clone https://github.com/alapi-sdk/mcp-alapi-cn.git
35-
36-
#CNB 国内加速地址
37-
#git clone https://cnb.cool/alapi/mcp-alapi-cn.git
38-
39-
cd mcp-server
40-
go mod tidy
41-
go build
30+
npx -y @smithery/cli install @ALAPI-SDK/mcp-alapi-cn --client claude
4231
```
4332

44-
### 下载已构建的软件包
45-
下载对应系统的软件包
33+
### 方法二:直接使用预编译二进制文件(推荐,不用安装依赖)
4634

47-
Github: https://github.com/ALAPI-SDK/mcp-alapi-cn/releases
35+
1. 访问 [Releases 页面](https://github.com/ALAPI-SDK/mcp-alapi-cn/releases) 下载最新版本
36+
> 国内加速下载地址:https://cnb.cool/alapi/mcp-alapi-cn/-/releases
4837
49-
CNB(国内加速): https://cnb.cool/alapi/mcp-alapi-cn/-/releases
38+
2. 根据您的操作系统选择对应最新的版本:
39+
- Windows: `mcp-alapi-cn.exe`
40+
- macOS: `mcp-alapi-cn-macos`
41+
- Linux: `mcp-alapi-cn-linux`
5042

51-
## 配置和使用
43+
3. 在支持 MCP 的客户端(如 Claude Desktop)中配置:
44+
- 打开 MCP 客户端设置
45+
- 添加新的 MCP 服务器
46+
- 指定下载的二进制文件路径
47+
- 配置必要的环境变量(如 `ALAPI_TOKEN`
5248

53-
### 环境变量配置
49+
### 配置环境变量
5450

55-
项目使用以下环境变量:
51+
#### `ALAPI_TOKEN` - ALAPI平台访问令牌(必填)
5652

57-
- `ALAPI_TOKEN`(必需):ALAPI 的认证令牌,在 [token管理](https://www.alapi.cn/dashboard/data/token) 里面创建, **如果不设置,mcp 会启动不了**
58-
- `ALAPI_ID`(可选):指定要加载的 API ID,不设置则加载所有 API(实际的API_id 可通过 [ALAPI](https://www.alapi.cn) 官网查看,可在我的API里面查询)
53+
需要配置为您在 ALAPI 平台上创建的 [TOKEN](https://www.alapi.cn/dashboard/data/token),用于接口认证。
5954

55+
### MCP 客户端配置示例
6056

61-
### Cursor配置方式
57+
在 Claude Desktop 或其他支持 MCP 的客户端中,可以参考以下配置:
6258

63-
1. 打开Cursor设置 > 扩展 > MCP工具
64-
2. 添加新的MCP工具
65-
3. 按照以下格式填写配置:
59+
#### JSON 配置(使用本地二进制文件)
6660

6761
```json
6862
{
69-
"mcpServers": {
70-
"mcp-alapi-cn": {
71-
"command": "C:\\Users\\Administrator\\实际目录\\mcp-alapi-cn.exe",
72-
"env": {
73-
"ALAPI_TOKEN": "xxxx",
74-
"ALAPI_API_ID": "0"
75-
}
76-
}
63+
"mcpServers": {
64+
"alapi": {
65+
"path": "/path/to/mcp-alapi-cn",
66+
"env": {
67+
"ALAPI_TOKEN": "在 ALAPI 平台申请创建的 token"
68+
}
7769
}
70+
}
7871
}
7972
```
8073

81-
### CherryStudio配置方式
82-
1. 打开 CherryStudio 设置 -> MCP 服务器
83-
2. 添加MCP服务器
84-
3. 配置说明:
8574

86-
名称: `MCP-ALAPI-CN`
87-
类型: `STDIO`
88-
命令: `C:\\Users\\Administrator\\实际目录\\mcp-alapi-cn.exe`
89-
环境变量:
90-
```
91-
ALAPI_TOKEN=你的token
92-
```
75+
### 支持的 MCP 客户端
76+
77+
根据 [MCP 文档](https://modelcontextprotocol.io/clients),以下客户端支持 MCP 工具集成:
78+
79+
- Claude Desktop App
80+
- Claude Code
81+
- Cursor
82+
- Continue
83+
- Cline
84+
- 等其他支持 MCP 协议的客户端
85+
86+
> 注意:确保您的 MCP 客户端支持工具集成功能,请参考各客户端的具体文档进行配置。
87+
88+
## 🛠️ 支持的功能
89+
90+
以下是部分支持的功能,完整功能请以实际调用为准:
91+
92+
| 功能名称 | 描述 |
93+
| ------------ | ----------------------------------------------------------------------------- |
94+
| IP查询 | 查询IP归属地信息,支持IPv4和IPv6 |
95+
| 天气查询 | 查询国内天气详情,包含天气信息、天气预警、天气指数、AQI等 |
96+
| 今日热榜 | 查询今日热榜数据,包含抖音热搜、头条热榜、知乎、36k、百度热搜、微博热搜等数据 |
97+
| 文本审核 | 查询文本是否违规,特别适合AI内容审核 |
98+
| 短网址 | 短网址缩短,将长网址缩短为短网址,方便短信发送、二维码生成等场景 |
99+
| 二维码识别 | 支持一图多码,支持数十二维码,条形码的识别 |
100+
| 历史上的今天 | 查询历史上的指定日期发生的大事 |
101+
| 汇率查询 | 根据货币代码查询货币汇率和换算,支持全球170+个国家和地区货币查询 |
102+
| 企业查询 | 根据企业名称或统一社会信用代码查询企业基本工商信息 |
103+
| 快递查询 | 免费查询快递物流轨迹,支持中通、申通、顺丰、极兔、百世、圆通等 |
104+
| 星座运势 | 提供星座运势查询服务,支持查询十二星座今日或明日、本周、本月、本年的运势 |
105+
| 黄金价格 | 查询当前黄金的实时价格,最高价,最低价,品牌黄金的价格 |
106+
107+
## 🔗 相关链接
108+
109+
- [ALAPI官网](https://www.alapi.cn) - 获取API服务和Token
110+
- [MCP协议文档](https://modelcontextprotocol.io) - 了解更多MCP协议相关信息
111+
112+
## 🙏 鸣谢
113+
114+
- [ALAPI](https://www.alapi.cn) - 提供强大的API支持
115+
- [Model Context Protocol](https://modelcontextprotocol.io) - 提供协议标准
116+
117+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.1
55
require (
66
github.com/getkin/kin-openapi v0.131.0
77
github.com/go-resty/resty/v2 v2.16.5
8-
github.com/mark3labs/mcp-go v0.17.0
8+
github.com/mark3labs/mcp-go v0.20.0
99
)
1010

1111
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
2222
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
2323
github.com/mark3labs/mcp-go v0.17.0 h1:5Ps6T7qXr7De/2QTqs9h6BKeZ/qdeUeGrgM5lPzi930=
2424
github.com/mark3labs/mcp-go v0.17.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
25+
github.com/mark3labs/mcp-go v0.20.0 h1:NYZDZ10GBKHVz4SdQ2tPFSDFQFKCTrTZJLn4wj6jAaw=
26+
github.com/mark3labs/mcp-go v0.20.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
2527
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
2628
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
2729
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=

internal/config/config.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
11
package config
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"os/exec"
78
"strings"
89
)
910

11+
// 定义 context key 类型,避免与其他包的 key 冲突
12+
type contextKey string
13+
14+
// ConfigKey 是在 context 中存储 Config 的 key
15+
const ConfigKey contextKey = "config"
16+
1017
type Config struct {
11-
ServerName string
12-
Version string
13-
OpenAPIURL string
14-
BaseURL string
15-
Token string
18+
ServerName string `yaml:"server_name"`
19+
Version string `yaml:"version"`
20+
BaseURL string `yaml:"base_url"`
21+
Token string `yaml:"token"`
22+
OpenAPIURL string `yaml:"openapi_url"`
1623
}
1724

1825
// getVersion 从 Git tag 获取版本号
1926
func getVersion() string {
2027
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
2128
output, err := cmd.Output()
2229
if err != nil {
23-
return "unknown"
30+
return "latest"
2431
}
2532
return strings.TrimSpace(strings.TrimPrefix(string(output), "v"))
2633
}
2734

28-
func NewConfig() (*Config, error) {
35+
// WithConfig 返回带有配置信息的新 context
36+
func WithConfig(ctx context.Context, cfg *Config) context.Context {
37+
return context.WithValue(ctx, ConfigKey, cfg)
38+
}
39+
40+
// FromContext 从 context 中获取配置信息
41+
func FromContext(ctx context.Context) (*Config, bool) {
42+
cfg, ok := ctx.Value(ConfigKey).(*Config)
43+
return cfg, ok
44+
}
45+
46+
// MustFromContext 从 context 中获取配置信息,如果不存在则 panic
47+
func MustFromContext(ctx context.Context) *Config {
48+
cfg, ok := FromContext(ctx)
49+
if !ok {
50+
panic("config not found in context")
51+
}
52+
return cfg
53+
}
54+
55+
func NewConfig(ctx context.Context) (*Config, error) {
2956
token := os.Getenv("ALAPI_TOKEN")
3057
if token == "" {
3158
return nil, fmt.Errorf("ALAPI_TOKEN environment variable is required")

internal/handler/tool_handler.go renamed to internal/handler/openapi_tool_handler.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import (
1010
"github.com/mark3labs/mcp-go/mcp"
1111
)
1212

13-
type ToolHandler struct {
13+
type OpenAPIToolHandler struct {
1414
baseURL string
1515
token string
1616
client *resty.Client
1717
}
1818

19-
func NewToolHandler(baseURL string, token string) *ToolHandler {
20-
return &ToolHandler{
19+
func NewOpenAPIToolHandler(baseURL string, token string) *OpenAPIToolHandler {
20+
return &OpenAPIToolHandler{
2121
baseURL: baseURL,
2222
token: token,
2323
client: resty.New(),
2424
}
2525
}
2626

27-
func (h *ToolHandler) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
27+
func (h *OpenAPIToolHandler) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
2828
arguments := request.Params.Arguments
2929
uri := request.Params.Name
3030

@@ -49,8 +49,7 @@ func (h *ToolHandler) Handle(ctx context.Context, request mcp.CallToolRequest) (
4949
return nil, fmt.Errorf("unmarshal response failed: %w", err)
5050
}
5151
if baseResp.Code != 200 {
52-
// return nil, fmt.Errorf("api response failed:%s", baseResp.Message)
53-
return mcp.NewToolResultText(baseResp.Message), nil
52+
return nil, fmt.Errorf("request params error: %s", baseResp.Message)
5453
}
5554

5655
// 只返回 data 部分的数据

0 commit comments

Comments
 (0)