Skip to content

Commit 8628cec

Browse files
Fix null return values for LangChain4j compatibility (#45)
- send_email now returns success message instead of None - add_email_account now returns success message instead of None - Updated tests to verify return values - Fixes #42
1 parent 6369fc9 commit 8628cec

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

mcp_email_server/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ async def list_available_accounts() -> list[AccountAttributes]:
2929

3030

3131
@mcp.tool(description="Add a new email account configuration to the settings.")
32-
async def add_email_account(email: EmailSettings) -> None:
32+
async def add_email_account(email: EmailSettings) -> str:
3333
settings = get_settings()
3434
settings.add_email(email)
3535
settings.store()
36+
return f"Successfully added email account '{email.account_name}'"
3637

3738

3839
@mcp.tool(description="Paginate emails, page start at 1, before and since as UTC datetime.")
@@ -96,7 +97,8 @@ async def send_email(
9697
list[str] | None,
9798
Field(default=None, description="A list of BCC email addresses."),
9899
] = None,
99-
) -> None:
100+
) -> str:
100101
handler = dispatch_handler(account_name)
101102
await handler.send_email(recipients, subject, body, cc, bcc)
102-
return
103+
recipient_str = ", ".join(recipients)
104+
return f"Email sent successfully to {recipient_str}"

tests/test_mcp_tools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ async def test_add_email_account(self):
8989

9090
with patch("mcp_email_server.app.get_settings", return_value=mock_settings):
9191
# Call the function
92-
await add_email_account(email_settings)
92+
result = await add_email_account(email_settings)
93+
94+
# Verify the return value
95+
assert result == "Successfully added email account 'test_account'"
9396

9497
# Verify add_email and store were called correctly
9598
mock_settings.add_email.assert_called_once_with(email_settings)
@@ -170,7 +173,7 @@ async def test_send_email(self):
170173

171174
with patch("mcp_email_server.app.dispatch_handler", return_value=mock_handler):
172175
# Call the function
173-
await send_email(
176+
result = await send_email(
174177
account_name="test_account",
175178
recipients=["recipient@example.com"],
176179
subject="Test Subject",
@@ -179,6 +182,9 @@ async def test_send_email(self):
179182
bcc=["bcc@example.com"],
180183
)
181184

185+
# Verify the return value
186+
assert result == "Email sent successfully to recipient@example.com"
187+
182188
# Verify send_email was called correctly
183189
mock_handler.send_email.assert_called_once_with(
184190
["recipient@example.com"],

0 commit comments

Comments
 (0)