Skip to content

Commit e801fa4

Browse files
authored
feat: Use pydantic field for description (#13)
1 parent 28538f9 commit e801fa4

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

mcp_email_server/app.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
2-
from typing import Annotated
32

43
from mcp.server.fastmcp import FastMCP
4+
from pydantic import Field
55

66
from mcp_email_server.config import (
77
AccountAttributes,
@@ -36,16 +36,16 @@ async def add_email_account(email: EmailSettings) -> None:
3636

3737
@mcp.tool(description="Paginate emails, page start at 1, before and since as UTC datetime.")
3838
async def page_email(
39-
account_name: Annotated[str, "The name of the email account."],
40-
page: Annotated[int, "The page number to retrieve (starting from 1)."] = 1,
41-
page_size: Annotated[int, "The number of emails to retrieve per page."] = 10,
42-
before: Annotated[datetime | None, "Retrieve emails before this datetime (UTC)."] = None,
43-
since: Annotated[datetime | None, "Retrieve emails since this datetime (UTC)."] = None,
44-
subject: Annotated[str | None, "Filter emails by subject."] = None,
45-
body: Annotated[str | None, "Filter emails by body."] = None,
46-
text: Annotated[str | None, "Filter emails by text."] = None,
47-
from_address: Annotated[str | None, "Filter emails by sender address."] = None,
48-
to_address: Annotated[str | None, "Filter emails by recipient address."] = None,
39+
account_name: str = Field(description="The name of the email account."),
40+
page: int = Field(default=1, description="The page number to retrieve (starting from 1)."),
41+
page_size: int = Field(default=10, description="The number of emails to retrieve per page."),
42+
before: datetime | None = Field(default=None, description="Retrieve emails before this datetime (UTC)."),
43+
since: datetime | None = Field(default=None, description="Retrieve emails since this datetime (UTC)."),
44+
subject: str | None = Field(default=None, description="Filter emails by subject."),
45+
body: str | None = Field(default=None, description="Filter emails by body."),
46+
text: str | None = Field(default=None, description="Filter emails by text."),
47+
from_address: str | None = Field(default=None, description="Filter emails by sender address."),
48+
to_address: str | None = Field(default=None, description="Filter emails by recipient address."),
4949
) -> EmailPageResponse:
5050
handler = dispatch_handler(account_name)
5151

@@ -66,12 +66,12 @@ async def page_email(
6666
description="Send an email using the specified account. Recipient should be a list of email addresses.",
6767
)
6868
async def send_email(
69-
account_name: Annotated[str, "The name of the email account to send from."],
70-
recipients: Annotated[list[str], "A list of recipient email addresses."],
71-
subject: Annotated[str, "The subject of the email."],
72-
body: Annotated[str, "The body of the email."],
73-
cc: Annotated[list[str] | None, "A list of CC email addresses."] = None,
74-
bcc: Annotated[list[str] | None, "A list of BCC email addresses."] = None,
69+
account_name: str = Field(description="The name of the email account to send from."),
70+
recipients: list[str] = Field(description="A list of recipient email addresses."),
71+
subject: str = Field(description="The subject of the email."),
72+
body: str = Field(description="The body of the email."),
73+
cc: list[str] | None = Field(default=None, description="A list of CC email addresses."),
74+
bcc: list[str] | None = Field(default=None, description="A list of BCC email addresses."),
7575
) -> None:
7676
handler = dispatch_handler(account_name)
7777
await handler.send_email(recipients, subject, body, cc, bcc)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ ignore = [
109109
"TRY003",
110110
# try-consider-else
111111
"TRY300",
112+
112113
]
113114

114115
[tool.ruff.lint.per-file-ignores]
115116
"tests/*" = ["S101", "S106", "SIM117"]
117+
"mcp_email_server/app.py" = ["B008"]
116118

117119
[tool.ruff.format]
118120
preview = true

0 commit comments

Comments
 (0)