Posts

mcp with mcp inspector

Image
mcp inspector provide us with the necessary tool to invoke a mcp tools. Let's get back to some basic.  Here is my server.py and my client.py server.py from mcp . server . mcpserver import MCPServer mcp = MCPServer ( "hello-world" ) @ mcp . tool () def say_hello ( name : str = "world" ) -> str :     """Greet someone by name."""     return f "Hello, { name } ! 👋 (from my first MCP server)" @ mcp . tool () def add ( a : float , b : float ) -> float :     """Add two numbers."""     return a + b if __name__ == "__main__" :     # stdio transport: the client launches this script and talks over stdin/stdout     mcp . run ( transport = "stdio" ) client.py import asyncio , sys from mcp import ClientSession , StdioServerParameters from mcp . client . stdio import stdio_client async def main ():     params = StdioServerParameters ( command = sys . exec...

gcp spark quickstart 2 - fraud detector

Image
Let's create another python script that we can run with our serverless spark cluster. Some preliminary setup here :- gcloud services enable dataproc.googleapis.com bigquery.googleapis.com export BUCKET = $ (gcloud config get - value project) - fraud - demo gcloud storage buckets create gs : // $ BUCKET -- location = us - central1 bq mk -- location = US fraud And next we will create the requires tables in bigquery - all these command are ran from the command line  bq query -- use_legacy_sql = false << 'SQL' CREATE OR REPLACE TABLE fraud.transactions AS WITH normal AS (   SELECT     GENERATE_UUID() AS txn_id,     CONCAT( 'card_' , CAST( 1 + CAST(FLOOR(RAND() * 5000 ) AS INT64 ) AS STRING )) AS card_id,     ROUND( 5 + 100 * POW(RAND(), 3 ), 2 ) AS amount,     TIMESTAMP_ADD(TIMESTAMP( '2026-11-01' ),                   INTERVAL CAST(FLOOR(RAND() * 30 * 24 * 3600 ) AS ...

gcp apache spark deployment quickstart

Image
We can deploy a spark job without creating any cluster in GCP and this is a quickstart that we will be doing today with the followings commands:-  # enabling services gcloud services enable dataproc.googleapis.com bigquery.googleapis.com # Creating the bucket export BUCKET = $ (gcloud config get - value project) - spark - demo gcloud storage buckets create gs: // $ BUCKET -- location = us - central1 bq mk -- location = US wordcount_dataset And this is the code that we will be using  import sys from pyspark.sql import SparkSession, functions as F bucket = sys . argv [ 1 ] spark = SparkSession.builder.appName( "shakespeare-wordcount" ).getOrCreate() spark .conf.set( "temporaryGcsBucket" , bucket )   # staging area for the BigQuery write # 1. READ from BigQuery words = ( spark .read.format( "bigquery" )          .option( "table" , "bigquery-public-data:samples.shakespeare" )          .load()       ...

google adk - memory bank we can use to store our agentic application

Image
 With memorybank we can store user conversation and these conversations are stored based on app_name and user_id.  Another important point to note is we need both ImMorySessionService and VertexAiMemoryBankService.  import asyncio import os from google import adk from google . adk . agents . callback_context import CallbackContext from google . adk . memory import VertexAiMemoryBankService from google . adk . sessions import InMemorySessionService from google . adk . tools . preload_memory_tool import PreloadMemoryTool from google . genai import types os . environ [ "GOOGLE_GENAI_USE_ENTERPRISE" ] = "TRUE" os . environ [ "GOOGLE_CLOUD_PROJECT" ] = "project-xxxxxxxx" os . environ [ "GOOGLE_CLOUD_LOCATION" ] = "australia-southeast1" APP_NAME = "APP_NAME" # Memories are scoped per (app_name, user_id), so keep user_id stable # across sessions or the agent won't find earlier memories. USER_ID ...

google adk - compactiing conversation

We can easily compact our conversation by using the following code. Notice we are using App and EventsCompactionConfig (it is experimental) that can help to optimized latency and reduces cost. How we choose to compact our conversation is defined here Threshold approach # 3. Compaction config compaction_config = EventsCompactionConfig (     # Token-based (primary): compact when the prompt exceeds this many tokens     token_threshold = 1000 ,     event_retention_size = 3 ,       # keep the last 3 events raw     # Sliding window (supplementary): compact every N invocations     compaction_interval = 3 ,     overlap_size = 1 ,     summarizer = summarizer , ) If you opt for sliding window compact approach Sliding window approach   compaction_config = EventsCompactionConfig (     compaction_interval = 10 ,   # Number of new invocations between standard compactions     overlap_...

Developer guide for Gemini Carbon Model

Here is the link that you can check it out  https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-4-carbon

gke autopilot simulating 7 days upgrade pause

Image
We will simulate 7 days upgrade delay for GKE Autopilot cluster. First we make a pdb that will prevent node upgrade. You can use the following command to do that.  cat <<'EOF' | kubectl apply -f - apiVersion : apps/v1 kind : Deployment metadata :   name : big spec :   replicas : 2   selector :     matchLabels :       app : big   template :     metadata :       labels :         app : big     spec :       nodeSelector :         cloud.google.com/compute-class : autopilot       containers :       - name : nginx         image : nginx         resources :           requests : { cpu : "500m" , memory : 512Mi }           limits :   { cpu : "500m" , memory : 512Mi } --- apiVersion : policy/v1 kind : PodDisruptionBudget metadata ...