MaxMindDB MCP Server 是一个强大的模型上下文协议(MCP)服务器,它通过 MaxMindDB 数据库提供全面的地理位置和网络情报。支持对 GeoIP2、GeoLite2 和自定义 MMDB 文件进行查询,并具备高级过滤、有状态迭代和自动更新等功能。
⚠️ 重要提示
这是一个非官方项目,未得到 MaxMind Inc. 的认可。此 MCP 服务器是独立实现的。如需官方 MaxMind 产品和支持,请访问 maxmind.com。
go install github.com/oschwald/maxminddb-mcp/cmd/maxminddb-mcp@latest
git clone https://github.com/oschwald/maxminddb-mcp.git
cd maxminddb-mcp
go build -o maxminddb-mcp cmd/maxminddb-mcp/main.go
创建 ~/.config/maxminddb-mcp/config.toml
文件:
mode = "maxmind"
auto_update = true
update_interval = "24h"
[maxmind]
account_id = 123456
license_key = "your_license_key_here"
editions = ["GeoLite2-City", "GeoLite2-Country", "GeoLite2-ASN"]
database_dir = "~/.cache/maxminddb-mcp/databases"
将以下内容添加到 Claude Desktop 配置文件中:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"maxminddb": {
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
}
}
若已有 GeoIP.conf 文件,可使用以下配置:
{
"mcpServers": {
"maxminddb": {
"command": "maxminddb-mcp"
}
}
}
将 MCP 服务器添加到 Claude Code CLI:
claude mcp add maxminddb maxminddb-mcp
若要使用自定义配置:
MAXMINDDB_MCP_CONFIG=/path/to/config.toml claude chat
安装 Claude Code 扩展并添加到 VS Code 设置中:
{
"claude.mcpServers": {
"maxminddb": {
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
}
}
安装 Continue 扩展并添加到 Continue 配置文件 (~/.continue/config.json
) 中:
{
"mcpServers": [
{
"name": "maxminddb",
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
]
}
将以下内容添加到 Zed 设置 (~/.config/zed/settings.json
) 中:
{
"assistant": {
"mcp_servers": [
{
"name": "maxminddb",
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
]
}
}
安装 Cline 并添加到 VS Code 设置中:
{
"cline.mcpServers": {
"maxminddb": {
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
}
}
将以下内容添加到 Gemini CLI 配置文件中:
{
"mcpServers": {
"maxminddb": {
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
}
}
更多详细信息请参阅 Gemini CLI MCP 指南。
将以下内容添加到 Codex 配置文件中:
[mcp_servers.maxminddb]
command = "maxminddb-mcp"
env = { MAXMINDDB_MCP_CONFIG = "/path/to/your/config.toml" }
若不使用自定义配置:
[mcp_servers.maxminddb]
command = "maxminddb-mcp"
将以下内容添加到 Cody 设置中:
{
"cody.experimental.mcp": {
"servers": {
"maxminddb": {
"command": "maxminddb-mcp",
"env": {
"MAXMINDDB_MCP_CONFIG": "/path/to/your/config.toml"
}
}
}
}
}
安装 LLM 工具并配置 MCP:
# 安装 LLM
pip install llm
# 配置 MCP 服务器
llm mcp install maxminddb-mcp --command maxminddb-mcp
# 使用环境变量
MAXMINDDB_MCP_CONFIG=/path/to/config.toml llm chat -m claude-3.5-sonnet
pip install mcp
from mcp import ClientSession, StdioServerParameters
async with ClientSession(
StdioServerParameters(
command="maxminddb-mcp",
env={"MAXMINDDB_MCP_CONFIG": "/path/to/config.toml"}
)
) as session:
await session.initialize()
tools = await session.list_tools()
result = await session.call_tool("lookup_ip", {"ip": "8.8.8.8"})
npm install @modelcontextprotocol/sdk
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "maxminddb-mcp",
env: { MAXMINDDB_MCP_CONFIG: "/path/to/config.toml" },
});
const client = new Client(
{
name: "maxminddb-client",
version: "1.0.0",
},
{ capabilities: {} }
);
await client.connect(transport);
const result = await client.callTool({
name: "lookup_ip",
arguments: { ip: "8.8.8.8" },
});
go get github.com/mark3labs/mcp-go
import (
"github.com/mark3labs/mcp-go/client"
"github.com/mark3labs/mcp-go/transport/stdio"
)
cmd := exec.Command("maxminddb-mcp")
cmd.Env = append(cmd.Env, "MAXMINDDB_MCP_CONFIG=/path/to/config.toml")
transport := stdio.NewTransport(cmd)
mcpClient := client.New(transport)
// ... 使用客户端
使用 JSON-RPC 直接测试服务器:
# 列出可用工具
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | maxminddb-mcp
# 测试 IP 查找
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"lookup_ip","arguments":{"ip":"8.8.8.8"}}}' | maxminddb-mcp
# 使用 jq 进行美化输出
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | maxminddb-mcp | jq .
maxminddb-mcp
在系统路径中,或者提供二进制文件的完整路径。MAXMINDDB_MCP_CONFIG
:配置文件的路径。MAXMINDDB_MCP_LOG_LEVEL
:日志级别 (debug
, info
, warn
, error
)。MAXMINDDB_MCP_LOG_FORMAT
:日志格式 (text
, json
)。服务器支持三种配置模式(按顺序检查):
MAXMINDDB_MCP_CONFIG
~/.config/maxminddb-mcp/config.toml
/etc/GeoIP.conf
或 ~/.config/maxminddb-mcp/GeoIP.conf
# 操作模式: "maxmind", "directory", 或 "geoip_compat"
mode = "maxmind"
# 自动更新设置
auto_update = true
update_interval = "24h"
# 迭代器设置
iterator_ttl = "10m"
iterator_cleanup_interval = "1m"
# 日志记录 (可选)
log_level = "info" # debug, info, warn, error
log_format = "text" # text, json
[maxmind]
# MaxMind 账户凭证
account_id = 123456
license_key = "your_license_key_here"
# 要下载的数据库
editions = [
"GeoLite2-City",
"GeoLite2-Country",
"GeoLite2-ASN",
"GeoIP2-City",
"GeoIP2-Country"
]
# 存储位置
database_dir = "~/.cache/maxminddb-mcp/databases"
# 自定义端点 (可选)
# endpoint = "https://updates.maxmind.com"
[directory]
# 目录模式 - 扫描这些路径以查找 MMDB 文件
paths = [
"/path/to/mmdb/files",
"/another/path"
]
[geoip_compat]
# GeoIP.conf 兼容模式
config_path = "/etc/GeoIP.conf"
database_dir = "/var/lib/GeoIP"
iterator_ttl
(默认值:"10m"):空闲迭代器在清理前的保留时间。iterator_cleanup_interval
(默认值:"1m"):检查过期迭代器的频率。服务器会自动检测并使用现有的 GeoIP.conf 文件:
# 示例 GeoIP.conf
AccountID 123456
LicenseKey your_license_key_here
EditionIDs GeoLite2-Country GeoLite2-City GeoLite2-ASN
DatabaseDirectory /var/lib/GeoIP
无需额外配置,服务器将自动使用兼容模式。
lookup_ip
查找特定 IP 地址的地理位置和网络信息。
ip
(必需):要查找的 IP 地址(IPv4 或 IPv6)。database
(可选):要查询的特定数据库文件名。{
"name": "lookup_ip",
"arguments": {
"ip": "8.8.8.8",
"database": "GeoLite2-City.mmdb"
}
}
{
"ip": "8.8.8.8",
"network": "8.8.8.0/24",
"data": {
"country": {
"iso_code": "US",
"names": { "en": "United States" }
},
"location": {
"latitude": 37.4056,
"longitude": -122.0775
}
}
}
lookup_network
使用强大的过滤功能查询网络范围内的所有 IP 地址。
network
(必需):要扫描的 CIDR 网络(例如,"192.168.1.0/24")。database
(可选):要查询的特定数据库。filters
(可选):过滤对象数组。每个对象必须包含 field
、operator
和 value
。filter_mode
(可选):"and"(默认)或 "or"。max_results
(可选):返回的最大结果数(默认值:1000)。iterator_id
(可选):恢复现有迭代器。resume_token
(可选):过期迭代器的备用令牌。{
"name": "lookup_network",
"arguments": {
"network": "10.0.0.0/8",
"filters": [
{
"field": "country.iso_code",
"operator": "in",
"value": ["US", "CA", "MX"]
}
]
}
}
{
"name": "lookup_network",
"arguments": {
"network": "192.168.0.0/16",
"filters": [
{
"field": "traits.user_type",
"operator": "equals",
"value": "residential"
}
]
}
}
常见错误和验证:
"traits.user_type=residential"
。服务器会拒绝此类请求,并提示使用对象:{ "field": "traits.user_type", "operator": "equals", "value": "residential" }
。filters
必须是对象数组,其他类型无效。operator
必须是支持的运算符(见下文列表)。短别名 (eq
, ne
, gt
, gte
, lt
, lte
) 也被接受。{
"name": "lookup_network",
"arguments": {
"network": "10.0.0.0/24",
"filters": [
{
"field": "traits.is_anonymous_proxy",
"operator": "equals",
"value": false
},
{
"field": "traits.is_satellite_provider",
"operator": "equals",
"value": false
}
],
"filter_mode": "and"
}
}
list_databases
列出所有可用的 MaxMind 数据库及其元数据。
{
"name": "list_databases",
"arguments": {}
}
{
"databases": [
{
"name": "GeoLite2-City.mmdb",
"type": "City",
"description": "GeoLite2 City Database",
"last_updated": "2024-01-15T10:30:00Z",
"size": 67108864
}
]
}
update_databases
手动触发数据库更新(仅适用于 MaxMind/GeoIP 模式)。
{
"name": "update_databases",
"arguments": {}
}
equals
:精确匹配not_equals
:不等于指定值in
:值在提供的数组中not_in
:值不在提供的数组中contains
:字符串包含子字符串regex
:匹配正则表达式greater_than
:数值比较greater_than_or_equal
:数值比较(≥)less_than
:数值比较less_than_or_equal
:数值比较(≤)exists
:字段存在(布尔值)为方便起见,支持短运算符别名(不区分大小写):
eq
→ equals
ne
→ not_equals
gt
→ greater_than
gte
→ greater_than_or_equal
lt
→ less_than
lte
→ less_than_or_equal
所有工具都返回结构化的错误响应,包含机器可读的错误代码:
{
"error": {
"code": "db_not_found",
"message": "Database not found: invalid_db.mmdb"
}
}
db_not_found
:指定的数据库不存在invalid_ip
:IP 地址格式无效invalid_network
:网络 CIDR 格式无效invalid_filter
:过滤器验证失败iterator_not_found
:迭代器 ID 未找到或已过期parse_error
:解析请求参数失败对于大型网络查询,服务器使用有状态迭代器系统:
iterator_id
恢复活动迭代。resume_token
恢复。// 第一次调用 - 创建迭代器
{
"name": "lookup_network",
"arguments": {
"network": "10.0.0.0/8",
"max_results": 1000
}
}
// 响应中包含用于继续的 iterator_id
{
"results": [...],
"iterator_id": "iter_abc123",
"resume_token": "eyJ0eXAiOiJKV1Q...",
"has_more": true
}
// 使用 iterator_id 继续(快速路径)
{
"name": "lookup_network",
"arguments": {
"network": "10.0.0.0/8",
"iterator_id": "iter_abc123",
"max_results": 1000
}
}
在 TOML 配置中配置自动更新:
auto_update = true
update_interval = "24h" # 每 24 小时检查一次
服务器将:
使用 update_databases
工具触发立即更新。
在目录模式下,服务器监控文件系统变化:
mode = "directory"
[directory]
paths = ["/path/to/mmdb/files"]
递归监控所有子目录中的 MMDB 文件。
# 验证配置文件语法
maxminddb-mcp --help
# 测试配置加载
MAXMINDDB_MCP_LOG_LEVEL=debug maxminddb-mcp
# 启用调试日志
MAXMINDDB_MCP_LOG_LEVEL=debug maxminddb-mcp
# 检查服务器是否在 PATH 中
which maxminddb-mcp
# 直接测试服务器
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | maxminddb-mcp
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
启用详细日志以进行故障排除:
# 环境变量
MAXMINDDB_MCP_LOG_LEVEL=debug
MAXMINDDB_MCP_LOG_FORMAT=json
# 或在 config.toml 中
log_level = "debug"
log_format = "json"
服务器在启动时验证所有配置,并提供详细的错误消息:
max_results
。update_interval
平衡数据新鲜度和网络使用。max_results
限制。本项目采用 ISC 许可证,请参阅 LICENSE 文件获取详细信息。
欢迎贡献代码!请阅读我们的 贡献指南,了解如何提交拉取请求、报告问题和提出改进建议。