https://linen.dev logo
MCP Server: Connection closed by server
# 🖥│support-forum
d
MCP server is not getting connected for the below snippet:
Copy code
python
from anthropic import Anthropic

# Initialize Anthropic client
client = Anthropic(api_key="")

# Use the MCP server URL you generated
mcp_server_url = ""

# Use MCP with Anthropic (beta feature)
response = client.beta.messages.create(
model="claude-sonnet-4-5",
system="You are a helpful assistant with access to various tools through MCP. Use these tools to help the user. Do not ask for confirmation before using the tools.",
max_tokens=1000,
messages=[{
    "role": "user",
    "content": "What all repos do I have in github and channels in slack?"
}],
mcp_servers=[{
    "type": "url",
    "url": mcp_server_url,
    "name": "testing-init-flow"
}],
betas=["mcp-client-2025-04-04"]  # Enable MCP beta
)

print(response.content)
Error:
Copy code
BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'Connection error while communicating with MCP server: Connection closed by server'}, 'request_id': 'req_xx'}
I have been following the doc: https://docs.composio.dev/docs/mcp-quickstart. Any guidance will be helpful, thanks in Advance!
a
Could you share the exact error message you're seeing? Also, I would not suggest sharing MCP server URL + user/connection ID on a public medium.
d
Sure have removed the MCP server url and have pasted the error above
Sure have removed the MCP server URL and have pasted the error above
I have taken the MCP server url from the composio platform after authenticating with github and slack
a
Thanks, it could be happening with this MCP client.. can you share the request ID from logs? and maybe can you try this in a different MCP client like MCP inspector / postman and see if issue persist? Meanwhile I'll see if I can repro the same in anthropic.
d
Hey thanks a lot but it got fixed. Maybe issue was that I created MCP server without any tools and the anthropic client didn’t even connect to it instead of showing that no tools are available
2 Views