https://linen.dev logo
p
Hi all is there someplace where i can find how to properly add the mcp server url to an agents code using google adk ? i tried adding the mcp server url but i dont get any reponse from my agent after that.the server seems to be closing the connection from composio side!
u
Hey @Providence94, could you share more details about "closing connection from composio side"? It'll help us understand what's happening. Please do share any error logs/messages.
p
hey
this is my adk agent code im just testing basic connection i am succesfully able to send an email from your playground
but not through my adk code
"""Root agent wiring plus a configurable MCP tool.""" from google.adk.agents.llm_agent import Agent from google.adk.tools import google_search from google.adk.tools.mcp_tool import MCPToolset, StreamableHTTPConnectionParams from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams HARDCODED_MCP_USER_ID = "pg-test-afcd440b-c276-4a52-947d-db70b3dbcbbd" HARDCODED_MCP_URL = ( "https://backend.composio.dev/v3/mcp/855457be-b8c5-4a68-8acb-e784ef838cb2/sse" "?include_composio_helper_actions=true" f"&user_id={HARDCODED_MCP_USER_ID}" ) root_agent = Agent( # type: ignore[call-arg] model="gemini-2.5-flash", name="root_agent", description="A helpful assistant for user questions.", instruction="Answer user questions to the best of your knowledge", # tools=[google_search, *_MCP_TOOLSETS] if _MCP_TOOLSETS else [google_search], tools=[ MCPToolset(connection_params=SseConnectionParams(url=HARDCODED_MCP_URL)), google_search, ], ) print("--- Loaded Agent Tools ---") print(root_agent.tools) print("--------------------------")
should i send api key too ?
u
By closing a connection from Composio side, are you referring to this error: " *ERROR - adk_web_server.py:1428 - Error in event_generator: Connection closed*"? This seems to be your adk closing the connection. Also, I can see you've imported
StreamableHTTPConnectionParams
and are using sse? I can help you with an example snippet which you can take as a reference:
Copy code
from google.adk.agents import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types

# from composio import Composio
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset, StreamableHTTPConnectionParams
# ADK config
model = "gemini-2.0-flash"
app_name = "github_agent"
session_id = "1234"
user_id = "pg-test-xxxx"


mcp_server_url = "https://backend.composio.dev/v3/mcp/<id>/mcp?user_id=pg-test-xxxx"
mcp_tools = McpToolset(
    connection_params=StreamableHTTPConnectionParams(
        url=mcp_server_url
    )
)

# Agent
github_agent = Agent(
    name=app_name,
    model=model,
    instruction="You are a github utility agent with ability to interact with github APIs",
    tools=[mcp_tools],
)

# Session and Runner
session_service = InMemorySessionService()
session = session_service.create_session_sync(
    app_name=app_name,
    user_id=user_id,
    session_id=session_id,
)
runner = Runner(
    agent=github_agent,
    app_name=app_name,
    session_service=session_service,
)


# Agent Interaction
content = types.Content(
    role="user",
    parts=[
        types.Part(
            text="Star github repository composiohq/composio.",
        )
    ],
)
events = runner.run(
    user_id=user_id,
    session_id=session_id,
    new_message=content
)
for event in events:
    if (
        event.is_final_response()
        and event.content is not None
        and event.content.parts
        and len(event.content.parts) > 0
    ):
        print("Agent Response: ", event.content.parts[0].text)
No no, you don't need to share your personal api-keys. Please refer the above snippet and lmk if it's working for you?
p
okai let me try this code
currently in my code i am not sending api key in the header int he request
u
It’s a good practice to send your composio API key in the headers with your MCP URL. For testing, you can skip this step and let me know if it works for you? If you want to pass headers this way:
Copy code
mcp_tools = McpToolset(
    connection_params=StreamableHTTPConnectionParams(
        url=mcp_server_url,
        headers={
            "Authorization": f"Bearer {get_id_token()}",
        },
    )
)
Yes, the example snipper I've shared is for Github. You can replace your Gmail MCP server and update the snippet to do tool calls related to Gmail toolkit.
p
okai so instead of calling connection_params=SseConnectionParams i should be doing connection_params=StreamableHTTPConnectionParams ?
this doesnt seem to work 2025-12-01 13:29:09,701 - INFO - _client.py:1740 - HTTP Request: POST https://backend.composio.dev/v3/mcp/855457be-b8c5-4a68-8acb-e784ef838cb2/sse?include_composio_helper_actions=true&user_id=pg-test-afcd440b-c276-4a52-947d-db70b3dbcbbd "HTTP/1.1 405 Method Not Allowed" ERROR: ASGI callable returned without completing response.
u
Exactly! Also, please remove /see from your url and replace it with /mcp: "https://backend.composio.dev/v3/mcp/855457be-b8c5-4a68-8acb-e784ef838cb2/mcp"
p
earlier i had tried doing StreamableHTTPConnectionParams after that i tried SseConnectionParams
u
I see, the snippet I've share is throwing "*method not allowed*"?
p
so after i added the /mcp to the end of the url i get another set of errors
but i think the mcp server handshake worked i got adk related errors which said something like tool use with function calling not supported
i would like to know where the documentation is for some of the things you have mentioned looking at the docs on your website i did see the suggestion to add /mcp etc to resolve whats going on
u
@Providence94, if you are looking for the
connection_params=StreamableHTTPConnectionParams
, you can refer to this documentation: https://codelabs.developers.google.com/codelabs/cloud-run/use-mcp-server-on-cloud-run-with-an-adk-agent#5 — Does this solve your query?
p
dont know yet. let me check these
okai Uday things seem to work. thank you
u
Awesome, lmk if you face any issues.