Skip to content
Merged
Changes from 3 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
4 changes: 3 additions & 1 deletion src/agents/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, cache_tools_list: bool, client_session_timeout_seconds: float
self.exit_stack: AsyncExitStack = AsyncExitStack()
self._cleanup_lock: asyncio.Lock = asyncio.Lock()
self.cache_tools_list = cache_tools_list
self.instructions: str | None = None

self.client_session_timeout_seconds = client_session_timeout_seconds

Expand Down Expand Up @@ -122,7 +123,8 @@ async def connect(self):
else None,
)
)
await session.initialize()
server_result = await session.initialize()
self.instructions = getattr(server_result, "instructions", None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use getattr? I see initialize() returns types.InitializeResult, which has instructions: str | None = None

In fact, we should probably just set self.server_initialize_result. That way devs can read other info too, e.g. protocol version or capabilities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you prefer, the issue was about instructions so I read that value, but now I set the variable as you suggested.

self.session = session
except Exception as e:
logger.error(f"Error initializing MCP server: {e}")
Expand Down