Skip to content

Commit 287df90

Browse files
committed
update snippets
1 parent 4a7bafd commit 287df90

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/servers/everything-server/mcp_everything_server/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ async def test_sampling(prompt: str, ctx: Context[ServerSession, None]) -> str:
134134
max_tokens=100,
135135
)
136136

137-
content = result.content[0] if isinstance(result.content, list) else result.content
138-
if content.type == "text":
139-
model_response = content.text
137+
content = result.content if isinstance(result.content, list) else [result.content]
138+
if any(c.type == "text" for c in content):
139+
model_response = "\n".join(c.text for c in content if c.type == "text")
140140
else:
141141
model_response = "No response"
142142

examples/snippets/servers/sampling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def generate_poem(topic: str, ctx: Context[ServerSession, None]) -> str:
2020
max_tokens=100,
2121
)
2222

23-
content = result.content[0] if isinstance(result.content, list) else result.content
24-
if content.type == "text":
25-
return content.text
26-
return str(content)
23+
content = result.content if isinstance(result.content, list) else [result.content]
24+
if all(c.type == "text" for c in content):
25+
return "\n".join(c.text for c in content if c.type == "text")
26+
return str(result.content)

0 commit comments

Comments
 (0)