Added mcp 'instructions' attribute to the server (#706)

Added the `instructions` attribute to the MCP servers to solve #704 .

Let me know if you want to add an example to the documentation.
This commit is contained in:
Daniele Morotti 2025-05-18 19:25:08 +02:00 committed by GitHub
parent c282324d95
commit 003cbfe5f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,7 +12,7 @@ from mcp import ClientSession, StdioServerParameters, Tool as MCPTool, stdio_cli
from mcp.client.sse import sse_client
from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client
from mcp.shared.message import SessionMessage
from mcp.types import CallToolResult
from mcp.types import CallToolResult, InitializeResult
from typing_extensions import NotRequired, TypedDict
from ..exceptions import UserError
@ -73,6 +73,7 @@ class _MCPServerWithClientSession(MCPServer, abc.ABC):
self.exit_stack: AsyncExitStack = AsyncExitStack()
self._cleanup_lock: asyncio.Lock = asyncio.Lock()
self.cache_tools_list = cache_tools_list
self.server_initialize_result: InitializeResult | None = None
self.client_session_timeout_seconds = client_session_timeout_seconds
@ -122,7 +123,8 @@ class _MCPServerWithClientSession(MCPServer, abc.ABC):
else None,
)
)
await session.initialize()
server_result = await session.initialize()
self.server_initialize_result = server_result
self.session = session
except Exception as e:
logger.error(f"Error initializing MCP server: {e}")