Skip to content

Commit 4dd097a

Browse files
authored
Fix workflow test fix and server header addition (#366)
* Fix workflow * pin setuptools due to newer version not having pkg_resources * fix server header
1 parent 7890092 commit 4dd097a

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

.github/workflows/pr-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ jobs:
252252
pip3 install virtualenv
253253
virtualenv venv
254254
source venv/bin/activate
255-
pip install --upgrade pip setuptools
255+
pip install --upgrade pip
256+
pip install setuptools>=70.0.0
256257
pip install -r requirements.txt
257258
pip install -r dev-requirements.txt
258259
mkdir -p test-results

services/chatbot/src/mcpserver/server.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import os
44
import time
55

6+
from importlib.metadata import version
7+
68
import httpx
9+
import uvicorn
710
from fastmcp import FastMCP
811
from starlette.middleware import Middleware
912

@@ -143,17 +146,40 @@ async def debug_web_service(path: str = "") -> dict:
143146
if __name__ == "__main__":
144147
mcp_server_port = int(os.environ.get("MCP_SERVER_PORT", 5500))
145148

149+
150+
class ServerHeaderMiddleware:
151+
def __init__(self, app):
152+
self.app = app
153+
self.server_header = f"FastMCP/{version('FastMCP')}".encode()
154+
155+
async def __call__(self, scope, receive, send):
156+
if scope["type"] == "http":
157+
async def send_with_header(message):
158+
if message["type"] == "http.response.start":
159+
headers = [
160+
(k, v) for k, v in message.get("headers", [])
161+
if k != b"server"
162+
]
163+
headers.append((b"server", self.server_header))
164+
message["headers"] = headers
165+
await send(message)
166+
await self.app(scope, receive, send_with_header)
167+
else:
168+
await self.app(scope, receive, send)
169+
146170
# Auth middleware to validate requests against identity service
147171
middleware = [
172+
Middleware(ServerHeaderMiddleware),
148173
Middleware(
149174
MCPAuthMiddleware,
150175
identity_service_url=BASE_IDENTITY_URL,
151-
)
176+
),
152177
]
153178

154-
mcp.run(
155-
transport="streamable-http",
179+
app = mcp.streamable_http_app(middleware=middleware)
180+
uvicorn.run(
181+
app,
156182
host="0.0.0.0",
157183
port=mcp_server_port,
158-
middleware=middleware,
184+
server_header=False,
159185
)

services/workshop/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ FROM python:3.11-alpine
3939
COPY --from=build /app /app
4040
WORKDIR /app
4141
RUN apk update && apk add --no-cache postgresql-libs curl cairo
42-
RUN pip install setuptools
42+
RUN pip install "setuptools>=70.0.0,<82"
4343
RUN pip install --no-index --find-links=/app/wheels -r requirements.txt
4444
COPY ./certs /app/certs
4545
COPY health.sh /app/health.sh

services/workshop/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
setuptools>=70.0.0,<82
12
bcrypt==4.1.2
23
Django~=4.1.13
34
cryptography==40.0.2

0 commit comments

Comments
 (0)