Skip to content

Commit dbf1022

Browse files
committed
Refactor MCP server with modular architecture and stateless HTTP support
Major refactoring to improve code organization, testing, and HTTP transport: - Fix stateless HTTP mode by moving stateless_http parameter to run() method - Extract tools into separate modules (chat.py, search.py, datasources.py) - Add comprehensive test suite (76% coverage with 27 passing tests) - Implement XML response transformer for 60-90% token reduction in search results - Add shared error handling utilities and data source conversion helpers - Create modular core components (client.py, config.py, logging.py) - Simplify chat API to accept string IDs instead of complex objects - Add request ID tracing for better debugging - Clean up unnecessary files and comments - Add .mcp.json to .gitignore for local configuration This refactoring improves maintainability, reduces code duplication from ~1140 lines, and ensures the server works reliably with both stdio and stateless HTTP transports.
1 parent 781f545 commit dbf1022

20 files changed

+1925
-862
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,6 @@ cython_debug/
178178

179179
# JetBrains IDE
180180
.idea/
181+
182+
# MCP configuration file
183+
.mcp.json

Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ RUN apt-get update \
1010
&& apt-get install -y --no-install-recommends gcc libssl-dev \
1111
&& rm -rf /var/lib/apt/lists/*
1212

13-
# Install Python dependencies
14-
RUN pip install --no-cache-dir \
15-
fastmcp>=2.0.0 \
16-
httpx>=0.26.0 \
17-
python-dotenv>=1.0.0
18-
19-
# Copy application code
13+
# Copy application code first
2014
COPY . /app
2115

16+
# Install the package using pyproject.toml
17+
RUN pip install --no-cache-dir -e .
18+
2219
# Expose port for HTTP transport
2320
EXPOSE 8000
2421

pyproject.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ name = "codealive-mcp"
33
version = "0.2.0"
44
description = "MCP server for the CodeAlive API"
55
readme = "README.md"
6-
requires-python = "~=3.11.0"
6+
requires-python = ">=3.11"
77
dependencies = [
8-
"fastmcp>=2.0.0",
9-
"httpx>=0.26.0",
10-
"python-dotenv>=1.0.0",
11-
"loguru>=0.7.0",
8+
"fastmcp==2.12.3",
9+
"httpx==0.28.1",
10+
"python-dotenv==1.1.1",
11+
]
12+
13+
[project.optional-dependencies]
14+
test = [
15+
"pytest==8.3.6",
16+
"pytest-asyncio==0.25.2",
17+
"pytest-mock==3.15.0",
18+
"pytest-cov==6.0.0",
1219
]
1320

1421
[project.scripts]
@@ -20,4 +27,4 @@ build-backend = "setuptools.build_meta"
2027

2128
[tool.setuptools]
2229
packages = ["src"]
23-
package-dir = {"" = "."}
30+
package-dir = {"" = "."}

0 commit comments

Comments
 (0)