Spaces:
Sleeping
Sleeping
Merge pull request #3 from humandotlearning/feature/hf-spaces-mcp
Browse files- app.py +72 -0
- pyproject.toml +8 -0
- requirements.txt +2 -0
- uv.lock +0 -0
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from typing import List, Optional
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
# Ensure src is in python path
|
| 7 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
|
| 8 |
+
|
| 9 |
+
from npi_mcp_server.tools import search_providers, get_provider_by_npi
|
| 10 |
+
from npi_mcp_server.schemas import ProviderSummary, ProviderDetail
|
| 11 |
+
|
| 12 |
+
async def search_providers_tool(query: str, state: str = None, taxonomy: str = None) -> List[dict]:
|
| 13 |
+
"""
|
| 14 |
+
Search for healthcare providers via the NPI API.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
query: Name (first/last) or organization name.
|
| 18 |
+
state: Two-letter state code.
|
| 19 |
+
taxonomy: Taxonomy code or description.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
List of ProviderSummary objects as dictionaries.
|
| 23 |
+
"""
|
| 24 |
+
results = await search_providers(query, state, taxonomy)
|
| 25 |
+
return [r.model_dump() for r in results]
|
| 26 |
+
|
| 27 |
+
async def get_provider_by_npi_tool(npi: str) -> Optional[dict]:
|
| 28 |
+
"""
|
| 29 |
+
Retrieve details for a specific provider by NPI.
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
npi: 10-digit NPI string.
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
ProviderDetail object as dictionary or None if not found.
|
| 36 |
+
"""
|
| 37 |
+
result = await get_provider_by_npi(npi)
|
| 38 |
+
if result:
|
| 39 |
+
return result.model_dump()
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
with gr.Blocks() as demo:
|
| 43 |
+
gr.Markdown("# NPI Registry MCP Server")
|
| 44 |
+
gr.Markdown("This interface exposes NPI Registry tools as an MCP server.")
|
| 45 |
+
|
| 46 |
+
with gr.Tab("Search Providers"):
|
| 47 |
+
with gr.Row():
|
| 48 |
+
query_input = gr.Textbox(label="Query", placeholder="Name or Organization")
|
| 49 |
+
state_input = gr.Textbox(label="State", placeholder="2-letter code (e.g., CA)")
|
| 50 |
+
taxonomy_input = gr.Textbox(label="Taxonomy", placeholder="Taxonomy code")
|
| 51 |
+
search_btn = gr.Button("Search")
|
| 52 |
+
search_output = gr.JSON(label="Results")
|
| 53 |
+
|
| 54 |
+
search_btn.click(
|
| 55 |
+
fn=search_providers_tool,
|
| 56 |
+
inputs=[query_input, state_input, taxonomy_input],
|
| 57 |
+
outputs=search_output
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
with gr.Tab("Get Provider by NPI"):
|
| 61 |
+
npi_input = gr.Textbox(label="NPI", placeholder="10-digit NPI")
|
| 62 |
+
get_btn = gr.Button("Get Details")
|
| 63 |
+
get_output = gr.JSON(label="Provider Details")
|
| 64 |
+
|
| 65 |
+
get_btn.click(
|
| 66 |
+
fn=get_provider_by_npi_tool,
|
| 67 |
+
inputs=[npi_input],
|
| 68 |
+
outputs=get_output
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
demo.launch(mcp_server=True)
|
pyproject.toml
CHANGED
|
@@ -9,6 +9,7 @@ dependencies = [
|
|
| 9 |
"httpx>=0.24.0",
|
| 10 |
"pydantic>=2.0.0",
|
| 11 |
"mcp>=1.0.0",
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
[project.optional-dependencies]
|
|
@@ -29,3 +30,10 @@ packages = ["src/npi_mcp_server"]
|
|
| 29 |
pythonpath = ["src"]
|
| 30 |
testpaths = ["tests"]
|
| 31 |
asyncio_mode = "auto"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"httpx>=0.24.0",
|
| 10 |
"pydantic>=2.0.0",
|
| 11 |
"mcp>=1.0.0",
|
| 12 |
+
"gradio[mcp]>=6.0.1",
|
| 13 |
]
|
| 14 |
|
| 15 |
[project.optional-dependencies]
|
|
|
|
| 30 |
pythonpath = ["src"]
|
| 31 |
testpaths = ["tests"]
|
| 32 |
asyncio_mode = "auto"
|
| 33 |
+
|
| 34 |
+
[dependency-groups]
|
| 35 |
+
dev = [
|
| 36 |
+
"pytest>=9.0.1",
|
| 37 |
+
"pytest-asyncio>=1.3.0",
|
| 38 |
+
"pytest-mock>=3.15.1",
|
| 39 |
+
]
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
.
|
uv.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|