Skip to content

Commit c3f01a1

Browse files
committed
update mcp
1 parent f12b118 commit c3f01a1

1 file changed

Lines changed: 22 additions & 81 deletions

File tree

β€Žchapter_3/agent_mcp_example.ipynbβ€Ž

Lines changed: 22 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,10 @@
8585
},
8686
{
8787
"cell_type": "code",
88-
"execution_count": 1,
88+
"execution_count": null,
8989
"id": "b3c72322",
9090
"metadata": {},
91-
"outputs": [
92-
{
93-
"name": "stdout",
94-
"output_type": "stream",
95-
"text": [
96-
"βœ… API key helper ready.\n"
97-
]
98-
}
99-
],
91+
"outputs": [],
10092
"source": [
10193
"import os\n",
10294
"from dotenv import load_dotenv\n",
@@ -133,18 +125,10 @@
133125
},
134126
{
135127
"cell_type": "code",
136-
"execution_count": 16,
128+
"execution_count": null,
137129
"id": "5032d7ac",
138130
"metadata": {},
139-
"outputs": [
140-
{
141-
"name": "stdout",
142-
"output_type": "stream",
143-
"text": [
144-
"βœ… bio_tools_server.py written to disk.\n"
145-
]
146-
}
147-
],
131+
"outputs": [],
148132
"source": [
149133
"server_code = '''\n",
150134
"#!/usr/bin/env python\n",
@@ -321,72 +305,52 @@
321305
" \n",
322306
"Do **not** run this in a notebook cell with `!` β€” it blocks the kernel and no other cells will run.\n",
323307
"\n",
324-
"**4.** Wait a few seconds until cloudflared prints a line like:\n",
308+
"**4.** Wait a few seconds until cloudflared prints a line like. Read through the terminal logs to identify the correct URL.\n",
325309
"```\n",
326310
"https://abc-def-123.trycloudflare.com\n",
327311
"```\n",
328-
"Copy that URL, paste it into the cell below, and run it.\n"
312+
"Copy that URL, paste it into the cell below, and run it. \n",
313+
"\n",
314+
"Do not close the terminal as we want to keep the Cloudflare tunnel open.\n"
329315
]
330316
},
331317
{
332318
"cell_type": "code",
333319
"execution_count": null,
334320
"id": "e4e0f7ca",
335321
"metadata": {},
336-
"outputs": [
337-
{
338-
"name": "stdout",
339-
"output_type": "stream",
340-
"text": [
341-
"1.27.0\n"
342-
]
343-
}
344-
],
322+
"outputs": [],
345323
"source": [
346324
"# Paste your cloudflared URL here (e.g. https://xxxx.trycloudflare.com)\n",
347325
"tunnel_url = \" https://xxxx.trycloudflare.com\""
348326
]
349327
},
350328
{
351-
"cell_type": "code",
352-
"execution_count": null,
329+
"cell_type": "markdown",
353330
"id": "c91457af",
354331
"metadata": {},
355-
"outputs": [
356-
{
357-
"name": "stdout",
358-
"output_type": "stream",
359-
"text": [
360-
"βœ… MCP URL set: https://difficulty-ages-stuck-corrections.trycloudflare.com/mcp\n"
361-
]
362-
}
363-
],
364332
"source": [
365-
"mcp_url = tunnel_url.rstrip(\"/\") + \"/mcp\"\n",
366-
"mcp_server_config = {\"type\": \"url\", \"url\": mcp_url, \"name\": \"bio_tools\"}\n",
367-
"print(f\"βœ… MCP URL set: {mcp_url}\")"
333+
"Now let's make sure if we can connect to the MCP server"
368334
]
369335
},
370336
{
371337
"cell_type": "code",
372-
"execution_count": 19,
338+
"execution_count": null,
373339
"id": "695692ff",
374340
"metadata": {},
375-
"outputs": [
376-
{
377-
"name": "stdout",
378-
"output_type": "stream",
379-
"text": [
380-
"HTTP 400 β€” tunnel is up but server rejected the request (this is OK)\n"
381-
]
382-
}
383-
],
341+
"outputs": [],
384342
"source": [
385343
"import urllib.request\n",
344+
"\n",
345+
"mcp_url = tunnel_url.rstrip(\"/\") + \"/mcp\"\n",
346+
"mcp_server_config = {\"type\": \"url\", \"url\": mcp_url, \"name\": \"bio_tools\"}\n",
347+
"print(f\"βœ… MCP URL set: {mcp_url}\")\n",
348+
"\n",
386349
"req = urllib.request.Request(\n",
387350
" mcp_server_config[\"url\"],\n",
388351
" headers={\"Accept\": \"application/json, text/event-stream\"}\n",
389352
")\n",
353+
"\n",
390354
"try:\n",
391355
" with urllib.request.urlopen(req, timeout=10) as r:\n",
392356
" print(f\"βœ… Reachable: HTTP {r.status}\")\n",
@@ -415,18 +379,10 @@
415379
},
416380
{
417381
"cell_type": "code",
418-
"execution_count": 30,
382+
"execution_count": null,
419383
"id": "61810bd4",
420384
"metadata": {},
421-
"outputs": [
422-
{
423-
"name": "stdout",
424-
"output_type": "stream",
425-
"text": [
426-
"Anthropic client ready.\n"
427-
]
428-
}
429-
],
385+
"outputs": [],
430386
"source": [
431387
"from anthropic import Anthropic\n",
432388
"\n",
@@ -510,22 +466,7 @@
510466
"execution_count": null,
511467
"id": "6f726632",
512468
"metadata": {},
513-
"outputs": [
514-
{
515-
"name": "stdout",
516-
"output_type": "stream",
517-
"text": [
518-
"πŸ§ͺ Question: \n",
519-
"I'm studying the role of EGFR in non-small-cell lung cancer.\n",
520-
"Here is a fragment of its amino acid sequence:\n",
521-
"\n",
522-
"MRPSGTAGAA...\n",
523-
"\n",
524-
"────────────────────────────────────────────────────────────\n",
525-
"I'll analyze this EGFR fragment in two parallel ways: computing its biophysical properties from the sequence, and pulling together its biological/disease context. Then I'll synthesize drug discovery hypotheses."
526-
]
527-
}
528-
],
469+
"outputs": [],
529470
"source": [
530471
"egfr_sequence_fragment = (\n",
531472
" \"MRPSGTAGAALLALLAALCPASRALEEKKVCQGTSNKLTQLGTFEDHFLSLQRMFNNCEVVLGNLEITYVQRNYDLSFLKTIQ\"\n",

0 commit comments

Comments
Β (0)