Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async and await for send_log_message in fastmcp #172

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
20 changes: 10 additions & 10 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ async def read_resource(self, uri: str | AnyUrl) -> str | bytes:
), "Context is not available outside of a request"
return await self._fastmcp.read_resource(uri)

def log(
async def log(
self,
level: Literal["debug", "info", "warning", "error"],
message: str,
Expand All @@ -635,7 +635,7 @@ def log(
logger_name: Optional logger name
**extra: Additional structured data to include
"""
self.request_context.session.send_log_message(
await self.request_context.session.send_log_message(
level=level, data=message, logger=logger_name
)

Expand All @@ -659,18 +659,18 @@ def session(self):
return self.request_context.session

# Convenience methods for common log levels
def debug(self, message: str, **extra: Any) -> None:
async def debug(self, message: str, **extra: Any) -> None:
"""Send a debug log message."""
self.log("debug", message, **extra)
await self.log("debug", message, **extra)

def info(self, message: str, **extra: Any) -> None:
async def info(self, message: str, **extra: Any) -> None:
"""Send an info log message."""
self.log("info", message, **extra)
await self.log("info", message, **extra)

def warning(self, message: str, **extra: Any) -> None:
async def warning(self, message: str, **extra: Any) -> None:
"""Send a warning log message."""
self.log("warning", message, **extra)
await self.log("warning", message, **extra)

def error(self, message: str, **extra: Any) -> None:
async def error(self, message: str, **extra: Any) -> None:
"""Send an error log message."""
self.log("error", message, **extra)
await self.log("error", message, **extra)
Loading