mcp-auth-fetch
A powerful and flexible package designed to simplify HTTP/HTTPS requests by automatically applying authentication credentials based on configurable rules. It acts as a seamless proxy for your fetch calls, finding the correct authentication method for a given URL, and attaching the necessary headers or parameters.
README
MCP Auth Fetch
mcp-auth-fetch is a powerful and flexible package designed to simplify HTTP/HTTPS requests by automatically applying authentication credentials based on configurable rules.
It acts as a seamless proxy for your fetch calls, finding the correct authentication method for a given URL, and attaching the necessary headers or parameters.
Features
- Rule-Based Authentication: Configure different authentication methods for different URL patterns (exact match, glob, or regex).
- Multiple Auth Methods: Supports Bearer Tokens, API Keys (in header or query), Basic Auth, and custom Cookies.
- Environment Variable Support: Keep your secrets safe by referencing environment variables directly from the configuration file.
- Global Settings: Configure global settings like user-agent and request timeouts.
Usage as an MCP Plugin
{
"mcpServers": {
"mcp-auth-fetch": {
"command": "npx",
"args": ["mcp-auth-fetch"]
}
}
}
This package is designed to be used as a plugin within an MCP (Model-Centric Programming) environment. Once the package is installed, it exposes its functions as tools that can be called from a compatible MCP client.
Tool: fetch_url
Fetches a URL, automatically applying the authentication configured in .mcp-auth-fetch.json.
Parameters:
--url(required): The URL to fetch.--method(optional): The HTTP method (e.g.,GET,POST). Defaults toGET.--headers(optional): A JSON string of custom headers.--body(optional): The request body forPOST,PUT, etc.--timeout(optional): A request-specific timeout in milliseconds.
Tool: test_auth
Tests your configuration by finding which rule matches a given domain and returns the result as a JSON string.
Configuration
The power of this tool lies in its configuration file. Create a file named .mcp-auth-fetch.json in your project's root directory or your home directory.
Configuration Structure
{
"global_settings": {
"default_timeout": 15000,
"user_agent": "MyAwesomeApp/1.0"
},
"auth_rules": [
{
"url_pattern": "api.github.com",
"description": "GitHub API",
"auth": {
"type": "bearer",
"token": "${GITHUB_TOKEN}"
}
},
{
"url_pattern": "*.openai.com",
"description": "OpenAI API",
"auth": {
"type": "api_key",
"in": "header",
"key": "Authorization",
"value": "Bearer ${OPENAI_API_KEY}"
}
},
{
"url_pattern": "internal-api.my-company.com",
"description": "Internal Basic Auth API",
"auth": {
"type": "basic",
"username": "${INTERNAL_USER}",
"password": "${INTERNAL_PASS}"
}
},
{
"url_pattern": "legacy.example.com",
"description": "Legacy Cookie Auth",
"auth": {
"type": "cookie",
"cookies": {
"session_id": "abc-123-def-456",
"user_token": "${LEGACY_USER_TOKEN}"
}
}
},
{
"url_pattern": "auth-server.my-company.com",
"description": "OAuth2 Client Credentials",
"auth": {
"type": "oauth2",
"token_url": "https://auth-server.my-company.com/oauth/token",
"client_id": "${OAUTH_CLIENT_ID}",
"client_secret": "${OAUTH_CLIENT_SECRET}",
"scope": "api:read"
}
},
{
"url_pattern": "another-service.com",
"description": "OAuth2 with Refresh Token",
"auth": {
"type": "oauth2",
"token_url": "https://another-service.com/api/token",
"client_id": "${SERVICE_CLIENT_ID}",
"client_secret": "${SERVICE_CLIENT_SECRET}",
"refresh_token": "${SERVICE_REFRESH_TOKEN}"
}
},
{
"url_pattern": "/api\\.special\\.com/",
"description": "A special API requiring regex matching",
"auth": {
"type": "bearer",
"token": "${SPECIAL_TOKEN}"
},
"enabled": true
}
]
}
Configuration Fields
global_settings(optional): Settings that apply to all requests.default_timeout: Default request timeout in milliseconds.user_agent: A custom User-Agent string.verbose_test_auth: Set totrueto show the full, unmasked authentication details in thetest_authoutput. Defaults tofalse, which masks sensitive information for security.
auth_rules: An array of authentication rules.url_pattern: The URL pattern to match against the domain of the request URL.- Exact Match:
api.service.com - Glob Match:
*.service.com - Regex Match:
/api\\.service\\.(com|org)/(Note: Regex must be a string starting and ending with/)
- Exact Match:
description(optional): A human-readable description of the rule.enabled(optional): Set tofalseto disable a rule. Defaults totrue.auth: An object describing the authentication method.type: One ofbearer,api_key,basic,cookie,oauth2,function.bearer:{ "type": "bearer", "token": "..." }api_key:{ "type": "api_key", "in": "header"|"query", "key": "...", "value": "..." }basic:{ "type": "basic", "username": "...", "password": "..." }cookie:{ "type": "cookie", "cookies": { "key1": "value1", ... } }oauth2: Handles OAuth2 client credentials and refresh token flows.{ "type": "oauth2", "token_url": "...", "client_id": "...", "client_secret": "...", "scope": "(optional)", "refresh_token": "(optional)" }function: For advanced dynamic credentials. Requires a.mcp-auth-fetch.jsconfig file. The value is a function that returns headers or a bearer token.{ "type": "function", "function": () => ({ "Authorization": "Bearer ..." }) }
Using Environment Variables
For security, you can store secrets in environment variables and reference them in your config file using the ${VAR_NAME} syntax. The tool will automatically substitute them at runtime.
Development
To contribute or run this project locally:
- Clone the repository.
- Install dependencies:
npm install - Run tests:
npm test - Build the project:
npm run build
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。