Skip to content

Commit b1d944a

Browse files
committed
update snippets using content_as_list
1 parent 287df90 commit b1d944a

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ async def generate_poem(topic: str, ctx: Context[ServerSession, None]) -> str:
887887
)
888888

889889
if all(c.type == "text" for c in result.content_as_list):
890-
return '\n'.join(c.text for c in result.content_as_list if c.type == "text")
890+
return "\n".join(c.text for c in result.content_as_list if c.type == "text")
891891
return str(result.content)
892892
```
893893

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

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

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")
137+
if any(c.type == "text" for c in result.content_as_list):
138+
model_response = "\n".join(c.text for c in result.content_as_list if c.type == "text")
140139
else:
141140
model_response = "No response"
142141

examples/snippets/servers/sampling.py

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

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")
23+
if all(c.type == "text" for c in result.content_as_list):
24+
return "\n".join(c.text for c in result.content_as_list if c.type == "text")
2625
return str(result.content)

0 commit comments

Comments
 (0)