Skip to content

Commit babc325

Browse files
authored
Merge pull request #8 from tumf/devin/1745046602-docker-support
Docker Support (replaces PR #6)
2 parents 626f9ed + 74cb5ca commit babc325

12 files changed

+94
-14
lines changed

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS uv
3+
4+
# Install the project into `/app`
5+
WORKDIR /app
6+
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
9+
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
12+
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev --no-editable
18+
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD . /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
uv sync --frozen --no-dev --no-editable
24+
25+
FROM python:3.13-slim-bookworm
26+
27+
WORKDIR /app
28+
29+
# COPY --from=uv /root/.local /root/.local
30+
COPY --from=uv --chown=app:app /app/.venv /app/.venv
31+
32+
# Copy the source code
33+
COPY --from=uv --chown=app:app /app/src /app/src
34+
35+
# Place executables in the environment at the front of the path
36+
ENV PATH="/app/.venv/bin:$PATH"
37+
38+
# Run mcp server
39+
ENTRYPOINT ["python", "src/mcp_text_editor/server.py"]

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ code ~/Library/Application\ Support/Claude/claude_desktop_config.json
2727
}
2828
```
2929

30+
or with docker:
31+
```json
32+
{
33+
"mcpServers": {
34+
"text-editor": {
35+
"command": "docker",
36+
"args": [
37+
"run",
38+
"-i",
39+
"--rm",
40+
"--mount",
41+
"type=bind,src=/some/path/src,dst=/some/path/dst",
42+
"mcp/text-editor"
43+
]
44+
}
45+
}
46+
}
47+
```
48+
3049
## Overview
3150

3251
MCP Text Editor Server is designed to facilitate safe and efficient line-based text file operations in a client-server architecture. It implements the Model Context Protocol, ensuring reliable file editing with robust conflict detection and resolution. The line-oriented approach makes it ideal for applications requiring synchronized file access, such as collaborative editing tools, automated text processing systems, or any scenario where multiple processes need to modify text files safely. The partial file access capability is particularly valuable for LLM-based tools, as it helps reduce token consumption by loading only the necessary portions of files.
@@ -113,6 +132,11 @@ pyenv install 3.13.0
113132
pyenv local 3.13.0
114133
```
115134

135+
### Docker Installation
136+
```
137+
docker build --network=host -t mcp/text-editor .
138+
```
139+
116140
2. Install uv (recommended) or pip
117141

118142
```bash
@@ -135,6 +159,18 @@ Start the server:
135159
python -m mcp_text_editor
136160
```
137161

162+
Start the server with docker:
163+
164+
```bash
165+
docker run -i --rm --mount "type=bind,src=/some/path/src,dst=/some/path/dst" mcp/text-editor
166+
```
167+
168+
with inspector:
169+
170+
```bash
171+
npx @modelcontextprotocol/inspector docker run -i --rm --mount "type=bind,src=/some/path/src,dst=/some/path/dst" mcp/text-editor
172+
```
173+
138174
### MCP Tools
139175

140176
The server provides several tools for text file manipulation:

src/mcp_text_editor/handlers/append_text_file_contents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mcp.types import TextContent, Tool
1010

11-
from .base import BaseHandler
11+
from mcp_text_editor.handlers.base import BaseHandler
1212

1313
logger = logging.getLogger("mcp-text-editor")
1414

src/mcp_text_editor/handlers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from mcp.types import TextContent, Tool
66

7-
from ..text_editor import TextEditor
7+
from mcp_text_editor.text_editor import TextEditor
88

99

1010
class BaseHandler:

src/mcp_text_editor/handlers/create_text_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mcp.types import TextContent, Tool
1010

11-
from .base import BaseHandler
11+
from mcp_text_editor.handlers.base import BaseHandler
1212

1313
logger = logging.getLogger("mcp-text-editor")
1414

src/mcp_text_editor/handlers/delete_text_file_contents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from mcp.types import TextContent, Tool
1010

11-
from ..models import DeleteTextFileContentsRequest, FileRange
12-
from .base import BaseHandler
11+
from mcp_text_editor.handlers.base import BaseHandler
12+
from mcp_text_editor.models import DeleteTextFileContentsRequest, FileRange
1313

1414
logger = logging.getLogger("mcp-text-editor")
1515

src/mcp_text_editor/handlers/get_text_file_contents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from mcp.types import TextContent, Tool
88

9-
from .base import BaseHandler
9+
from mcp_text_editor.handlers.base import BaseHandler
1010

1111

1212
class GetTextFileContentsHandler(BaseHandler):

src/mcp_text_editor/handlers/insert_text_file_contents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mcp.types import TextContent, Tool
1010

11-
from .base import BaseHandler
11+
from mcp_text_editor.handlers.base import BaseHandler
1212

1313
logger = logging.getLogger("mcp-text-editor")
1414

src/mcp_text_editor/handlers/patch_text_file_contents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mcp.types import TextContent, Tool
1010

11-
from .base import BaseHandler
11+
from mcp_text_editor.handlers.base import BaseHandler
1212

1313
logger = logging.getLogger("mcp-text-editor")
1414

src/mcp_text_editor/server.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""MCP Text Editor Server implementation."""
22

3+
import asyncio
34
import logging
45
import traceback
56
from collections.abc import Sequence
@@ -8,21 +9,21 @@
89
from mcp.server import Server
910
from mcp.types import TextContent, Tool
1011

11-
from .handlers import (
12+
from mcp_text_editor.handlers import (
1213
AppendTextFileContentsHandler,
1314
CreateTextFileHandler,
1415
DeleteTextFileContentsHandler,
1516
GetTextFileContentsHandler,
1617
InsertTextFileContentsHandler,
1718
PatchTextFileContentsHandler,
1819
)
19-
from .version import __version__
20+
from mcp_text_editor.version import __version__
2021

2122
# Configure logging
2223
logging.basicConfig(level=logging.INFO)
2324
logger = logging.getLogger("mcp-text-editor")
2425

25-
app = Server("mcp-text-editor")
26+
app: Server = Server("mcp-text-editor")
2627

2728
# Initialize tool handlers
2829
get_contents_handler = GetTextFileContentsHandler()
@@ -88,3 +89,7 @@ async def main() -> None:
8889
except Exception as e:
8990
logger.error(f"Server error: {str(e)}")
9091
raise
92+
93+
94+
if __name__ == "__main__":
95+
asyncio.run(main())

0 commit comments

Comments
 (0)