RDF Validation Deployment commited on
Commit
1487636
·
1 Parent(s): 28bc89c

Clean fix: MCP server with proper JSON returns and startup logging - 2025-10-04 15:14:29

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -206,11 +206,11 @@ def get_property_info(property_uri: str) -> str:
206
  if not prop_info:
207
  # Find partial matches
208
  matches = [k for k in kb.properties.keys() if property_uri.lower() in k.lower()]
209
- return {
210
  "error": f"Property '{property_uri}' not found in BIBFRAME ontology",
211
  "suggestions": matches[:10] if matches else list(kb.properties.keys())[:10],
212
  "total_properties": len(kb.properties)
213
- }
214
 
215
  # Generate examples based on range
216
  examples = _generate_property_examples(property_uri, prop_info)
@@ -250,11 +250,11 @@ def get_class_info(class_name: str) -> str:
250
  if not class_info:
251
  # Find partial matches
252
  matches = [k for k in kb.classes.keys() if class_name.lower() in k.lower()]
253
- return {
254
  "error": f"Class '{class_name}' not found in BIBFRAME ontology",
255
  "suggestions": matches[:10] if matches else list(kb.classes.keys())[:10],
256
  "total_classes": len(kb.classes)
257
- }
258
 
259
  # Find properties that have this class in their domain
260
  applicable_properties = []
@@ -346,7 +346,7 @@ def get_property_usage(property_name: str, class_name: str = "") -> str:
346
  prop_info = kb.properties.get(property_name, {})
347
 
348
  if not prop_info:
349
- return {"error": f"Property '{property_name}' not found in BIBFRAME ontology"}
350
 
351
  usage = {
352
  "property": property_name,
@@ -507,10 +507,18 @@ def create_interface():
507
  return demo
508
 
509
  if __name__ == "__main__":
 
 
 
 
 
 
510
  demo = create_interface()
 
 
511
  demo.launch(
512
  server_name="0.0.0.0",
513
  server_port=7860,
514
  show_api=True,
515
- mcp_server=True # Enable MCP server
516
  )
 
206
  if not prop_info:
207
  # Find partial matches
208
  matches = [k for k in kb.properties.keys() if property_uri.lower() in k.lower()]
209
+ return json.dumps({
210
  "error": f"Property '{property_uri}' not found in BIBFRAME ontology",
211
  "suggestions": matches[:10] if matches else list(kb.properties.keys())[:10],
212
  "total_properties": len(kb.properties)
213
+ }, indent=2)
214
 
215
  # Generate examples based on range
216
  examples = _generate_property_examples(property_uri, prop_info)
 
250
  if not class_info:
251
  # Find partial matches
252
  matches = [k for k in kb.classes.keys() if class_name.lower() in k.lower()]
253
+ return json.dumps({
254
  "error": f"Class '{class_name}' not found in BIBFRAME ontology",
255
  "suggestions": matches[:10] if matches else list(kb.classes.keys())[:10],
256
  "total_classes": len(kb.classes)
257
+ }, indent=2)
258
 
259
  # Find properties that have this class in their domain
260
  applicable_properties = []
 
346
  prop_info = kb.properties.get(property_name, {})
347
 
348
  if not prop_info:
349
+ return json.dumps({"error": f"Property '{property_name}' not found in BIBFRAME ontology"}, indent=2)
350
 
351
  usage = {
352
  "property": property_name,
 
507
  return demo
508
 
509
  if __name__ == "__main__":
510
+ print("🚀 Starting BIBFRAME MCP Server...")
511
+
512
+ # Force ontology loading to show progress
513
+ kb.load_ontology()
514
+ print(f"✅ Loaded {len(kb.properties)} properties and {len(kb.classes)} classes")
515
+
516
  demo = create_interface()
517
+ print("🔧 Launching with MCP server enabled...")
518
+
519
  demo.launch(
520
  server_name="0.0.0.0",
521
  server_port=7860,
522
  show_api=True,
523
+ mcp_server=True # Enable MCP server at /gradio_api/mcp/sse
524
  )