Skip to content

Commit cf15e71

Browse files
olaservoclaude
andcommitted
Align with repo conventions: American spelling, top-level test function
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 2b30123 commit cf15e71

4 files changed

Lines changed: 30 additions & 29 deletions

File tree

src/mcp/server/mcpserver/server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,10 @@ def add_tool(
593593
- If None, auto-detects based on the function's return type annotation
594594
- If True, creates a structured tool (return type annotation permitting)
595595
- If False, unconditionally creates an unstructured tool
596-
mirror_structured_content: Whether structured output is also serialised into a
596+
mirror_structured_content: Whether structured output is also serialized into a
597597
`content` text block alongside `structuredContent` (the spec's SHOULD,
598598
default True). Set False to send `structuredContent` only, without the
599-
duplicate serialised copy on the wire.
599+
duplicate serialized copy on the wire.
600600
"""
601601
self._tool_manager.add_tool(
602602
fn,
@@ -649,10 +649,10 @@ def tool(
649649
- If None, auto-detects based on the function's return type annotation
650650
- If True, creates a structured tool (return type annotation permitting)
651651
- If False, unconditionally creates an unstructured tool
652-
mirror_structured_content: Whether structured output is also serialised into a
652+
mirror_structured_content: Whether structured output is also serialized into a
653653
`content` text block alongside `structuredContent` (the spec's SHOULD,
654654
default True). Set False to send `structuredContent` only, without the
655-
duplicate serialised copy on the wire.
655+
duplicate serialized copy on the wire.
656656
657657
Example:
658658
```python

src/mcp/server/mcpserver/tools/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Tool(BaseModel):
5151
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this tool")
5252
mirror_structured_content: bool = Field(
5353
default=True,
54-
description="Whether structured output is also mirrored into a serialised text content block",
54+
description="Whether structured output is also mirrored into a serialized text content block",
5555
)
5656

5757
@cached_property

src/mcp/server/mcpserver/utilities/func_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def convert_result(
117117
being JSON-dumped into a text block.
118118
119119
For a tool with an output schema, the structured output is returned as
120-
`structuredContent`. By default it is *also* serialised into a `content`
120+
`structuredContent`. By default it is *also* serialized into a `content`
121121
text block -- the spec's SHOULD, which keeps the value available to a
122122
client that consumes `content`. When ``mirror_structured_content`` is
123-
False that serialised copy is omitted and `structuredContent` is the only
123+
False that serialized copy is omitted and `structuredContent` is the only
124124
representation on the wire, so the same payload is not sent twice. Because
125-
the serialised-text guidance is a SHOULD (not a MUST), opting out stays
125+
the serialized-text guidance is a SHOULD (not a MUST), opting out stays
126126
conformant. The SDK makes no assumption about which field a client routes
127127
to a model versus elsewhere; that is the client's choice.
128128
"""

tests/server/mcpserver/test_server.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -537,27 +537,6 @@ def get_user(user_id: int) -> UserOutput:
537537
assert isinstance(result.content[0], TextContent)
538538
assert '"name": "John Doe"' in result.content[0].text
539539

540-
async def test_tool_mirror_structured_content_false_omits_text_block(self):
541-
"""mirror_structured_content=False returns structuredContent only, with empty content."""
542-
543-
class UserOutput(BaseModel):
544-
name: str
545-
age: int
546-
547-
mcp = MCPServer()
548-
549-
@mcp.tool(mirror_structured_content=False)
550-
def get_user(user_id: int) -> UserOutput:
551-
"""Get user by ID"""
552-
return UserOutput(name="John Doe", age=30)
553-
554-
async with Client(mcp) as client:
555-
result = await client.call_tool("get_user", {"user_id": 123})
556-
assert result.is_error is False
557-
assert result.structured_content == {"name": "John Doe", "age": 30}
558-
# The serialised text mirror is suppressed; structuredContent is the sole representation.
559-
assert result.content == []
560-
561540
async def test_tool_structured_output_primitive(self):
562541
"""Test tool with structured output returning primitive type"""
563542

@@ -2366,3 +2345,25 @@ def greeting() -> str: # pragma: no cover
23662345
assert mcp._prompt_manager.list_prompts() == []
23672346
with pytest.raises(ValueError, match="Unknown prompt: greeting"):
23682347
mcp.remove_prompt("greeting")
2348+
2349+
2350+
async def test_tool_mirror_structured_content_false_omits_text_block():
2351+
"""mirror_structured_content=False returns structuredContent only, with empty content."""
2352+
2353+
class UserOutput(BaseModel):
2354+
name: str
2355+
age: int
2356+
2357+
mcp = MCPServer()
2358+
2359+
@mcp.tool(mirror_structured_content=False)
2360+
def get_user(user_id: int) -> UserOutput:
2361+
"""Get user by ID"""
2362+
return UserOutput(name="John Doe", age=30)
2363+
2364+
async with Client(mcp) as client:
2365+
result = await client.call_tool("get_user", {"user_id": 123})
2366+
assert result.is_error is False
2367+
assert result.structured_content == {"name": "John Doe", "age": 30}
2368+
# The serialized text mirror is suppressed; structuredContent is the sole representation.
2369+
assert result.content == []

0 commit comments

Comments
 (0)