Skip to content

Instantly share code, notes, and snippets.

@janakiramm
Created August 17, 2025 06:43
Show Gist options
  • Select an option

  • Save janakiramm/a42db90cc1ca1fd7fb72d86982ae965d to your computer and use it in GitHub Desktop.

Select an option

Save janakiramm/a42db90cc1ca1fd7fb72d86982ae965d to your computer and use it in GitHub Desktop.
Simple MCP Gemini Client
import os
import asyncio
from google import genai
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
import warnings
warnings.filterwarnings("ignore")
MCP_SERVER_URL = "http://127.0.0.1:8080/mcp/"
client = genai.Client()
async def main():
async with streamablehttp_client(MCP_SERVER_URL) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
prompt = "Who is the Intern in the company?"
response = await client.aio.models.generate_content(
model="gemini-2.5-flash",
contents=prompt,
config=genai.types.GenerateContentConfig(
temperature=0,
tools=[session], # Pass the MCP session as a tool
),
)
print(response.text)
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment