Commit 96379f03 authored by Your Name's avatar Your Name

Add MCP documentation and dashboard settings

- Add MCP features to README.md key features
- Add MCP configuration section to dashboard settings page
- Add MCP form handling in main.py dashboard_settings_save
- Add comprehensive MCP documentation to API_EXAMPLES.md
parent 924dfeeb
...@@ -643,6 +643,118 @@ for i in range(100): ...@@ -643,6 +643,118 @@ for i in range(100):
) )
``` ```
## MCP Server (Model Context Protocol)
AISBF includes an MCP server that allows remote agents to configure the system and make model requests. MCP is disabled by default and must be enabled in the configuration.
### Enabling MCP
Add to your `aisbf.json` config:
```json
{
"mcp": {
"enabled": true,
"autoselect_tokens": ["your-autoselect-token"],
"fullconfig_tokens": ["your-fullconfig-token"]
}
}
```
Or use the dashboard settings page.
### Authentication Levels
- **Autoselect Tokens**: Access to autoselection/autorotation settings + standard APIs
- **Fullconfig Tokens**: Access to full system configuration + standard APIs
### MCP Endpoints
#### SSE Endpoint (Streaming)
```bash
# Initialize connection
curl -N http://localhost:17765/mcp \
-H "Authorization: Bearer your-token"
```
#### HTTP POST Endpoint
```bash
# List available tools
curl -X POST http://localhost:17765/mcp \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}'
# Call a tool
curl -X POST http://localhost:17765/mcp \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_models",
"arguments": {}
}
}'
```
#### Direct Tool Calls
```bash
# List available tools
curl http://localhost:17765/mcp/tools \
-H "Authorization: Bearer your-token"
# Call a tool directly
curl -X POST http://localhost:17765/mcp/tools/call \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{
"name": "list_models",
"arguments": {}
}'
```
### Available Tools
**Common tools (all authenticated clients):**
- `list_models` - List all available models
- `list_rotations` - List all rotation configurations
- `list_autoselect` - List all autoselect configurations
- `chat_completion` - Make chat completion requests
**Autoselect-level tools:**
- `get_autoselect_config` - Get autoselect configuration
- `get_rotation_config` - Get rotation configuration
- `get_autoselect_settings` - Get autoselect settings
- `get_rotation_settings` - Get rotation settings
**Fullconfig-level tools:**
- `get_providers_config` - Get providers configuration
- `set_autoselect_config` - Set autoselect configuration
- `set_rotation_config` - Set rotation configuration
- `set_provider_config` - Set provider configuration
- `get_server_config` - Get server configuration
- `set_server_config` - Set server configuration
- `delete_autoselect_config` - Delete autoselect configuration
- `delete_rotation_config` - Delete rotation configuration
- `delete_provider_config` - Delete provider configuration
### Example: Using MCP with Claude Code
```bash
# Set the MCP server URL
global MCP_SERVER_URL "http://localhost:17765/mcp"
global MCP_AUTH_TOKEN "your-fullconfig-token"
# Or configure in your AI tool's MCP settings
```
## Dashboard Access ## Dashboard Access
Access the web dashboard at: Access the web dashboard at:
......
...@@ -18,6 +18,7 @@ A modular proxy server for managing multiple AI provider integrations with unifi ...@@ -18,6 +18,7 @@ A modular proxy server for managing multiple AI provider integrations with unifi
- **Effective Context Tracking**: Reports total tokens used (effective_context) for every request - **Effective Context Tracking**: Reports total tokens used (effective_context) for every request
- **SSL/TLS Support**: Built-in HTTPS support with Let's Encrypt integration and automatic certificate renewal - **SSL/TLS Support**: Built-in HTTPS support with Let's Encrypt integration and automatic certificate renewal
- **Self-Signed Certificates**: Automatic generation of self-signed certificates for development/testing - **Self-Signed Certificates**: Automatic generation of self-signed certificates for development/testing
- **MCP Server**: Model Context Protocol server for remote agent configuration and model access (SSE and HTTP streaming)
## Author ## Author
......
...@@ -1264,6 +1264,14 @@ async def dashboard_settings(request: Request): ...@@ -1264,6 +1264,14 @@ async def dashboard_settings(request: Request):
with open(config_path) as f: with open(config_path) as f:
aisbf_config = json.load(f) aisbf_config = json.load(f)
# Ensure MCP config exists with defaults
if 'mcp' not in aisbf_config:
aisbf_config['mcp'] = {
'enabled': False,
'autoselect_tokens': [],
'fullconfig_tokens': []
}
return templates.TemplateResponse("dashboard/settings.html", { return templates.TemplateResponse("dashboard/settings.html", {
"request": request, "request": request,
"session": request.session, "session": request.session,
...@@ -1281,7 +1289,10 @@ async def dashboard_settings_save( ...@@ -1281,7 +1289,10 @@ async def dashboard_settings_save(
dashboard_username: str = Form(...), dashboard_username: str = Form(...),
dashboard_password: str = Form(""), dashboard_password: str = Form(""),
condensation_model_id: str = Form(...), condensation_model_id: str = Form(...),
autoselect_model_id: str = Form(...) autoselect_model_id: str = Form(...),
mcp_enabled: bool = Form(False),
autoselect_tokens: str = Form(""),
fullconfig_tokens: str = Form("")
): ):
"""Save server settings""" """Save server settings"""
auth_check = require_dashboard_auth(request) auth_check = require_dashboard_auth(request)
...@@ -1309,6 +1320,13 @@ async def dashboard_settings_save( ...@@ -1309,6 +1320,13 @@ async def dashboard_settings_save(
aisbf_config['internal_model']['condensation_model_id'] = condensation_model_id aisbf_config['internal_model']['condensation_model_id'] = condensation_model_id
aisbf_config['internal_model']['autoselect_model_id'] = autoselect_model_id aisbf_config['internal_model']['autoselect_model_id'] = autoselect_model_id
# Update MCP config
if 'mcp' not in aisbf_config:
aisbf_config['mcp'] = {}
aisbf_config['mcp']['enabled'] = mcp_enabled
aisbf_config['mcp']['autoselect_tokens'] = [t.strip() for t in autoselect_tokens.split('\n') if t.strip()]
aisbf_config['mcp']['fullconfig_tokens'] = [t.strip() for t in fullconfig_tokens.split('\n') if t.strip()]
# Save config # Save config
config_path = Path.home() / '.aisbf' / 'aisbf.json' config_path = Path.home() / '.aisbf' / 'aisbf.json'
config_path.parent.mkdir(parents=True, exist_ok=True) config_path.parent.mkdir(parents=True, exist_ok=True)
......
...@@ -84,6 +84,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -84,6 +84,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<textarea id="auth_tokens" name="auth_tokens" style="min-height: 100px;">{{ '\n'.join(config.auth.tokens) }}</textarea> <textarea id="auth_tokens" name="auth_tokens" style="min-height: 100px;">{{ '\n'.join(config.auth.tokens) }}</textarea>
</div> </div>
<h3 style="margin: 30px 0 20px;">MCP Server</h3>
<div class="form-group">
<label>
<input type="checkbox" name="mcp_enabled" {% if config.mcp.enabled %}checked{% endif %}>
Enable MCP Server
</label>
<small style="color: #666; display: block; margin-top: 5px;">Model Context Protocol server for remote agent configuration</small>
</div>
<div class="form-group">
<label for="autoselect_tokens">Autoselect Tokens (one per line)</label>
<textarea id="autoselect_tokens" name="autoselect_tokens" style="min-height: 80px;" placeholder="Tokens for autoselection/autorotation access">{{ '\n'.join(config.mcp.autoselect_tokens) if config.mcp.autoselect_tokens else '' }}</textarea>
<small style="color: #666; display: block; margin-top: 5px;">Tokens that give access to autoselection and autorotation settings + standard APIs</small>
</div>
<div class="form-group">
<label for="fullconfig_tokens">Full Config Tokens (one per line)</label>
<textarea id="fullconfig_tokens" name="fullconfig_tokens" style="min-height: 80px;" placeholder="Tokens for full configuration access">{{ '\n'.join(config.mcp.fullconfig_tokens) if config.mcp.fullconfig_tokens else '' }}</textarea>
<small style="color: #666; display: block; margin-top: 5px;">Tokens that give access to full system configuration + standard APIs</small>
</div>
<h3 style="margin: 30px 0 20px;">Dashboard</h3> <h3 style="margin: 30px 0 20px;">Dashboard</h3>
<div class="form-group"> <div class="form-group">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment