core: `dereference_refs` seems to lead to infinite recursion

### Checked other resources

- [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- [x] I added a clear and descriptive title that summarizes this issue.
- [x] I used the GitHub search to find a similar question and didn't find it.
- [x] I am sure that this is a bug in LangChain rather than my code.
- [x] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- [x] I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

### Example Code

```python
import os

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_xai import ChatXAI


async def get_mcp_tools():
    client = MultiServerMCPClient(
        {
            "hasura": {
                "url": "http://127.0.0.1:5000/mcp",
                "transport": "streamable_http",
            }
        }
    )
    tools = await client.get_tools()
    print(f"Tools: {[tool.name for tool in tools]}")
    return tools


def create_agent():
    model = ChatXAI(
        xai_api_key=os.getenv("xai_api_key"), model="grok-4-latest", temperature=0.2
    )
    print("llm initialized")
    return model


async def main():
    agent = create_agent()
    print(f"Agent: {agent.name}")
    tools = await get_mcp_tools()
    agent = agent.bind_tools(tools)
    print(f"Agent with tools: {agent.name}")

    response = await agent.ainvoke(
        ("user", "What is the health status of the pigs?"),
    )

    print(response)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())
```

Apollo-mcp-server run as an external service, can not provide example code.

### Error Message and Stack Trace (if applicable)

``` 
 File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 52, in _dereference_refs_helper
    full_ref = _dereference_refs_helper(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rusty/Documents/susteynable/chatfarm/.venv/lib/python3.12/site-packages/langchain_core/utils/json_schema.py", line 58, in _dereference_refs_helper
    obj_out[k] = _dereference_refs_helper(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
```

### Description

I am using [apollo-mcp-server](https://www.apollographql.com/docs/apollo-mcp-server) to integrate my current GraphQL service with LangGraph, but it gets stuck at the following lines:

```python
# Bind tools to model
model_with_tools = model.bind_tools(tools)
...
```

As shown in the stack trace above, `_dereference_refs_helper` seems to have entered an infinite recursion.

After investigating the LangChain code, I found that line 73 is the issue. Why is the value being removed from `processed_refs`?
https://github.com/langchain-ai/langchain/blob/7f259863e1d5713764deb7413e39ece3bffd1aee/libs/core/langchain_core/utils/json_schema.py#L69-L74


### System Info


System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000
> Python Version:  3.12.10 (main, May 22 2025, 01:38:44) [Clang 20.1.4 ]

Package Information
-------------------
> langchain_core: 0.3.74
> langchain: 0.3.27
> langchain_community: 0.3.27
> langsmith: 0.4.13
> langchain_mcp_adapters: 0.1.9
> langchain_modelscope: Installed. No version info available.
> langchain_openai: 0.2.14
> langchain_text_splitters: 0.3.9
> langchain_xai: 0.1.1
> langgraph_api: 0.2.129
> langgraph_cli: 0.3.6
> langgraph_license: Installed. No version info available.
> langgraph_runtime: Installed. No version info available.
> langgraph_runtime_inmem: 0.6.12
> langgraph_sdk: 0.2.0

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.12.15
> aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
> async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
> blockbuster<2.0.0,>=1.5.24: Installed. No version info available.
> click>=8.1.7: Installed. No version info available.
> cloudpickle>=3.0.0: Installed. No version info available.
> cryptography<45.0,>=42.0.0: Installed. No version info available.
> dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
> httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
> httpx<1,>=0.23.0: Installed. No version info available.
> httpx>=0.25.0: Installed. No version info available.
> httpx>=0.25.2: Installed. No version info available.
> jsonpatch<2.0,>=1.33: Installed. No version info available.
> jsonschema-rs<0.30,>=0.20.0: Installed. No version info available.
> langchain-anthropic;: Installed. No version info available.
> langchain-aws;: Installed. No version info available.
> langchain-azure-ai;: Installed. No version info available.
> langchain-cohere;: Installed. No version info available.
> langchain-community;: Installed. No version info available.
> langchain-core<0.4,>=0.3.36: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.66: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.72: Installed. No version info available.
> langchain-core>=0.3.64: Installed. No version info available.
> langchain-deepseek;: Installed. No version info available.
> langchain-fireworks;: Installed. No version info available.
> langchain-google-genai;: Installed. No version info available.
> langchain-google-vertexai;: Installed. No version info available.
> langchain-groq;: Installed. No version info available.
> langchain-huggingface;: Installed. No version info available.
> langchain-mistralai;: Installed. No version info available.
> langchain-ollama;: Installed. No version info available.
> langchain-openai;: Installed. No version info available.
> langchain-perplexity;: Installed. No version info available.
> langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available.
> langchain-together;: Installed. No version info available.
> langchain-xai;: Installed. No version info available.
> langchain<1.0.0,>=0.3.26: Installed. No version info available.
> langgraph-api<0.3.0,>=0.2.67;: Installed. No version info available.
> langgraph-checkpoint>=2.0.23: Installed. No version info available.
> langgraph-checkpoint>=2.0.25: Installed. No version info available.
> langgraph-runtime-inmem<0.7,>=0.6.9: Installed. No version info available.
> langgraph-runtime-inmem>=0.6.0;: Installed. No version info available.
> langgraph-sdk>=0.1.0;: Installed. No version info available.
> langgraph-sdk>=0.2.0: Installed. No version info available.
> langgraph>=0.2: Installed. No version info available.
> langgraph>=0.4.0: Installed. No version info available.
> langsmith-pyo3>=0.1.0rc2;: Installed. No version info available.
> langsmith>=0.1.125: Installed. No version info available.
> langsmith>=0.1.17: Installed. No version info available.
> langsmith>=0.3.45: Installed. No version info available.
> mcp>=1.9.2: Installed. No version info available.
> numpy>=1.26.2;: Installed. No version info available.
> numpy>=2.1.0;: Installed. No version info available.
> openai: 1.99.9
> openai-agents>=0.0.3;: Installed. No version info available.
> opentelemetry-api>=1.30.0;: Installed. No version info available.
> opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available.
> opentelemetry-sdk>=1.30.0;: Installed. No version info available.
> orjson>=3.10.1: Installed. No version info available.
> orjson>=3.9.14;: Installed. No version info available.
> orjson>=3.9.7: Installed. No version info available.
> packaging>=23.2: Installed. No version info available.
> pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
> pydantic<3,>=1: Installed. No version info available.
> pydantic<3.0.0,>=2.7.4: Installed. No version info available.
> pydantic>=2.7.4: Installed. No version info available.
> pyjwt>=2.9.0: Installed. No version info available.
> pytest>=7.0.0;: Installed. No version info available.
> python-dotenv>=0.8.0;: Installed. No version info available.
> PyYAML>=5.3: Installed. No version info available.
> requests: 2.32.4
> requests-toolbelt>=1.0.0: Installed. No version info available.
> requests<3,>=2: Installed. No version info available.
> requests>=2.0.0: Installed. No version info available.
> rich>=13.9.4;: Installed. No version info available.
> SQLAlchemy<3,>=1.4: Installed. No version info available.
> sse-starlette<2.2.0,>=2.1.0: Installed. No version info available.
> sse-starlette>=2: Installed. No version info available.
> starlette>=0.37: Installed. No version info available.
> starlette>=0.38.6: Installed. No version info available.
> structlog<26,>=24.1.0: Installed. No version info available.
> structlog>23: Installed. No version info available.
> tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
> tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
> tenacity>=8.0.0: Installed. No version info available.
> tiktoken: 0.11.0
> truststore>=0.1: Installed. No version info available.
> typing-extensions>=4.14.0: Installed. No version info available.
> typing-extensions>=4.7: Installed. No version info available.
> uvicorn>=0.26.0: Installed. No version info available.
> vcrpy>=7.0.0;: Installed. No version info available.
> watchfiles>=0.13: Installed. No version info available.
> zstandard>=0.23.0: Installed. No version info available.

Labels: help wanted, bug
State: closed