Download README.md from augustosouza/prompt-optimizer-mcp-server: direct link, hf CLI and curl.
- Browser
- Download file 5.59 kB
-
https://huggingface.co/spaces/augustosouza/prompt-optimizer-mcp-server/resolve/main/README.md
- Command line
-
hf download hf://spaces/augustosouza/prompt-optimizer-mcp-server/README.md
-
curl -L -o README.md https://huggingface.co/spaces/augustosouza/prompt-optimizer-mcp-server/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.33.0
title: Prompt Optimizer MCP Server
emoji: 💬
colorFrom: yellow
colorTo: purple
sdk: gradio
sdk_version: 5.37.0
app_file: app.py
pinned: false
license: mit
An example chatbot using Gradio, huggingface_hub, and the Hugging Face Inference API.
Prompt Optimizer — MCP Server (Hugging Face Spaces)
This repo exposes a Model Context Protocol (MCP) server—backed by a Gradio app—that provides three prompt‑engineering tools your clients (e.g., agents, apps, or the companion Chrome extension via a proxy) can call. Under the hood it uses Groq’s llama-3.3-70b-versatile model.
What it provides
Three tools (each returns plain text, no commentary):
One‑shot Optimization ID:
one_shot_optimizationInput: Free‑text prompt idea (optionally include a tone like “Technical writing tone”). Output: A single optimized prompt.Five Q&A → 3 Follow‑ups ID:
five_questions_analysis_and_followup_generationInput: Exactly 5 question–answer pairs describing the task. Output: Exactly three numbered follow‑up questions.Eight Q&A → Final Prompt ID:
eight_questions_analysis_and_prompt_generationInput: Exactly 8 question–answer pairs describing scope, constraints, audience, etc. Output: A complete, ready‑to‑paste final prompt.
Project structure
app.py # Gradio + MCP server with 3 tools
README.md # You are here
requirements.txt # gradio, groq, textblob, requests, (optional) python-dotenv
Requirements
- Python 3.10+
- Environment variable:
GROQ_API_KEY - Python packages:
gradio,groq,textblob,requests(and optionallypython-dotenvfor local dev)
Example requirements.txt:
gradio
textblob
requests
groq
python-dotenv
Running locally
Install dependencies:
pip install -r requirements.txtSet your key:
export GROQ_API_KEY=your_keyStart the server:
python app.pyThis launches Gradio and an MCP server (
demo.launch(mcp_server=True)). The console shows the local URL.
Deploying on Hugging Face Spaces
Create a new Gradio Space.
Add files:
app.py,requirements.txt,README.md.In Settings → Secrets, add
GROQ_API_KEY.Commit and let the Space build. When it’s running, you’ll have:
- A web UI with three tabs (for quick testing).
- An MCP server endpoint exposed by Gradio (path printed in Space logs). Often available at
<SPACE_URL>/mcp.
If you use this server from a browser extension, route calls through a small proxy (e.g., Flask) so you don’t expose API keys.
Calling via HTTP (Gradio REST API)
Each tool is given an api_name, so Gradio exposes simple JSON endpoints. The payload uses Gradio’s { "data": [ ... ] } format.
1) One‑shot Optimization
curl -X POST https://<SPACE_URL>/api/one_shot_optimization \
-H "Content-Type: application/json" \
-d '{"data": ["Rewrite my prompt to draft a professional email about… (Technical writing tone)"]}'
Response (abridged):
{"data": ["<optimized prompt here>"]}
2) Five Q&A → 3 Follow‑ups
curl -X POST https://<SPACE_URL>/api/five_questions_analysis_and_followup_generation \
-H "Content-Type: application/json" \
-d '{"data": ["1) Q: … A: …\n2) Q: … A: …\n3) Q: … A: …\n4) Q: … A: …\n5) Q: … A: …"]}'
Response (abridged):
{"data": ["1. …?\n2. …?\n3. …?"]}
3) Eight Q&A → Final Prompt
curl -X POST https://<SPACE_URL>/api/eight_questions_analysis_and_prompt_generation \
-H "Content-Type: application/json" \
-d '{"data": ["1) Q: … A: …\n…\n8) Q: … A: …"]}'
Response (abridged):
{"data": ["<final, ready-to-paste prompt>"]}
Consuming as an MCP tool server
Use any MCP client that supports SSE connections to an MCP server. The URL is the Space URL (the exact MCP path is printed in the Space logs; commonly /mcp).
Example (Python pseudo‑code with Agno):
from agno.tools.mcp import MCPTools, SSEClientParams
mcp = MCPTools(
server_params=SSEClientParams(server_url="https://<SPACE_URL>/mcp"),
transport="sse",
)
# Then call tools by ID, passing the text payload expected by each function
Behavior guarantees
- Deterministic output format: Each tool returns only the text specified (no extra commentary).
- Model:
llama-3.3-70b-versatilevia Groq’s Chat Completions API. - Language: English by default; content/tone follows user input.
Troubleshooting
- 401/403 or empty output: Check
GROQ_API_KEYis set in your env/Space Secrets. - MCP client can’t connect: Confirm the Space is running and that you’re using the correct MCP path (see Space logs). Some platforms require HTTPS and support only Server‑Sent Events for transport.
- Gradio HTTP calls fail: Ensure you’re posting to
/api/<api_name>with JSON body{"data": ["..."]}. - Model quota/rate limit: Verify your Groq account has sufficient quota.
Privacy & data
This server is stateless. Inputs are sent to Groq to generate outputs; no data is persisted by the app. Consider adding your own logging/retention policy if needed.