Rajesh Betkiker commited on
Commit
ddcdfce
Β·
1 Parent(s): a6f6ba1

Dockerized

Browse files
Files changed (5) hide show
  1. .dockerignore +7 -0
  2. Dockerfile +23 -0
  3. README.md +2 -5
  4. mcp_server.py +40 -2
  5. pyproject.toml +2 -3
.dockerignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.pyc
3
+ *.log
4
+ .venv/
5
+ logs/
6
+ *.egg-info/
7
+ *.dist-info/
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.13-slim
2
+
3
+ # Create non-root user
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+
7
+ # Environment
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+ RUN chown -R user:1000 /app
12
+
13
+ # Install pip and uv
14
+ RUN pip install --upgrade pip && pip install uv
15
+
16
+ # Copy project files
17
+ COPY --chown=user:1000 . /app
18
+
19
+ # Install dependencies
20
+ RUN uv sync --frozen
21
+
22
+ # Run the server
23
+ CMD ["uv", "run", "/app/mcp_server.py", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -3,11 +3,8 @@ title: Unit3 MCP PR Agent
3
  emoji: πŸ“š
4
  colorFrom: gray
5
  colorTo: blue
6
- sdk: gradio
7
- sdk_version: 5.34.1
8
- python_version: 3.13
9
- app_file: mcp_server.py
10
- pinned: false
11
  license: apache-2.0
12
  short_description: MCP - Server - Gets/Adds tags - HuggingFace model repository
13
  tags:
 
3
  emoji: πŸ“š
4
  colorFrom: gray
5
  colorTo: blue
6
+ sdk: docker
7
+ pinned: true
 
 
 
8
  license: apache-2.0
9
  short_description: MCP - Server - Gets/Adds tags - HuggingFace model repository
10
  tags:
mcp_server.py CHANGED
@@ -3,8 +3,10 @@
3
  Simplified MCP Server for HuggingFace Hub Tagging Operations using FastMCP
4
  """
5
 
 
6
  import os
7
  import json
 
8
  from fastmcp import FastMCP
9
  from huggingface_hub import HfApi, model_info, ModelCard, ModelCardData
10
  from huggingface_hub.utils import HfHubHTTPError
@@ -21,7 +23,6 @@ hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN else None
21
  # Create the FastMCP server
22
  mcp = FastMCP("hf-tagging-bot")
23
 
24
-
25
  @mcp.tool()
26
  def get_current_tags(repo_id: str) -> str:
27
  """Get current tags from a HuggingFace model repository"""
@@ -179,6 +180,43 @@ This PR adds the `{new_tag}` tag to the model repository.
179
  print(f"❌ add_new_tag error returning: {json_str}")
180
  return json_str
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
 
183
  if __name__ == "__main__":
184
- mcp.run(transport="sse")
 
 
3
  Simplified MCP Server for HuggingFace Hub Tagging Operations using FastMCP
4
  """
5
 
6
+ import asyncio
7
  import os
8
  import json
9
+ from fastapi import FastAPI
10
  from fastmcp import FastMCP
11
  from huggingface_hub import HfApi, model_info, ModelCard, ModelCardData
12
  from huggingface_hub.utils import HfHubHTTPError
 
23
  # Create the FastMCP server
24
  mcp = FastMCP("hf-tagging-bot")
25
 
 
26
  @mcp.tool()
27
  def get_current_tags(repo_id: str) -> str:
28
  """Get current tags from a HuggingFace model repository"""
 
180
  print(f"❌ add_new_tag error returning: {json_str}")
181
  return json_str
182
 
183
+ # Mount the MCP app as a sub-application
184
+ mcp_app = mcp.http_app()
185
+
186
+ # Create FastAPI app
187
+ app = FastAPI(
188
+ title="HF Tagging Bot - MCP Server",
189
+ description="A service that provides health endpoint and MCP tools",
190
+ version="1.0.0",
191
+ lifespan=mcp_app.router.lifespan_context,
192
+ )
193
+
194
+ app.mount("/mcp-server", mcp_app, "mcp")
195
+
196
+ @app.get("/")
197
+ async def root():
198
+ """Root endpoint with basic information"""
199
+ return {
200
+ "name": "HF Tagging Bot - MCP Server",
201
+ "status": "running",
202
+ "description": "mcp server - Webhook listener for automatic model tagging",
203
+ "tools": {
204
+ "get_current_tags": "Get current tags from a HuggingFace model repository",
205
+ "add_new_tag": "Add a new tag to a HuggingFace model repository via PR"
206
+ }
207
+ }
208
+
209
+ @app.get("/health")
210
+ async def health_check():
211
+ """Health check endpoint for monitoring"""
212
+ return {
213
+ "status": "healthy",
214
+ "components": {
215
+ "hf_token": "configured" if HF_TOKEN else "missing",
216
+ }
217
+ }
218
 
219
+ # Add a simple main block for direct execution
220
  if __name__ == "__main__":
221
+ import uvicorn
222
+ uvicorn.run("mcp_server:app", host="0.0.0.0", port=7860)
pyproject.toml CHANGED
@@ -5,10 +5,9 @@ description = "MCP - Server - Gets/Adds tags - HuggingFace model repository"
5
  readme = "README.md"
6
  requires-python = ">=3.13"
7
  dependencies = [
8
- "huggingface_hub",
9
- "gradio[mcp]",
10
  "fastmcp",
11
- "python-dotenv",
12
  ]
13
 
14
  [build-system]
 
5
  readme = "README.md"
6
  requires-python = ">=3.13"
7
  dependencies = [
8
+ "huggingface_hub[mcp]",
9
+ "fastapi",
10
  "fastmcp",
 
11
  ]
12
 
13
  [build-system]