Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions mcp/src/agentmail_mcp/tools/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def setup_client(api_key: Optional[str] = None):
"""Setup the API client with authentication."""
global client

headers = {}
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
Expand Down Expand Up @@ -153,7 +153,8 @@ async def listThreads(inbox_id: str, limit: Optional[int] = None, offset: Option

result = await make_api_request("GET", f"/inboxes/{inbox_id}/threads", params=params)
return str(result)


# modified to be slimmer and easier to understand
@mcp.tool(description="Get thread by ID")
async def getThread(inbox_id: str, thread_id: str) -> str:
"""
Expand All @@ -164,6 +165,20 @@ async def getThread(inbox_id: str, thread_id: str) -> str:
thread_id: ID of the thread to retrieve
"""
result = await make_api_request("GET", f"/inboxes/{inbox_id}/threads/{thread_id}")
# Clean up messages in the result
if isinstance(result, dict) and "messages" in result:
cleaned_messages = []
for msg in result["messages"]:
cleaned_msg = {
"message_id": msg.get("message_id"),
"timestamp": msg.get("timestamp"),
"from": msg.get("from"),
"to": msg.get("to"),
"subject": msg.get("subject"),
"text": msg.get("text"),
}
cleaned_messages.append(cleaned_msg)
result["messages"] = cleaned_messages
return str(result)

# Message operations
Expand Down Expand Up @@ -226,7 +241,7 @@ async def sendMessage(

Args:
inbox_id: ID of the sending inbox
to: Recipient email addresses
to: List of recipient email addresses
subject: Email subject
body: Email body content
cc: CC recipients
Expand Down Expand Up @@ -288,4 +303,4 @@ async def replyToMessage(
"sendMessage": sendMessage,
"replyToMessage": replyToMessage,
"getAttachment": getAttachment
}
}