本指南详细介绍了 MCP 服务器的安装、配置、使用示例、故障排除等内容,帮助你快速搭建和使用 MCP 服务器。
要运行 MCP 服务器,你需要先安装相关依赖项,然后进行配置和使用。以下是具体步骤:
npm 安装 MCP 服务器。要运行 MCP 服务器,请先安装以下依赖项:
安装命令如下:
npm install -g mcp-server
以下是 MCP 服务器的典型配置文件:
{
"mcpServers": {
"default": {
"command": "uvx",
"args": ["mcp-server"],
"env": {
"OPENAPI_SPEC_URL": "https://example.com/openapi.json",
"TOOL_WHITELIST": "/users,/posts",
"API_KEY": "your_api_key"
}
}
}
}
以下是一个 Box API 的配置示例:
{
"mcpServers": {
"box": {
"command": "uvx",
"args": ["mcp-server"],
"env": {
"OPENAPI_SPEC_URL": "https://raw.githubusercontent.com/APIs-guru/openapi-directory/refs/heads/main/APIs/box.com/2.0.0/openapi.yaml",
"TOOL_WHITELIST": "/files,/folders",
"BOX_API_KEY": "your_box_api_key"
}
}
}
}
以下是一个 Wolfram Alpha API 的配置示例:
{
"mcpServers": {
"wolfram-alpha": {
"command": "uvx",
"args": ["mcp-server"],
"env": {
"OPENAPI_SPEC_URL": "https://example.com/wolfram-alpha/openapi.json",
"WOLFRAM_API_KEY": "your_wolfram_api_key"
}
}
}
}
OPENAPI_SPEC_URL="https://example.com/openapi.yaml" TOOL_WHITELIST="/users,/posts" uvx mcp-server
以下是一个典型的 MCP 服务器配置文件示例:
{
"mcpServers": {
"development": {
"command": "uvx",
"args": ["mcp-server"],
"env": {
"NODE_ENV": "development",
"PORT": 3000,
"API_KEY": "your_api_key_here"
}
},
"production": {
"command": "uvx",
"args": ["mcp-server"],
"env": {
"NODE_ENV": "production",
"PORT": 3001,
"API_KEY": "your_production_api_key"
}
}
}
}
以下是 MCP 服务器支持的关键环境变量:
OPENAPI_SPEC_URL:指定 OpenAPI 规范的 URL 或本地文件路径。TOOL_WHITELIST:指定允许的工具端点,以逗号分隔的字符串。API_KEY:指定 API 访问密钥。DEBUG:启用调试模式(值为 true 时)。OPENAPI_SPEC_URL 是否正确,并确保路径可访问。TOOL_WHITELIST 是否包含所需的端点,或将其设置为 null 允许所有端点。API_KEY 是否有效,并确保 API 服务正常运行。MCP 服务器支持以下日志记录级别:
debuginfowarningerror本项目遵循 MIT 许可证,具体条款如下:
MIT License
Copyright (c) [year] [author]
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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.
以上是 MCP 服务器的完整配置指南。如需进一步帮助,请参考官方文档或联系支持团队。