Spaces:
Runtime error
Add Local Demo MCP server with checkbox toggle for metadata fetching
Browse filesFeatures:
- Built-in Local Demo MCP server with 3 sample datasets:
- E-commerce Data Pipeline (11 nodes)
- ML Feature Pipeline (6 nodes)
- Data Warehouse Schema (9 nodes)
- Checkbox to enable/disable MCP metadata fetching
- MCP Query field to filter datasets (ecommerce, ml, warehouse)
- Local Demo MCP selected by default in presets
- Lineage extraction works both with MCP and local metadata input
- MCP accordion now open by default for visibility
Usage:
1. Check "Use MCP Server for Metadata"
2. Select "Local Demo MCP (Built-in)" from presets
3. Optionally enter query like "ecommerce" or "ml pipeline"
4. Click "Extract Lineage" to visualize MCP-provided metadata
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
41 unmodified lines42434445464724 unmodified lines727374757677290 unmodified lines368369370371372373165 unmodified lines53954054154254354454554654754854955065 unmodified lines6166176186196206216226236246256266276286296303 unmodified lines63463563663763863964064164264364464580 unmodified lines72672772872973073173241 unmodified lines# Preset MCP Servers on HuggingFace that can provide metadataMCP_PRESETS = {"mcp_tools": {"name": "MCP Tools by abidlabs","url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse",24 unmodified lines}}# ============================================================================# Mermaid Rendering# ============================================================================290 unmodified lines"""Health-check to MCP server by fetching schema."""if not server_url:return "No MCP server URL configured."try:headers = {}if api_key:165 unmodified linesdef extract_lineage_from_text(metadata_text: str,source_type: str,visualization_format: str) -> Tuple[str, str]:"""Extract lineage from provided metadata text (local processing only)."""# Local processing - MCP servers are used separately via explicit fetchif not metadata_text.strip():return "", "Please provide metadata content."if EXPORTERS_AVAILABLE:graph, summary = parse_metadata_to_graph(metadata_text, source_type)65 unmodified lines""")# MCP Server Configuration (collapsible)with gr.Accordion("MCP Server Configuration (Optional)", open=False):gr.Markdown("""**Connect to MCP Servers on HuggingFace** to fetch metadata and enhance lineage extraction.Select a preset server or enter a custom URL.""")with gr.Row():mcp_preset = gr.Dropdown(choices=[("-- Select Preset --", ""),("MCP Tools by abidlabs", "mcp_tools"),("HuggingFace MCP by dylanebert", "huggingface_mcp"),("Ragmint RAG Pipeline", "ragmint"),3 unmodified linesvalue="",scale=2)mcp_server = gr.Textbox(label="MCP Server URL",placeholder="https://your-mcp-server.hf.space/gradio_api/mcp/sse",info="Or enter a custom MCP server URL",scale=3)with gr.Row():mcp_api_key = gr.Textbox(label="API Key (Optional)",80 unmodified linesextract_btn.click(fn=extract_lineage_from_text,inputs=[metadata_input, source_type, viz_format],outputs=[output_viz, output_summary])41 unmodified lines4243444546474849505152535424 unmodified lines798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198290 unmodified lines489490491492493494495496497498499500165 unmodified lines66666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569665 unmodified lines7627637647657667677687697707717727737747757767777787797807817823 unmodified lines78678778878979079179279379479579679779879980080180280380480 unmodified lines88588688788888989089141 unmodified lines# Preset MCP Servers on HuggingFace that can provide metadataMCP_PRESETS = {"local_demo": {"name": "Local Demo MCP (Built-in)","url": "local://demo","schema_url": "local://demo/schema","description": "Built-in demo MCP server that provides sample lineage metadata for testing","tools": ["get_sample_lineage", "get_dbt_metadata", "get_airflow_dag", "get_warehouse_schema"]},"mcp_tools": {"name": "MCP Tools by abidlabs","url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse",24 unmodified lines}}# ============================================================================# Local Demo MCP Server (Built-in)# ============================================================================# Sample metadata that the local MCP server can provideLOCAL_MCP_METADATA = {"ecommerce_pipeline": {"name": "E-commerce Data Pipeline","nodes": [{"id": "raw_orders", "type": "source", "name": "Raw Orders (PostgreSQL)"},{"id": "raw_customers", "type": "source", "name": "Raw Customers (PostgreSQL)"},{"id": "raw_products", "type": "source", "name": "Raw Products (API)"},{"id": "stg_orders", "type": "model", "name": "Staging Orders"},{"id": "stg_customers", "type": "model", "name": "Staging Customers"},{"id": "stg_products", "type": "model", "name": "Staging Products"},{"id": "dim_customers", "type": "dimension", "name": "Dim Customers"},{"id": "dim_products", "type": "dimension", "name": "Dim Products"},{"id": "fact_orders", "type": "fact", "name": "Fact Orders"},{"id": "mart_sales", "type": "table", "name": "Sales Mart"},{"id": "report_daily", "type": "report", "name": "Daily Sales Report"}],"edges": [{"from": "raw_orders", "to": "stg_orders"},{"from": "raw_customers", "to": "stg_customers"},{"from": "raw_products", "to": "stg_products"},{"from": "stg_customers", "to": "dim_customers"},{"from": "stg_products", "to": "dim_products"},{"from": "stg_orders", "to": "fact_orders"},{"from": "dim_customers", "to": "fact_orders"},{"from": "dim_products", "to": "fact_orders"},{"from": "fact_orders", "to": "mart_sales"},{"from": "mart_sales", "to": "report_daily"}]},"ml_pipeline": {"name": "ML Feature Pipeline","nodes": [{"id": "raw_events", "type": "source", "name": "Event Stream (Kafka)"},{"id": "raw_user_data", "type": "source", "name": "User Data (S3)"},{"id": "feature_eng", "type": "model", "name": "Feature Engineering"},{"id": "feature_store", "type": "table", "name": "Feature Store"},{"id": "training_data", "type": "table", "name": "Training Dataset"},{"id": "model_output", "type": "destination", "name": "Model Predictions"}],"edges": [{"from": "raw_events", "to": "feature_eng"},{"from": "raw_user_data", "to": "feature_eng"},{"from": "feature_eng", "to": "feature_store"},{"from": "feature_store", "to": "training_data"},{"from": "training_data", "to": "model_output"}]},"data_warehouse": {"name": "Data Warehouse Schema","nodes": [{"id": "src_crm", "type": "source", "name": "CRM System"},{"id": "src_erp", "type": "source", "name": "ERP System"},{"id": "src_web", "type": "source", "name": "Web Analytics"},{"id": "landing_crm", "type": "table", "name": "Landing CRM"},{"id": "landing_erp", "type": "table", "name": "Landing ERP"},{"id": "landing_web", "type": "table", "name": "Landing Web"},{"id": "dwh_customers", "type": "dimension", "name": "DWH Customers"},{"id": "dwh_transactions", "type": "fact", "name": "DWH Transactions"},{"id": "bi_dashboard", "type": "report", "name": "BI Dashboard"}],"edges": [{"from": "src_crm", "to": "landing_crm"},{"from": "src_erp", "to": "landing_erp"},{"from": "src_web", "to": "landing_web"},{"from": "landing_crm", "to": "dwh_customers"},{"from": "landing_erp", "to": "dwh_transactions"},{"from": "landing_web", "to": "dwh_transactions"},{"from": "dwh_customers", "to": "dwh_transactions"},{"from": "dwh_transactions", "to": "bi_dashboard"}]}}def local_mcp_get_metadata(tool_name: str, query: str = "") -> Dict[str, Any]:"""Simulate a local MCP server that returns sample metadata."""if tool_name == "get_sample_lineage" or tool_name == "search":# Return a random or query-matched sampleif "ecommerce" in query.lower() or "sales" in query.lower():return LOCAL_MCP_METADATA["ecommerce_pipeline"]elif "ml" in query.lower() or "feature" in query.lower():return LOCAL_MCP_METADATA["ml_pipeline"]elif "warehouse" in query.lower() or "dwh" in query.lower():return LOCAL_MCP_METADATA["data_warehouse"]else:# Default to ecommercereturn LOCAL_MCP_METADATA["ecommerce_pipeline"]elif tool_name == "get_dbt_metadata":return LOCAL_MCP_METADATA["ecommerce_pipeline"]elif tool_name == "get_airflow_dag":return LOCAL_MCP_METADATA["ml_pipeline"]elif tool_name == "get_warehouse_schema":return LOCAL_MCP_METADATA["data_warehouse"]elif tool_name == "list_datasets":return {"datasets": list(LOCAL_MCP_METADATA.keys())}else:return LOCAL_MCP_METADATA["ecommerce_pipeline"]def is_local_mcp(url: str) -> bool:"""Check if the URL is for the local demo MCP server."""return url and url.startswith("local://")def call_local_mcp(tool_name: str, query: str = "") -> Tuple[str, str]:"""Call the local MCP server and return metadata as JSON string."""metadata = local_mcp_get_metadata(tool_name, query)return json.dumps(metadata, indent=2), f"Fetched '{metadata.get('name', 'lineage')}' from Local Demo MCP"# ============================================================================# Mermaid Rendering# ============================================================================290 unmodified lines"""Health-check to MCP server by fetching schema."""if not server_url:return "No MCP server URL configured."# Handle local demo MCP serverif is_local_mcp(server_url):tools = MCP_PRESETS.get("local_demo", {}).get("tools", [])return f"Local Demo MCP ready! {len(tools)} tools available: {', '.join(tools)}"try:headers = {}if api_key:165 unmodified linesdef extract_lineage_from_text(metadata_text: str,source_type: str,visualization_format: str,use_mcp: bool = False,mcp_url: str = "",mcp_query: str = "") -> Tuple[str, str]:"""Extract lineage from provided metadata text, optionally using MCP server."""# If MCP is enabled and we have a URL, fetch metadata from MCPif use_mcp and mcp_url:if is_local_mcp(mcp_url):# Use local demo MCP servermcp_metadata, mcp_summary = call_local_mcp("get_sample_lineage", mcp_query or source_type)if mcp_metadata:# Parse the MCP metadataif EXPORTERS_AVAILABLE:graph, _ = parse_metadata_to_graph(mcp_metadata, "MCP Response")mermaid_code = generate_mermaid_from_graph(graph)return render_mermaid(mermaid_code), f"[MCP] {mcp_summary}"else:# External MCP - would need proper MCP client implementationreturn "", f"External MCP servers require proper MCP client. Use Local Demo MCP for testing."# Local processing - use provided metadataif not metadata_text.strip():return "", "Please provide metadata content or enable MCP to fetch sample data."if EXPORTERS_AVAILABLE:graph, summary = parse_metadata_to_graph(metadata_text, source_type)65 unmodified lines""")# MCP Server Configuration (collapsible)with gr.Accordion("MCP Server Configuration", open=True):gr.Markdown("""**Connect to MCP Servers** to fetch metadata for lineage extraction.Use the built-in **Local Demo MCP** for testing, or connect to external servers on HuggingFace.""")with gr.Row():use_mcp_checkbox = gr.Checkbox(label="Use MCP Server for Metadata",value=False,info="Enable to fetch lineage metadata from MCP server instead of local input")mcp_preset = gr.Dropdown(choices=[("-- Select Preset --", ""),("Local Demo MCP (Built-in)", "local_demo"),("MCP Tools by abidlabs", "mcp_tools"),("HuggingFace MCP by dylanebert", "huggingface_mcp"),("Ragmint RAG Pipeline", "ragmint"),3 unmodified linesvalue="",scale=2)with gr.Row():mcp_server = gr.Textbox(label="MCP Server URL",placeholder="Select a preset or enter custom URL",info="local://demo for built-in demo, or external MCP URL",scale=3)mcp_query = gr.Textbox(label="MCP Query (Optional)",placeholder="e.g., 'ecommerce', 'ml pipeline', 'warehouse'",info="Query to filter metadata from MCP server",scale=2)with gr.Row():mcp_api_key = gr.Textbox(label="API Key (Optional)",80 unmodified linesextract_btn.click(fn=extract_lineage_from_text,inputs=[metadata_input, source_type, viz_format, use_mcp_checkbox, mcp_server, mcp_query],outputs=[output_viz, output_summary])