Skip to content

Commit 7769cda

Browse files
Yoshihiro TakaharaYoshihiro Takahara
authored andcommitted
chore: unify 'path' param name to 'file_path' for Text Editor API
Changes: - Change parameter name from 'path' to 'file_path' in all APIs - Update corresponding error messages - Update test cases for consistency - Fix input schema requirements
1 parent 55356a0 commit 7769cda

8 files changed

+40
-40
lines changed

src/mcp_text_editor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def get_text_file_contents(
2929
async def insert_text_file_contents(request: Dict[str, Any]) -> Dict[str, Any]:
3030
"""Insert text content before or after a specific line in a file."""
3131
return await _text_editor.insert_text_file_contents(
32-
file_path=request["path"],
32+
file_path=request["file_path"],
3333
file_hash=request["file_hash"],
3434
after=request.get("after"),
3535
before=request.get("before"),

src/mcp_text_editor/handlers/append_text_file_contents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def get_tool_description(self) -> Tool:
5252
async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
5353
"""Execute the tool with given arguments."""
5454
try:
55-
if "path" not in arguments:
56-
raise RuntimeError("Missing required argument: path")
55+
if "file_path" not in arguments:
56+
raise RuntimeError("Missing required argument: file_path")
5757
if "contents" not in arguments:
5858
raise RuntimeError("Missing required argument: contents")
5959
if "file_hash" not in arguments:
6060
raise RuntimeError("Missing required argument: file_hash")
6161

62-
file_path = arguments["path"]
62+
file_path = arguments["file_path"]
6363
if not os.path.isabs(file_path):
6464
raise RuntimeError(f"File path must be absolute: {file_path}")
6565

src/mcp_text_editor/handlers/create_text_file.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_tool_description(self) -> Tool:
2929
inputSchema={
3030
"type": "object",
3131
"properties": {
32-
"path": {
32+
"file_path": {
3333
"type": "string",
3434
"description": "Path to the text file. File path must be absolute.",
3535
},
@@ -50,12 +50,12 @@ def get_tool_description(self) -> Tool:
5050
async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
5151
"""Execute the tool with given arguments."""
5252
try:
53-
if "path" not in arguments:
54-
raise RuntimeError("Missing required argument: path")
53+
if "file_path" not in arguments:
54+
raise RuntimeError("Missing required argument: file_path")
5555
if "contents" not in arguments:
5656
raise RuntimeError("Missing required argument: contents")
5757

58-
file_path = arguments["path"]
58+
file_path = arguments["file_path"]
5959
if not os.path.isabs(file_path):
6060
raise RuntimeError(f"File path must be absolute: {file_path}")
6161

src/mcp_text_editor/handlers/insert_text_file_contents.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_tool_description(self) -> Tool:
2727
inputSchema={
2828
"type": "object",
2929
"properties": {
30-
"path": {
30+
"file_path": {
3131
"type": "string",
3232
"description": "Path to the text file. File path must be absolute.",
3333
},
@@ -53,21 +53,21 @@ def get_tool_description(self) -> Tool:
5353
"default": "utf-8",
5454
},
5555
},
56-
"required": ["path", "file_hash", "contents"],
56+
"required": ["file_path", "file_hash", "contents"],
5757
},
5858
)
5959

6060
async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
6161
"""Execute the tool with given arguments."""
6262
try:
63-
if "path" not in arguments:
64-
raise RuntimeError("Missing required argument: path")
63+
if "file_path" not in arguments:
64+
raise RuntimeError("Missing required argument: file_path")
6565
if "file_hash" not in arguments:
6666
raise RuntimeError("Missing required argument: file_hash")
6767
if "contents" not in arguments:
6868
raise RuntimeError("Missing required argument: contents")
6969

70-
file_path = arguments["path"]
70+
file_path = arguments["file_path"]
7171
if not os.path.isabs(file_path):
7272
raise RuntimeError(f"File path must be absolute: {file_path}")
7373

tests/test_append_text_file.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def test_append_text_file_success(test_dir: str, cleanup_files: None) -> N
4242

4343
# Append content using handler
4444
arguments: Dict[str, Any] = {
45-
"path": test_file,
45+
"file_path": test_file,
4646
"contents": append_content,
4747
"file_hash": file_hash,
4848
}
@@ -66,7 +66,7 @@ async def test_append_text_file_not_exists(test_dir: str, cleanup_files: None) -
6666

6767
# Try to append to non-existent file
6868
arguments: Dict[str, Any] = {
69-
"path": test_file,
69+
"file_path": test_file,
7070
"contents": "Some content\n",
7171
"file_hash": "dummy_hash",
7272
}
@@ -91,7 +91,7 @@ async def test_append_text_file_hash_mismatch(
9191

9292
# Try to append with incorrect hash
9393
arguments: Dict[str, Any] = {
94-
"path": test_file,
94+
"file_path": test_file,
9595
"contents": "New content\n",
9696
"file_hash": "incorrect_hash",
9797
}
@@ -108,7 +108,7 @@ async def test_append_text_file_relative_path(
108108
) -> None:
109109
"""Test attempting to append using a relative path."""
110110
arguments: Dict[str, Any] = {
111-
"path": "relative_path.txt",
111+
"file_path": "relative_path.txt",
112112
"contents": "Some content\n",
113113
"file_hash": "dummy_hash",
114114
}
@@ -125,19 +125,19 @@ async def test_append_text_file_missing_args() -> None:
125125
# Test missing path
126126
with pytest.raises(RuntimeError) as exc_info:
127127
await append_handler.run_tool({"contents": "content\n", "file_hash": "hash"})
128-
assert "Missing required argument: path" in str(exc_info.value)
128+
assert "Missing required argument: file_path" in str(exc_info.value)
129129

130130
# Test missing contents
131131
with pytest.raises(RuntimeError) as exc_info:
132132
await append_handler.run_tool(
133-
{"path": "/absolute/path.txt", "file_hash": "hash"}
133+
{"file_path": "/absolute/path.txt", "file_hash": "hash"}
134134
)
135135
assert "Missing required argument: contents" in str(exc_info.value)
136136

137137
# Test missing file_hash
138138
with pytest.raises(RuntimeError) as exc_info:
139139
await append_handler.run_tool(
140-
{"path": "/absolute/path.txt", "contents": "content\n"}
140+
{"file_path": "/absolute/path.txt", "contents": "content\n"}
141141
)
142142
assert "Missing required argument: file_hash" in str(exc_info.value)
143143

@@ -163,7 +163,7 @@ async def test_append_text_file_custom_encoding(
163163

164164
# Append content using handler with specified encoding
165165
arguments: Dict[str, Any] = {
166-
"path": test_file,
166+
"file_path": test_file,
167167
"contents": append_content,
168168
"file_hash": file_hash,
169169
"encoding": "utf-8",

tests/test_create_text_file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def test_create_text_file_success(test_dir: str, cleanup_files: None) -> N
3232

3333
# Create file using handler
3434
arguments: Dict[str, Any] = {
35-
"path": test_file,
35+
"file_path": test_file,
3636
"contents": content,
3737
}
3838
response = await create_file_handler.run_tool(arguments)
@@ -59,7 +59,7 @@ async def test_create_text_file_exists(test_dir: str, cleanup_files: None) -> No
5959

6060
# Try to create file using handler
6161
arguments: Dict[str, Any] = {
62-
"path": test_file,
62+
"file_path": test_file,
6363
"contents": "New content\n",
6464
}
6565

@@ -75,7 +75,7 @@ async def test_create_text_file_relative_path(
7575
"""Test attempting to create a file with a relative path."""
7676
# Try to create file using relative path
7777
arguments: Dict[str, Any] = {
78-
"path": "relative_path.txt",
78+
"file_path": "relative_path.txt",
7979
"contents": "Some content\n",
8080
}
8181

@@ -91,11 +91,11 @@ async def test_create_text_file_missing_args() -> None:
9191
# Test missing path
9292
with pytest.raises(RuntimeError) as exc_info:
9393
await create_file_handler.run_tool({"contents": "content\n"})
94-
assert "Missing required argument: path" in str(exc_info.value)
94+
assert "Missing required argument: file_path" in str(exc_info.value)
9595

9696
# Test missing contents
9797
with pytest.raises(RuntimeError) as exc_info:
98-
await create_file_handler.run_tool({"path": "/absolute/path.txt"})
98+
await create_file_handler.run_tool({"file_path": "/absolute/path.txt"})
9999
assert "Missing required argument: contents" in str(exc_info.value)
100100

101101

@@ -109,7 +109,7 @@ async def test_create_text_file_custom_encoding(
109109

110110
# Create file using handler with specified encoding
111111
arguments: Dict[str, Any] = {
112-
"path": test_file,
112+
"file_path": test_file,
113113
"contents": content,
114114
"encoding": "utf-8",
115115
}

tests/test_insert_text_file.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def test_insert_after_line(tmp_path: Path) -> None:
2323
# Insert text after line 2
2424
result = await insert_text_file_contents(
2525
{
26-
"path": str(test_file),
26+
"file_path": str(test_file),
2727
"file_hash": file_hash,
2828
"after": 2,
2929
"contents": "new_line\n",
@@ -54,7 +54,7 @@ async def test_insert_before_line(tmp_path: Path) -> None:
5454
# Insert text before line 2
5555
result = await insert_text_file_contents(
5656
{
57-
"path": str(test_file),
57+
"file_path": str(test_file),
5858
"file_hash": file_hash,
5959
"before": 2,
6060
"contents": "new_line\n",
@@ -85,7 +85,7 @@ async def test_insert_beyond_file_end(tmp_path: Path) -> None:
8585
# Try to insert text after line 10 (file has only 3 lines)
8686
result = await insert_text_file_contents(
8787
{
88-
"path": str(test_file),
88+
"file_path": str(test_file),
8989
"file_hash": file_hash,
9090
"after": 10,
9191
"contents": "new_line\n",
@@ -102,7 +102,7 @@ async def test_file_not_found(tmp_path: Path) -> None:
102102
# Try to insert text into a non-existent file
103103
result = await insert_text_file_contents(
104104
{
105-
"path": str(tmp_path / "nonexistent.txt"),
105+
"file_path": str(tmp_path / "nonexistent.txt"),
106106
"file_hash": "any_hash",
107107
"after": 1,
108108
"contents": "new_line\n",
@@ -123,7 +123,7 @@ async def test_hash_mismatch(tmp_path: Path) -> None:
123123
# Try to insert text with incorrect hash
124124
result = await insert_text_file_contents(
125125
{
126-
"path": str(test_file),
126+
"file_path": str(test_file),
127127
"file_hash": "incorrect_hash",
128128
"after": 1,
129129
"contents": "new_line\n",

tests/test_insert_text_file_handler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ def handler():
1919

2020
@pytest.mark.asyncio
2121
async def test_missing_path(handler):
22-
"""Test handling of missing path argument."""
23-
with pytest.raises(RuntimeError, match="Missing required argument: path"):
22+
"""Test handling of missing file_path argument."""
23+
with pytest.raises(RuntimeError, match="Missing required argument: file_path"):
2424
await handler.run_tool({"file_hash": "hash", "contents": "content"})
2525

2626

2727
@pytest.mark.asyncio
2828
async def test_missing_hash(handler):
2929
"""Test handling of missing file_hash argument."""
3030
with pytest.raises(RuntimeError, match="Missing required argument: file_hash"):
31-
await handler.run_tool({"path": "/tmp/test.txt", "contents": "content"})
31+
await handler.run_tool({"file_path": "/tmp/test.txt", "contents": "content"})
3232

3333

3434
@pytest.mark.asyncio
3535
async def test_missing_contents(handler):
3636
"""Test handling of missing contents argument."""
3737
with pytest.raises(RuntimeError, match="Missing required argument: contents"):
38-
await handler.run_tool({"path": "/tmp/test.txt", "file_hash": "hash"})
38+
await handler.run_tool({"file_path": "/tmp/test.txt", "file_hash": "hash"})
3939

4040

4141
@pytest.mark.asyncio
@@ -44,7 +44,7 @@ async def test_relative_path(handler):
4444
with pytest.raises(RuntimeError, match="File path must be absolute"):
4545
await handler.run_tool(
4646
{
47-
"path": "relative/path.txt",
47+
"file_path": "relative/path.txt",
4848
"file_hash": "hash",
4949
"contents": "content",
5050
"before": 1,
@@ -59,7 +59,7 @@ async def test_neither_before_nor_after(handler):
5959
RuntimeError, match="Exactly one of 'before' or 'after' must be specified"
6060
):
6161
await handler.run_tool(
62-
{"path": "/tmp/test.txt", "file_hash": "hash", "contents": "content"}
62+
{"file_path": "/tmp/test.txt", "file_hash": "hash", "contents": "content"}
6363
)
6464

6565

@@ -71,7 +71,7 @@ async def test_both_before_and_after(handler):
7171
):
7272
await handler.run_tool(
7373
{
74-
"path": "/tmp/test.txt",
74+
"file_path": "/tmp/test.txt",
7575
"file_hash": "hash",
7676
"contents": "content",
7777
"before": 1,
@@ -95,7 +95,7 @@ async def test_successful_insert_before(handler, tmp_path):
9595

9696
result = await handler.run_tool(
9797
{
98-
"path": file_path,
98+
"file_path": file_path,
9999
"file_hash": init_hash,
100100
"contents": "new_line\n",
101101
"before": 2,

0 commit comments

Comments
 (0)