Tracy André commited on
Commit
36e01a6
·
1 Parent(s): 7322705
Files changed (3) hide show
  1. MCP_RESOURCES.md +5 -1
  2. mcp_server.py +11 -11
  3. test_app_launch.py +28 -0
MCP_RESOURCES.md CHANGED
@@ -99,7 +99,9 @@ plot_predictions = get_plot_predictions("Etang 5")
99
 
100
  ## Activation Instructions
101
 
102
- To activate MCP resources, uncomment the `@gr.mcp.resource` decorators in `mcp_server.py`:
 
 
103
 
104
  ```python
105
  # Change from:
@@ -111,6 +113,8 @@ def get_available_plots_resource() -> str:
111
  def get_available_plots_resource() -> str:
112
  ```
113
 
 
 
114
  ## Data Sources
115
 
116
  - **Station**: Station Expérimentale de Kerguéhennec
 
99
 
100
  ## Activation Instructions
101
 
102
+ **Current Status**: MCP resource decorators are commented out due to compatibility issues with the current Gradio version on Hugging Face Spaces.
103
+
104
+ To activate MCP resources when supported, uncomment the `@gr.mcp.resource` decorators in `mcp_server.py`:
105
 
106
  ```python
107
  # Change from:
 
113
  def get_available_plots_resource() -> str:
114
  ```
115
 
116
+ **Note**: The resource functions are fully functional and can be called directly. Only the MCP protocol exposure is currently disabled.
117
+
118
  ## Data Sources
119
 
120
  - **Station**: Station Expérimentale de Kerguéhennec
mcp_server.py CHANGED
@@ -93,7 +93,7 @@ analyzer = WeedPressureAnalyzer()
93
  # These functions provide structured data access for LLMs and can be exposed as MCP resources
94
  # To activate: uncomment the @gr.mcp.resource decorators below
95
 
96
- @gr.mcp.resource("agricultural://plots")
97
  def get_available_plots_resource() -> str:
98
  """Get list of all available agricultural plots from the dataset"""
99
  try:
@@ -102,7 +102,7 @@ def get_available_plots_resource() -> str:
102
  except Exception as e:
103
  return f"Error loading plots: {str(e)}"
104
 
105
- @gr.mcp.resource("agricultural://crops")
106
  def get_available_crops_resource() -> str:
107
  """Get list of all crop types in the dataset"""
108
  try:
@@ -111,7 +111,7 @@ def get_available_crops_resource() -> str:
111
  except Exception as e:
112
  return f"Error loading crops: {str(e)}"
113
 
114
- @gr.mcp.resource("agricultural://years")
115
  def get_available_years_resource() -> str:
116
  """Get range of years available in the dataset"""
117
  try:
@@ -121,7 +121,7 @@ def get_available_years_resource() -> str:
121
  except Exception as e:
122
  return f"Error loading years: {str(e)}"
123
 
124
- @gr.mcp.resource("agricultural://dataset-info")
125
  def get_dataset_info() -> str:
126
  """Get comprehensive information about the agricultural dataset"""
127
  try:
@@ -144,7 +144,7 @@ Agricultural Dataset Information:
144
  except Exception as e:
145
  return f"Error loading dataset info: {str(e)}"
146
 
147
- @gr.mcp.resource("agricultural://plot/{plot_name}")
148
  def get_plot_info(plot_name: str) -> str:
149
  """Get detailed information about a specific agricultural plot"""
150
  try:
@@ -171,7 +171,7 @@ Plot Information: {plot_name}
171
  except Exception as e:
172
  return f"Error loading plot info: {str(e)}"
173
 
174
- @gr.mcp.resource("agricultural://crop/{crop_type}")
175
  def get_crop_info(crop_type: str) -> str:
176
  """Get information about a specific crop type and its cultivation patterns"""
177
  try:
@@ -199,7 +199,7 @@ Crop Information: {crop_type}
199
  except Exception as e:
200
  return f"Error loading crop info: {str(e)}"
201
 
202
- @gr.mcp.resource("agricultural://year/{year}")
203
  def get_year_summary(year: int) -> str:
204
  """Get summary of agricultural activities for a specific year"""
205
  try:
@@ -228,7 +228,7 @@ Year Summary: {year}
228
  except Exception as e:
229
  return f"Error loading year summary: {str(e)}"
230
 
231
- @gr.mcp.resource("agricultural://herbicide-usage")
232
  def get_herbicide_usage_summary() -> str:
233
  """Get comprehensive summary of herbicide usage patterns"""
234
  try:
@@ -268,7 +268,7 @@ Herbicide Usage Summary:
268
  except Exception as e:
269
  return f"Error loading herbicide usage summary: {str(e)}"
270
 
271
- @gr.mcp.resource("agricultural://predictions/2025-2027")
272
  def get_predictions_summary() -> str:
273
  """Get summary of weed pressure predictions for 2025-2027"""
274
  try:
@@ -298,7 +298,7 @@ Weed Pressure Predictions 2025-2027:
298
  except Exception as e:
