personalmcpproxy公司
使用ASP.NET构建的具有单用户OAuth2身份验证(授权码+PKCE)的个人MCP服务器。NET Core,并作为原生AOT二进制文件发布。
MCP工具
黑森林实验室——图像生成
| 工具 | 说明 |
|---|---|
GenerateImage | 使用任何FLUX模型将文本转换为图像。支持 width/height (FLUX.2,16的倍数,最高4MP)和 aspect_ratio (Kontext,例如。 "16:9"). |
EditImage | 通过以下方式进行图像到图像编辑 input_image适用于FLUX.2和Kontext模型。 |
FillImage | 使用FLUX Fill进行遮蔽修复(flux-pro-1.0-fill).白色口罩=填充,黑色=保留。 |
GetBflCredits | 返回已配置API密钥的当前信用余额。 |
所有图像工具共享这些输出参数:
| 参数 | 默认值 | 说明 |
|---|---|---|
returnHtmlTag | true | 将结果打包成 `` 标签 |
returnBase64 | false | 内联返回图像数据,而不是服务器URL |
cacheKey | -- | 可选字符串键。第一次调用时,结果存储在此密钥下;具有相同密钥的后续调用立即从缓存返回,而不会命中BFL API。 |
输出模式矩阵:
returnHtmlTag | returnBase64 | 结果 |
|---|---|---|
true | false | `` |
false | false | https://host/images/{id} |
true | true | `` |
false | true | 原始base64字符串 |
通过URL提供的图像在服务器端缓存,并在以下时间过期 ImageTtlMinutes.何时 returnBase64 是真的,不是 cacheKey 如果设置了,则图像根本不会存储在服务器上。
效用
| 工具 | 说明 |
|---|---|
GetServerVersion | 返回正在运行的服务器版本。 |
GetRandomNumber | 返回给定范围内的随机数。 |
快速开始
本地开发
1.通过用户密钥设置凭据 (将秘密置于源代码控制之外):
dotnet user-secrets --project Mcp.Proxy.Server set "Authentication:Schemes:SingleUserOAuth:UserName" "alice"
dotnet user-secrets --project Mcp.Proxy.Server set "Authentication:Schemes:SingleUserOAuth:Password" "secret"
dotnet user-secrets --project Mcp.Proxy.Server set "BlackForestLabs:ApiKey" "your-bfl-api-key"2.运行:
dotnet run --project Mcp.Proxy.Server3.连接 您的MCP客户端 http://localhost:5000.
为了在重启过程中保持令牌稳定性,还设置 TokenSigningKey:
dotnet user-secrets --project Mcp.Proxy.Server set "Authentication:Schemes:SingleUserOAuth:TokenSigningKey" "$(openssl rand -hex 32)"码头工人
构建:
docker build -t personalmcpproxy:latest .运行:
docker run -d \
--name personalmcpproxy \
--restart unless-stopped \
-p 5000:5000 \
-e Authentication__Schemes__SingleUserOAuth__UserName=alice \
-e Authentication__Schemes__SingleUserOAuth__Password=secret \
-e Authentication__Schemes__SingleUserOAuth__TokenSigningKey=your-signing-key \
-e BlackForestLabs__ApiKey=your-bfl-api-key \
personalmcpproxy:latest反向代理的背后 --服务器信任 X-Forwarded-For / X-Forwarded-Proto 自动标题。Nginx示例:
server {
listen 443 ssl;
server_name mcp.example.com;
location / {
proxy_pass http://personalmcpproxy:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 300s; # generation can take up to ~5 minutes
}
}集 proxy_read_timeout 至少300秒-图像生成轮询BFL API长达280秒。认证
服务器使用OAuth2授权码流和PKCE。当MCP客户端连接时,它将:
- 获取
/.well-known/oauth-authorization-server为了发现 - 将您重定向到
/authorize--使用您的用户名和密码登录 - 将身份验证码替换为Bearer令牌
/token - 在所有后续MCP请求中使用令牌
配置参考
设置可以通过以下方式提供 appsettings.json,环境变量(使用 __ 而不是 : 作为分隔符)或用户秘密。
| 设置 | 环境变量 | 默认值 | 描述 |
|---|---|---|---|
McpServer:Transport | McpServer__Transport | Http | Http 或 Console (stdio) |
McpServer:Port | McpServer__Port | -- | HTTP端口覆盖 |
McpServer:ImageTtlMinutes | McpServer__ImageTtlMinutes | 60 | 生成的图像在服务器端缓存的时间(分钟) |
Authentication:Schemes:SingleUserOAuth:UserName | Authentication__Schemes__SingleUserOAuth__UserName | -- | 登录用户名 |
Authentication:Schemes:SingleUserOAuth:Password | Authentication__Schemes__SingleUserOAuth__Password | -- | 登录密码 |
Authentication:Schemes:SingleUserOAuth:TokenSigningKey | Authentication__Schemes__SingleUserOAuth__TokenSigningKey | random | 签名无记名代币的秘密。设置此选项可在重新启动时保持令牌有效。 |
BlackForestLabs:ApiKey | BlackForestLabs__ApiKey | - | BFL API密钥-在 api.bfl.ai |
应用程序参数示例
{
"McpServer": {
"Port": 5000,
"ImageTtlMinutes": 60
},
"Authentication": {
"Schemes": {
"SingleUserOAuth": {
"UserName": "alice",
"Password": "secret",
"TokenSigningKey": "your-signing-key"
}
}
},
"BlackForestLabs": {
"ApiKey": "your-bfl-api-key"
}
}测试
dotnet test现场烟雾测试符合真正的BFL API,除非 MCPPROXYAPP_BFL_API_KEY 已设置:
# PowerShell
$env:MCPPROXYAPP_BFL_API_KEY="your-key"; dotnet test --filter "BflApiSmokeTest"# Bash
MCPPROXYAPP_BFL_API_KEY="your-key" dotnet test --filter "BflApiSmokeTest"