Skip to content

Commit 4ec466c

Browse files
authored
add infra db dependency and sample tool server (#38)
add infra db dependency and sample tool server for the tool routing feature
1 parent 876bf2e commit 4ec466c

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

deployment/infra/azure-deployment.bicep

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,20 @@ resource cacheContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/cont
427427
}
428428
}
429429

430+
resource toolContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-04-15' = {
431+
name: 'ToolContainer'
432+
parent: cosmosDbSqlDb
433+
properties: {
434+
resource: {
435+
id: 'ToolContainer'
436+
partitionKey: {
437+
paths: ['/id']
438+
kind: 'Hash'
439+
}
440+
}
441+
}
442+
}
443+
430444
// Cosmos DB Data Contributor Role Assignment to UAI
431445
resource cosmosDbRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2022-11-15' = {
432446
parent: cosmosDb

deployment/infra/azure-deployment.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.38.33.27573",
8-
"templateHash": "2243900866350713366"
8+
"templateHash": "12874722858654947563"
99
}
1010
},
1111
"parameters": {
@@ -478,6 +478,25 @@
478478
"[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('cosmosDbAccountName'), 'McpGatewayDb')]"
479479
]
480480
},
481+
{
482+
"type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
483+
"apiVersion": "2023-04-15",
484+
"name": "[format('{0}/{1}/{2}', variables('cosmosDbAccountName'), 'McpGatewayDb', 'ToolContainer')]",
485+
"properties": {
486+
"resource": {
487+
"id": "ToolContainer",
488+
"partitionKey": {
489+
"paths": [
490+
"/id"
491+
],
492+
"kind": "Hash"
493+
}
494+
}
495+
},
496+
"dependsOn": [
497+
"[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('cosmosDbAccountName'), 'McpGatewayDb')]"
498+
]
499+
},
481500
{
482501
"type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments",
483502
"apiVersion": "2022-11-15",

sample-tool-server/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Simple container for the dummy score API service
2+
FROM python:3.12-slim
3+
4+
WORKDIR /app
5+
6+
# Create a non-root user
7+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
8+
9+
COPY requirements.txt ./
10+
RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
11+
12+
# Copy the application code
13+
COPY app.py ./
14+
15+
# Switch to non-root user
16+
USER appuser
17+
18+
EXPOSE 8000
19+
20+
CMD ["python", "app.py"]

sample-tool-server/app.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from fastapi import FastAPI, HTTPException
2+
from pydantic import BaseModel
3+
4+
app = FastAPI()
5+
6+
7+
class WeatherRequest(BaseModel):
8+
location: str | None = None
9+
unit: str | None = None
10+
11+
12+
@app.post("/score")
13+
async def get_weather(payload: WeatherRequest):
14+
"""Mocked weather endpoint matching the MCP tool contract."""
15+
location = payload.location
16+
unit = (payload.unit or "fahrenheit").lower()
17+
if not location:
18+
raise HTTPException(status_code=400, detail="Missing 'location' field.")
19+
if unit not in {"celsius", "fahrenheit"}:
20+
raise HTTPException(status_code=400, detail="Invalid 'unit' value.")
21+
22+
# Static temperature keeps the mock predictable for tests.
23+
base_temp_f = 72.0
24+
temperature = base_temp_f if unit == "fahrenheit" else round((base_temp_f - 32) * 5 / 9, 1)
25+
return {
26+
"location": location,
27+
"unit": unit,
28+
"temperature": temperature,
29+
"conditions": "clear",
30+
}
31+
32+
33+
if __name__ == "__main__":
34+
import uvicorn
35+
36+
uvicorn.run(app, host="0.0.0.0", port=8000)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastapi==0.111.0
2+
uvicorn[standard]==0.30.0

0 commit comments

Comments
 (0)