Skip to content

Commit 31dbc50

Browse files
author
Yoshihiro Takahara
committed
refactor: Remove content field from error responses
1 parent fe4bec4 commit 31dbc50

File tree

4 files changed

+1
-18
lines changed

4 files changed

+1
-18
lines changed

src/mcp_text_editor/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ class EditResult(BaseModel):
4949
hash: Optional[str] = Field(
5050
None, description="Current content hash (None for missing files)"
5151
)
52-
content: Optional[str] = Field(None, description="Current content if hash error")
5352

5453
def to_dict(self) -> Dict:
5554
"""Convert EditResult to a dictionary."""
5655
return {
5756
"result": self.result,
5857
"reason": self.reason,
5958
"hash": self.hash,
60-
"content": self.content,
6159
}
6260

6361

src/mcp_text_editor/service.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def edit_file_contents(
6565
result="error",
6666
reason="Content hash mismatch",
6767
hash=current_hash,
68-
content=None,
6968
)
7069
}
7170

@@ -79,7 +78,6 @@ def edit_file_contents(
7978
result="error",
8079
reason="Invalid patch ranges",
8180
hash=current_hash,
82-
content=None,
8381
)
8482
}
8583

@@ -101,7 +99,6 @@ def edit_file_contents(
10199
file_path: EditResult(
102100
result="ok",
103101
hash=new_hash,
104-
content=None,
105102
reason=None,
106103
)
107104
}
@@ -112,7 +109,6 @@ def edit_file_contents(
112109
result="error",
113110
reason=str(e),
114111
hash=None,
115-
content=None,
116112
)
117113
}
118114
except Exception as e:
@@ -121,6 +117,5 @@ def edit_file_contents(
121117
result="error",
122118
reason=str(e),
123119
hash=None, # Don't return the current hash on error
124-
content=None,
125120
)
126121
}

tests/test_models.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,16 @@ def test_edit_result():
101101
assert result.result == "ok"
102102
assert result.hash == "newhash123"
103103
assert result.reason is None
104-
assert result.content is None
105104

106-
# Test error result with reason and content
105+
# Test error result with reason
107106
result = EditResult(
108107
result="error",
109108
reason="hash mismatch",
110109
hash="currenthash123",
111-
content="current content",
112110
)
113111
assert result.result == "error"
114112
assert result.reason == "hash mismatch"
115113
assert result.hash == "currenthash123"
116-
assert result.content == "current content"
117114

118115
# Test validation error - missing required fields
119116
with pytest.raises(ValidationError):
@@ -171,22 +168,19 @@ def test_edit_result_to_dict():
171168
"result": "ok",
172169
"hash": "newhash123",
173170
"reason": None,
174-
"content": None,
175171
}
176172

177173
# Test error result
178174
result = EditResult(
179175
result="error",
180176
reason="hash mismatch",
181177
hash="currenthash123",
182-
content="current content",
183178
)
184179
result_dict = result.to_dict()
185180
assert result_dict == {
186181
"result": "error",
187182
"reason": "hash mismatch",
188183
"hash": "currenthash123",
189-
"content": "current content",
190184
}
191185

192186

tests/test_service.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def test_edit_file_contents_hash_mismatch(service, tmp_path):
119119
edit_result = result[file_path]
120120
assert edit_result.result == "error"
121121
assert "hash mismatch" in edit_result.reason.lower()
122-
assert edit_result.content is None
123122

124123

125124
def test_edit_file_contents_invalid_patches(service, tmp_path):
@@ -186,7 +185,6 @@ def test_edit_file_unexpected_error(service, tmp_path):
186185
assert edit_result.result == "error"
187186
assert "no such file" in edit_result.reason.lower()
188187
assert edit_result.hash is None
189-
assert edit_result.content is None
190188

191189

192190
def test_edit_file_contents_permission_error(service, tmp_path):
@@ -214,7 +212,6 @@ def test_edit_file_contents_permission_error(service, tmp_path):
214212
assert edit_result.result == "error"
215213
assert "permission denied" in edit_result.reason.lower()
216214
assert edit_result.hash is None
217-
assert edit_result.content is None
218215

219216
# Clean up
220217
os.chmod(file_path, 0o644)
@@ -257,4 +254,3 @@ def test_edit_file_contents_general_exception(service, mocker):
257254
if os.path.exists(test_file):
258255
os.remove(test_file)
259256
assert edit_result.hash is None
260-
assert edit_result.content is None

0 commit comments

Comments
 (0)