jimfhahn commited on
Commit
4f508d7
Β·
verified Β·
1 Parent(s): 24b611a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -10
app.py CHANGED
@@ -462,7 +462,25 @@ MANUAL CORRECTION STEPS:
462
  -->"""
463
 
464
  def validate_rdf_interface(rdf_content: str, template: str, use_ai: bool = True):
465
- """Main validation function for Gradio interface"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  if not rdf_content.strip():
467
  return "❌ Error", "No RDF/XML data provided", "", ""
468
 
@@ -493,13 +511,18 @@ def get_rdf_examples(example_type: str = "valid") -> str:
493
  Retrieve example RDF/XML snippets for testing and learning.
494
 
495
  This tool provides sample RDF/XML content that can be used to test
496
- the validation system or learn proper RDF structure.
 
 
497
 
498
  Args:
499
- example_type (str): Type of example ('valid', 'invalid', or 'bibframe')
 
 
 
500
 
501
  Returns:
502
- str: RDF/XML example content
503
  """
504
  examples = {
505
  "valid": SAMPLE_VALID_RDF,
@@ -700,17 +723,36 @@ def create_interface():
700
  ### πŸ”§ **MCP Server Mode:**
701
  This app functions as both a web interface AND an MCP server for Claude Desktop and other MCP clients.
702
 
703
- **Available MCP Tools (via SSE):**
704
  - `validate_rdf_tool`: Validate RDF/XML against SHACL shapes
705
  - `get_ai_suggestions`: Get AI-powered fix suggestions
706
  - `get_ai_correction`: Generate corrected RDF/XML
707
  - `get_rdf_examples`: Retrieve example RDF snippets
 
 
 
 
708
 
709
- **MCP Connection:**
710
- 1. When deployed on Hugging Face Spaces, the MCP server is available at:
711
- `https://your-space-id.hf.space/gradio_api/mcp/sse`
712
- 2. Use this URL in Claude Desktop's MCP configuration
713
- 3. The app automatically exposes functions with proper docstrings as MCP tools
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
714
 
715
  ### πŸ’‘ **Features:**
716
  - βœ… Real-time RDF/XML validation against SHACL schemas
 
462
  -->"""
463
 
464
  def validate_rdf_interface(rdf_content: str, template: str, use_ai: bool = True):
465
+ """
466
+ Main validation function for Gradio interface and MCP server.
467
+
468
+ This function provides comprehensive RDF/XML validation with AI-powered
469
+ suggestions and corrections. It serves as the primary interface for both
470
+ the Gradio web UI and MCP client tools.
471
+
472
+ Args:
473
+ rdf_content (str): The RDF/XML content to validate
474
+ template (str): Validation template to use ('monograph' or 'custom')
475
+ use_ai (bool): Whether to enable AI-powered suggestions and corrections
476
+
477
+ Returns:
478
+ tuple: (status, results_text, suggestions, corrected_rdf) containing:
479
+ - status: Validation status message
480
+ - results_text: Detailed validation results
481
+ - suggestions: AI or manual fix suggestions
482
+ - corrected_rdf: AI-generated corrections or success message
483
+ """
484
  if not rdf_content.strip():
485
  return "❌ Error", "No RDF/XML data provided", "", ""
486
 
 
511
  Retrieve example RDF/XML snippets for testing and learning.
512
 
513
  This tool provides sample RDF/XML content that can be used to test
514
+ the validation system or learn proper RDF structure. Examples include
515
+ valid BibFrame Work records, invalid records for testing corrections,
516
+ and BibFrame Instance records.
517
 
518
  Args:
519
+ example_type (str): Type of example to retrieve. Options:
520
+ - 'valid': A complete, valid BibFrame Work record
521
+ - 'invalid': An incomplete BibFrame Work with validation errors
522
+ - 'bibframe': A BibFrame Instance record example
523
 
524
  Returns:
525
+ str: Complete RDF/XML example content ready for validation testing
526
  """
527
  examples = {
528
  "valid": SAMPLE_VALID_RDF,
 
723
  ### πŸ”§ **MCP Server Mode:**
724
  This app functions as both a web interface AND an MCP server for Claude Desktop and other MCP clients.
725
 
726
+ **Available MCP Tools:**
727
  - `validate_rdf_tool`: Validate RDF/XML against SHACL shapes
728
  - `get_ai_suggestions`: Get AI-powered fix suggestions
729
  - `get_ai_correction`: Generate corrected RDF/XML
730
  - `get_rdf_examples`: Retrieve example RDF snippets
731
+ - `validate_rdf_interface`: Complete validation with AI suggestions and corrections (primary tool)
732
+
733
+ **MCP Configuration (Streamable HTTP):**
734
+ Add this configuration to your MCP client (Claude Desktop, etc.):
735
 
736
+ ```json
737
+ {
738
+ "mcpServers": {
739
+ "rdf-validator": {
740
+ "url": "https://jimfhahn-mcp4rdf.hf.space/gradio_api/mcp/"
741
+ }
742
+ }
743
+ }
744
+ ```
745
+
746
+ **Alternative SSE Configuration:**
747
+ ```json
748
+ {
749
+ "mcpServers": {
750
+ "rdf-validator": {
751
+ "url": "https://jimfhahn-mcp4rdf.hf.space/gradio_api/mcp/sse"
752
+ }
753
+ }
754
+ }
755
+ ```
756
 
757
  ### πŸ’‘ **Features:**
758
  - βœ… Real-time RDF/XML validation against SHACL schemas