-
Notifications
You must be signed in to change notification settings - Fork 311
Description
The server has a tool named context_initialization that must be called before any other tool to initialize the context. My LangGraph agent correctly identifies and calls context_initialization first, and the logs show that the call is successful.
However, when the agent attempts to call a second tool (e.g., content_search), the execution fails with the error ToolException: Cannot execute tool "content_search" because context initialization is required first. This indicates that the state from the initialization was lost between the two tool calls.
Evidence of the Error
| Graph | Chat |
|---|---|
![]() |
![]() |
As seen in this screenshot from the logs, the context_initialization tool runs first, but the subsequent call to content_search fails.
To confirm that my MCP server is functioning correctly, I have tested it with other clients, such as Cursor, and it works as expected, maintaining the state after initialization.
Here is a successful execution in a different client:
My code is pretty simple, and I'm using the pre-release.
import os
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent
from agents.prompt import template
dot_api_key = os.getenv("DOT_API_KEY")
client = MultiServerMCPClient(
{
"dotcms": {
"command": "node",
"args": ["/Users/nicobytes1/Code/dotcms/core/core-web/dist/apps/mcp-server/main.js"],
"transport": "stdio",
"env": {
"DOTCMS_URL": "http://localhost:8080",
"AUTH_TOKEN": dot_api_key
}
},
}
)
async def make_graph():
tools = await client.get_tools()
prompt = template.render()
agent = create_agent("openai:gpt-4.1", tools, prompt=prompt)
return agent
