Skip to content

[BUG CLIENT]: Agent is not working with Remote MCP server #231

@JadyLiu

Description

@JadyLiu

Python -VV

Python 3.13.2 (main, Feb  4 2025, 14:51:09) [Clang 16.0.0 (clang-1600.0.26.6)]

Pip Freeze

annotated-types==0.7.0
anyio==4.9.0
Authlib==1.6.0
aws-requests-auth==0.4.3
boto3==1.38.23
botocore==1.38.23
certifi==2025.4.26
cffi==1.17.1
charset-normalizer==3.4.2
click==8.1.8
colorama==0.4.6
cryptography==45.0.3
Deprecated==1.2.18
dill==0.4.0
docstring-parser==0.15
eval_type_backport==0.2.2
exceptiongroup==1.3.0
fastapi==0.115.12
fastapi-mcp==0.3.4
fastmcp==2.5.2
googleapis-common-protos==1.70.0
griffe==1.7.3
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
httpx-sse==0.4.0
idna==3.10
importlib_metadata==8.6.1
itsdangerous==2.2.0
Jinja2==3.1.6
jmespath==1.0.1
Markdown==3.8
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mcp==1.9.1
mdurl==0.1.2
mistralai==1.8.1
mpmath==1.3.0
openapi-pydantic==0.5.1
opentelemetry-api==1.33.1
opentelemetry-exporter-otlp-proto-common==1.33.1
opentelemetry-exporter-otlp-proto-http==1.33.1
opentelemetry-proto==1.33.1
opentelemetry-sdk==1.33.1
opentelemetry-semantic-conventions==0.54b1
pillow==11.2.1
prompt_toolkit==3.0.51
protobuf==5.29.4
pycparser==2.22
pydantic==2.11.5
pydantic-settings==2.9.1
pydantic_core==2.33.2
Pygments==2.19.1
PyJWT==2.10.1
python-dateutil==2.9.0.post0
python-dotenv==1.1.0
python-multipart==0.0.20
requests==2.32.3
rich==14.0.0
s3transfer==0.13.0
shellingham==1.5.4
six==1.17.0
slack_bolt==1.23.0
slack_sdk==3.35.0
sniffio==1.3.1
sse-starlette==2.3.5
starlette==0.46.2
strands-agents==0.1.4
strands-agents-tools==0.1.3
sympy==1.14.0
tenacity==9.1.2
tomli==2.2.1
typer==0.15.4
typing-inspection==0.4.1
typing_extensions==4.13.2
urllib3==2.4.0
uvicorn==0.34.2
watchdog==6.0.0
wcwidth==0.2.13
websockets==15.0.1
wrapt==1.17.2
zipp==3.21.0

Reproduction Steps

  1. We have an existing remote MCP server working with current MCP client.
  2. We try to switch to Mistral agent by following example: https://docs.mistral.ai/agents/mcp/
  3. It works when using async with RunContext(model=MODEL,) as run_ctx: it does not work when using async with RunContext(agent_id=self.agent.id,) as run_ctx:
  4. The output is
    I'm sorry, but I currently don't have the tools needed to process and summarize the loan application for Jane Doe. If you have any other questions or need further assistance, feel free to ask!

Expected Behavior

The Agent is able to connect to remote MCP server using SSE.

Additional Context

The client code snippet is below:

#!/usr/bin/env python
import asyncio
import os

from mistralai import Mistral
from mistralai.extra.run.context import RunContext
from mistralai.extra.mcp.sse import MCPClientSSE, SSEServerParams
from pathlib import Path

# Set the current working directory and model to use
cwd = Path(__file__).parent
MODEL = "mistral-medium-latest"

# Define the URL for the remote MCP server
server_url = "http://myworkingserver:8000/mcp"
mcp_client = MCPClientSSE(sse_params=SSEServerParams(url=server_url, timeout=100))
query = (
    "Summarize the loan application for "
    '{"name": "Jane Doe","age": 35,"income": 2000000,'
    '"loan_amount": 4500000,"credit_score": 820,'
    '"existing_liabilities": 15000,"purpose": "Home Renovation"}'
)

class ClaimAgent:

    def __init__(self):
        self.client = None
        self.agent = None

    async def initialize(self):
        # Initialize the Mistral client with your API key
        api_key = os.environ["MISTRAL_API_KEY"]
        self.client = Mistral(api_key)

        self.agent = self.client.beta.agents.create(
            model=MODEL,
            name="claim-agent",
            instructions="Agent to answer user queries and response the loan summary using available tools.",
            description="Loan Summary Agent",
        )

    async def process_claim(self, query: str):
        """Process user query using the agent with MCP servers"""

        if not self.client or not self.agent:
            await self.initialize()
    
        # Create a run context for the agent
        async with RunContext(
            agent_id=self.agent.id,
            continue_on_fn_error=False,
        ) as run_ctx:
            # Register the MCP client with the run context
            await run_ctx.register_mcp_client(mcp_client=mcp_client)

            # Run the agent with a query
            print("Running the agent with the query...")
            run_result = await self.client.beta.conversations.run_async(
                run_ctx=run_ctx,
                inputs=query,
            )

            print("All run entries:")
            for entry in run_result.output_entries:
                print(f"{entry}")
                print()
            print(f"Final Response: {run_result.output_as_text}")



if __name__ == "__main__":
    claim_agent = ClaimAgent()
    try:
        asyncio.run(claim_agent.process_claim(query))
    except Exception as e:
        print(f"❌ Exception occurred: {e}")

Suggested Solutions

No response

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