Spaces:
Running
Running
Implement dual-mode authentication strategy
Browse files- Space demo: Uses provided API key for demonstration (limited usage)
- MCP clients: Must provide own API key for production usage
- Check SPACE_ID environment variable to detect Hugging Face Space
- Update documentation to clarify API key requirements
- Add comprehensive authentication strategy logging
- Ensure security: client API keys required for production use
Features:
β
Space demo works with pre-configured API key
β
MCP clients must provide their own API key
β
Clear documentation for both usage modes
β
Production-ready authentication strategy
README.md
CHANGED
@@ -96,9 +96,9 @@ This Gradio app serves as both a **web interface** and a **full MCP server**, pr
|
|
96 |
|
97 |
## π§ MCP Client Configuration
|
98 |
|
99 |
-
###
|
100 |
|
101 |
-
|
102 |
|
103 |
```json
|
104 |
{
|
@@ -119,23 +119,7 @@ Add this to your Claude Desktop configuration file:
|
|
119 |
}
|
120 |
```
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
```json
|
125 |
-
{
|
126 |
-
"mcpServers": {
|
127 |
-
"a1d-gradio": {
|
128 |
-
"command": "npx",
|
129 |
-
"args": [
|
130 |
-
"mcp-remote",
|
131 |
-
"http://localhost:7860/gradio_api/mcp/sse"
|
132 |
-
]
|
133 |
-
}
|
134 |
-
}
|
135 |
-
}
|
136 |
-
```
|
137 |
-
|
138 |
-
*Note: Requires `A1D_API_KEY` environment variable to be set.*
|
139 |
|
140 |
### For Other MCP Clients
|
141 |
- **Server URL:** `http://localhost:7860/gradio_api/mcp/sse`
|
@@ -169,7 +153,9 @@ To deploy this on your own Hugging Face Space:
|
|
169 |
|
170 |
### π MCP Client Configuration for Hosted Version
|
171 |
|
172 |
-
|
|
|
|
|
173 |
|
174 |
```json
|
175 |
{
|
@@ -190,21 +176,11 @@ To deploy this on your own Hugging Face Space:
|
|
190 |
}
|
191 |
```
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
"a1d-hosted": {
|
199 |
-
"command": "npx",
|
200 |
-
"args": [
|
201 |
-
"mcp-remote",
|
202 |
-
"https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/sse"
|
203 |
-
]
|
204 |
-
}
|
205 |
-
}
|
206 |
-
}
|
207 |
-
```
|
208 |
|
209 |
## π‘ How to Use
|
210 |
|
|
|
96 |
|
97 |
## π§ MCP Client Configuration
|
98 |
|
99 |
+
### β οΈ API Key Required for Client Usage
|
100 |
|
101 |
+
When using with your own MCP client (Claude Desktop, Cursor, etc.), you **must** provide your API key:
|
102 |
|
103 |
```json
|
104 |
{
|
|
|
119 |
}
|
120 |
```
|
121 |
|
122 |
+
**π API key is mandatory for client usage.** Get your API key at [A1D.ai](https://a1d.ai/home/api).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
### For Other MCP Clients
|
125 |
- **Server URL:** `http://localhost:7860/gradio_api/mcp/sse`
|
|
|
153 |
|
154 |
### π MCP Client Configuration for Hosted Version
|
155 |
|
156 |
+
#### β οΈ API Key Required for Client Usage
|
157 |
+
|
158 |
+
When using with your own MCP client (Claude Desktop, Cursor, etc.), you **must** provide your API key:
|
159 |
|
160 |
```json
|
161 |
{
|
|
|
176 |
}
|
177 |
```
|
178 |
|
179 |
+
**π API key is mandatory for client usage.** Get your API key at [A1D.ai](https://a1d.ai/home/api).
|
180 |
|
181 |
+
#### π Using the Hosted Demo on Hugging Face Space
|
182 |
+
|
183 |
+
The hosted demo at [https://huggingface.co/spaces/aigchacker/a1d-mcp-server](https://huggingface.co/spaces/aigchacker/a1d-mcp-server) uses our provided API key for demonstration purposes only, with limited usage. For production use, please obtain your own API key.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
## π‘ How to Use
|
186 |
|
app.py
CHANGED
@@ -25,14 +25,21 @@ def get_api_client():
|
|
25 |
except:
|
26 |
pass
|
27 |
|
28 |
-
# 2.
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
|
|
|
32 |
if not api_key:
|
33 |
raise ValueError(
|
34 |
-
"API key is required.
|
35 |
|
|
|
36 |
return A1DAPIClient(api_key)
|
37 |
|
38 |
|
@@ -296,13 +303,14 @@ def create_mcp_docs():
|
|
296 |
return gr.Markdown("""
|
297 |
## π§ MCP Client Configuration
|
298 |
|
299 |
-
###
|
300 |
-
|
|
|
301 |
|
302 |
```json
|
303 |
{
|
304 |
"mcpServers": {
|
305 |
-
"a1d
|
306 |
"command": "npx",
|
307 |
"args": [
|
308 |
"mcp-remote@latest",
|
@@ -318,6 +326,16 @@ Add this configuration to your Claude Desktop settings:
|
|
318 |
}
|
319 |
```
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
### π How to Get Your A1D API Key:
|
322 |
|
323 |
1. **Visit A1D Website**: Go to [https://a1d.ai](https://a1d.ai)
|
@@ -327,6 +345,8 @@ Add this configuration to your Claude Desktop settings:
|
|
327 |
5. **Copy Your Key**: Copy the generated API key
|
328 |
6. **Replace in Config**: Replace `your_a1d_api_key_here` with your actual API key
|
329 |
|
|
|
|
|
330 |
### π Available MCP Tools:
|
331 |
- `remove_bg_wrapper` - Remove background from images
|
332 |
- `image_upscaler_wrapper` - Upscale images (2x/4x/8x/16x)
|
@@ -338,6 +358,10 @@ Add this configuration to your Claude Desktop settings:
|
|
338 |
### π MCP Endpoints:
|
339 |
- **SSE Endpoint**: `https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/sse`
|
340 |
- **Schema**: `https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/schema`
|
|
|
|
|
|
|
|
|
341 |
""")
|
342 |
|
343 |
# Create Gradio interfaces for each tool
|
@@ -535,22 +559,39 @@ def create_gradio_app():
|
|
535 |
|
536 |
|
537 |
if __name__ == "__main__":
|
538 |
-
# Check for API key
|
539 |
-
if not os.getenv("A1D_API_KEY"):
|
540 |
-
print("β Error: A1D_API_KEY environment variable is required")
|
541 |
-
print("Please set your API key: export A1D_API_KEY=your_api_key_here")
|
542 |
-
exit(1)
|
543 |
-
|
544 |
print("π Starting A1D MCP Server...")
|
545 |
-
print("=" *
|
546 |
-
|
547 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
548 |
print(
|
549 |
f"π Server: http://{GRADIO_CONFIG['server_name']}:{GRADIO_CONFIG['server_port']}")
|
550 |
print(
|
551 |
f"π§ MCP Endpoint: http://{GRADIO_CONFIG['server_name']}:{GRADIO_CONFIG['server_port']}/gradio_api/mcp/sse")
|
552 |
print(f"π Available Tools: {len(TOOLS_CONFIG)} AI tools")
|
553 |
-
|
|
|
|
|
|
|
|
|
|
|
554 |
|
555 |
# Create and launch the app
|
556 |
demo = create_gradio_app()
|
|
|
25 |
except:
|
26 |
pass
|
27 |
|
28 |
+
# 2. Check if running on Hugging Face Space
|
29 |
+
is_space = os.getenv("SPACE_ID") is not None
|
30 |
+
space_api_key = os.getenv("A1D_API_KEY")
|
31 |
+
|
32 |
+
# 3. Use environment variable only if on Hugging Face Space
|
33 |
+
if not api_key and is_space and space_api_key:
|
34 |
+
print("π‘ Using API key from Space environment variable")
|
35 |
+
return A1DAPIClient(space_api_key)
|
36 |
|
37 |
+
# 4. If not on Space or no API key provided, require user API key
|
38 |
if not api_key:
|
39 |
raise ValueError(
|
40 |
+
"API key is required. Please provide API_KEY in request headers. Get your API key at https://a1d.ai")
|
41 |
|
42 |
+
print("π Using API key from MCP client headers")
|
43 |
return A1DAPIClient(api_key)
|
44 |
|
45 |
|
|
|
303 |
return gr.Markdown("""
|
304 |
## π§ MCP Client Configuration
|
305 |
|
306 |
+
### β οΈ API Key Required for Client Usage
|
307 |
+
|
308 |
+
When using with your own MCP client (Claude Desktop, Cursor, etc.), you **must** provide your API key:
|
309 |
|
310 |
```json
|
311 |
{
|
312 |
"mcpServers": {
|
313 |
+
"a1d": {
|
314 |
"command": "npx",
|
315 |
"args": [
|
316 |
"mcp-remote@latest",
|
|
|
326 |
}
|
327 |
```
|
328 |
|
329 |
+
**π API key is mandatory for client usage.** Get your API key at [A1D.ai](https://a1d.ai/home/api).
|
330 |
+
|
331 |
+
---
|
332 |
+
|
333 |
+
### π Using the Hosted Demo on Hugging Face Space
|
334 |
+
|
335 |
+
The hosted demo at [https://huggingface.co/spaces/aigchacker/a1d-mcp-server](https://huggingface.co/spaces/aigchacker/a1d-mcp-server) uses our provided API key for demonstration purposes only, with limited usage. For production use, please obtain your own API key.
|
336 |
+
|
337 |
+
---
|
338 |
+
|
339 |
### π How to Get Your A1D API Key:
|
340 |
|
341 |
1. **Visit A1D Website**: Go to [https://a1d.ai](https://a1d.ai)
|
|
|
345 |
5. **Copy Your Key**: Copy the generated API key
|
346 |
6. **Replace in Config**: Replace `your_a1d_api_key_here` with your actual API key
|
347 |
|
348 |
+
---
|
349 |
+
|
350 |
### π Available MCP Tools:
|
351 |
- `remove_bg_wrapper` - Remove background from images
|
352 |
- `image_upscaler_wrapper` - Upscale images (2x/4x/8x/16x)
|
|
|
358 |
### π MCP Endpoints:
|
359 |
- **SSE Endpoint**: `https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/sse`
|
360 |
- **Schema**: `https://aigchacker-a1d-mcp-server.hf.space/gradio_api/mcp/schema`
|
361 |
+
|
362 |
+
### π‘ Usage Summary:
|
363 |
+
- **Hosted Demo**: Works directly in browser with provided API key
|
364 |
+
- **MCP Client**: Requires your own API key for production use
|
365 |
""")
|
366 |
|
367 |
# Create Gradio interfaces for each tool
|
|
|
559 |
|
560 |
|
561 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
print("π Starting A1D MCP Server...")
|
563 |
+
print("=" * 70)
|
564 |
+
|
565 |
+
# Check environment and show configuration
|
566 |
+
is_space = os.getenv("SPACE_ID") is not None
|
567 |
+
space_api_key = os.getenv("A1D_API_KEY")
|
568 |
+
|
569 |
+
if is_space and space_api_key:
|
570 |
+
print("β
Running on Hugging Face Space with demo API key")
|
571 |
+
print("π Web demo: Works directly with provided API key")
|
572 |
+
print("π MCP clients: Must provide their own API key")
|
573 |
+
elif is_space:
|
574 |
+
print("β οΈ Running on Hugging Face Space without API key")
|
575 |
+
print("π All users must provide their own API key")
|
576 |
+
else:
|
577 |
+
print("π₯οΈ Running locally")
|
578 |
+
if space_api_key:
|
579 |
+
print("β
Local API key found")
|
580 |
+
else:
|
581 |
+
print("π Users must provide their own API key")
|
582 |
+
|
583 |
+
print(f"\nπ― Title: {GRADIO_CONFIG['title']}")
|
584 |
print(
|
585 |
f"π Server: http://{GRADIO_CONFIG['server_name']}:{GRADIO_CONFIG['server_port']}")
|
586 |
print(
|
587 |
f"π§ MCP Endpoint: http://{GRADIO_CONFIG['server_name']}:{GRADIO_CONFIG['server_port']}/gradio_api/mcp/sse")
|
588 |
print(f"π Available Tools: {len(TOOLS_CONFIG)} AI tools")
|
589 |
+
|
590 |
+
print(f"\nπ Authentication Strategy:")
|
591 |
+
print(" - Space demo: Uses provided API key (limited usage)")
|
592 |
+
print(" - MCP clients: Must provide own API key (production usage)")
|
593 |
+
print(" - Get API key at: https://a1d.ai")
|
594 |
+
print("=" * 70)
|
595 |
|
596 |
# Create and launch the app
|
597 |
demo = create_gradio_app()
|