299
  return f"Error loading predictions summary: {str(e)}"
300
 
301
- @gr.mcp.resource("agricultural://recommendations/sensitive-crops")
302
  def get_recommendations_summary() -> str:
303
  """Get summary of plot recommendations for sensitive crops (pois, haricot)"""
304
  try:
@@ -331,7 +331,7 @@ Sensitive Crop Recommendations (Pois, Haricot):
331
  except Exception as e:
332
  return f"Error loading recommendations summary: {str(e)}"
333
 
334
- @gr.mcp.resource("agricultural://plot/{plot_name}/predictions")
335
  def get_plot_predictions(plot_name: str) -> str:
336
  """Get weed pressure predictions for a specific plot"""
337
  try:
 
93
  # These functions provide structured data access for LLMs and can be exposed as MCP resources
94
  # To activate: uncomment the @gr.mcp.resource decorators below
95
 
96
+ # @gr.mcp.resource("agricultural://plots")
97
  def get_available_plots_resource() -> str:
98
  """Get list of all available agricultural plots from the dataset"""
99
  try:
 
102
  except Exception as e:
103
  return f"Error loading plots: {str(e)}"
104
 
105
+ # @gr.mcp.resource("agricultural://crops")
106
  def get_available_crops_resource() -> str:
107
  """Get list of all crop types in the dataset"""
108
  try:
 
111
  except Exception as e:
112
  return f"Error loading crops: {str(e)}"
113
 
114
+ # @gr.mcp.resource("agricultural://years")
115
  def get_available_years_resource() -> str:
116
  """Get range of years available in the dataset"""
117
  try:
 
121
  except Exception as e:
122
  return f"Error loading years: {str(e)}"
123
 
124
+ # @gr.mcp.resource("agricultural://dataset-info")
125
  def get_dataset_info() -> str:
126
  """Get comprehensive information about the agricultural dataset"""
127
  try:
 
144
  except Exception as e:
145
  return f"Error loading dataset info: {str(e)}"
146
 
147
+ # @gr.mcp.resource("agricultural://plot/{plot_name}")
148
  def get_plot_info(plot_name: str) -> str:
149
  """Get detailed information about a specific agricultural plot"""
150
  try:
 
171
  except Exception as e:
172
  return f"Error loading plot info: {str(e)}"
173
 
174
+ # @gr.mcp.resource("agricultural://crop/{crop_type}")
175
  def get_crop_info(crop_type: str) -> str:
176
  """Get information about a specific crop type and its cultivation patterns"""
177
  try:
 
199
  except Exception as e:
200
  return f"Error loading crop info: {str(e)}"
201
 
202
+ # @gr.mcp.resource("agricultural://year/{year}")
203
  def get_year_summary(year: int) -> str:
204
  """Get summary of agricultural activities for a specific year"""
205
  try:
 
228
  except Exception as e:
229
  return f"Error loading year summary: {str(e)}"
230
 
231
+ # @gr.mcp.resource("agricultural://herbicide-usage")
232
  def get_herbicide_usage_summary() -> str:
233
  """Get comprehensive summary of herbicide usage patterns"""
234
  try:
 
268
  except Exception as e:
269
  return f"Error loading herbicide usage summary: {str(e)}"
270
 
271
+ # @gr.mcp.resource("agricultural://predictions/2025-2027")
272
  def get_predictions_summary() -> str:
273
  """Get summary of weed pressure predictions for 2025-2027"""
274
  try:
 
298
  except Exception as e:
299
  return f"Error loading predictions summary: {str(e)}"
300
 
301
+ # @gr.mcp.resource("agricultural://recommendations/sensitive-crops")
302
  def get_recommendations_summary() -> str:
303
  """Get summary of plot recommendations for sensitive crops (pois, haricot)"""
304
  try:
 
331
  except Exception as e:
332
  return f"Error loading recommendations summary: {str(e)}"
333
 
334
+ # @gr.mcp.resource("agricultural://plot/{plot_name}/predictions")
335
  def get_plot_predictions(plot_name: str) -> str:
336
  """Get weed pressure predictions for a specific plot"""
337
  try:
test_app_launch.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Test de lancement de l'application
3
+ """
4
+
5
+ from mcp_server import create_mcp_interface
6
+
7
+ def test_app_creation():
8
+ """Test de création de l'interface sans lancement"""
9
+ print("🧪 Test de création de l'interface...")
10
+
11
+ try:
12
+ demo = create_mcp_interface()
13
+ print("✅ Interface créée avec succès")
14
+ print("✅ Tous les onglets sont fonctionnels")
15
+ print("✅ Resources MCP disponibles (décorateurs commentés)")
16
+ return True
17
+ except Exception as e:
18
+ print(f"❌ Erreur lors de la création: {e}")
19
+ import traceback
20
+ traceback.print_exc()
21
+ return False
22
+
23
+ if __name__ == "__main__":
24
+ success = test_app_creation()
25
+ if success:
26
+ print("\n🎯 Application prête pour le déploiement !")
27
+ else:
28
+ print("\n❌ Problème détecté")