phil71x commited on
Commit
ae7ffd8
·
1 Parent(s): 3be532c

docs: Add troubleshooting tips and deployment instructions for Hugging Face Spaces to MCP server documentation

Browse files
Files changed (1) hide show
  1. docs/01_mcp_server.md +67 -1
docs/01_mcp_server.md CHANGED
@@ -120,7 +120,73 @@ Gradio significantly simplifies exposing a Python function as an MCP tool:
120
 
121
  3. **MCP Endpoint**: Gradio hosts the MCP service at a specific path (usually `/gradio_api/mcp/sse` relative to the base URL), handling the JSON-RPC communication required by MCP.
122
 
123
- ## 6. Conclusion for Part 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  We have successfully built the server-side component of our application. This server uses Gradio to:
126
  * Provide a web UI for direct interaction with our `sentiment_analysis` function.
 
120
 
121
  3. **MCP Endpoint**: Gradio hosts the MCP service at a specific path (usually `/gradio_api/mcp/sse` relative to the base URL), handling the JSON-RPC communication required by MCP.
122
 
123
+ ## 7. Troubleshooting Tips
124
+
125
+ 1. **Type Hints and Docstrings**:
126
+ * Always provide type hints for your function parameters and return values.
127
+ * Include a docstring with an "Args:" block for each parameter.
128
+ * This helps Gradio generate accurate MCP tool schemas.
129
+ 2. **String Inputs**:
130
+ * When in doubt, accept input arguments as `str`.
131
+ * Convert them to the desired type inside the function.
132
+ * This provides better compatibility with MCP clients.
133
+ 3. **SSE Support**:
134
+ * Some MCP clients don't support SSE-based MCP Servers.
135
+ * In those cases, use `mcp-remote`:
136
+
137
+ ```json
138
+ {
139
+ "mcpServers": {
140
+ "gradio": {
141
+ "command": "npx",
142
+ "args": [
143
+ "mcp-remote",
144
+ "http://localhost:7860/gradio_api/mcp/sse"
145
+ ]
146
+ }
147
+ }
148
+ }
149
+ ```
150
+ 4. **Connection Issues**:
151
+ * If you encounter connection problems, try restarting both the client and server.
152
+ * Check that the server is running and accessible.
153
+ * Verify that the MCP schema is available at the expected URL (e.g., `http://localhost:7860/gradio_api/mcp/schema`).
154
+
155
+ ## 8. Deploying to Hugging Face Spaces
156
+
157
+ To make your server available to others, you can deploy it to Hugging Face Spaces:
158
+
159
+ 1. **Create a new Space on Hugging Face:**
160
+ * Go to [huggingface.co/spaces](https://huggingface.co/spaces)
161
+ * Click "Create new Space"
162
+ * Choose "Gradio" as the SDK
163
+ * Name your space (e.g., "mcp-sentiment")
164
+ 2. **Create a `requirements.txt` file:**
165
+
166
+ ```
167
+ gradio[mcp]
168
+ textblob
169
+ ```
170
+
171
+ 3. **Push your code to the Space:**
172
+
173
+ ```bash
174
+ git init
175
+ git add app.py requirements.txt
176
+ git commit -m "Initial commit"
177
+ git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/mcp-sentiment
178
+ git push -u origin main
179
+ ```
180
+
181
+ Your MCP server will now be available at:
182
+
183
+ ```
184
+ https://YOUR_USERNAME-mcp-sentiment.hf.space/gradio_api/mcp/sse
185
+ ```
186
+
187
+ For more details, see the [Hugging Face MCP Course documentation](https://huggingface.co/learn/mcp-course/unit2/gradio-server).
188
+
189
+ ## 9. Conclusion for Part 1
190
 
191
  We have successfully built the server-side component of our application. This server uses Gradio to:
192
  * Provide a web UI for direct interaction with our `sentiment_analysis` function.