Skip to content

You must call the "context_initialization" tool before using any other tools. #337

@nicobytes

Description

@nicobytes

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.

Image

Evidence of the Error

Graph Chat
Image Image

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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions