Skip to content

Commit 874cac6

Browse files
committed
lint + tests
1 parent 42f0c26 commit 874cac6

4 files changed

Lines changed: 307 additions & 35 deletions

File tree

azure/functions/decorators/function_app.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,45 +1685,49 @@ async def wrapper(context: str, *args, **kwargs):
16851685
"content": json.dumps(result_dict),
16861686
"structuredContent": json.dumps(result.structured_content) if result.structured_content else None
16871687
})
1688-
1688+
16891689
# Handle List[ContentBlock] - multiple content blocks
1690-
if isinstance(result, list) and all(isinstance(item, ContentBlock) for item in result):
1690+
if isinstance(result, list) and all(
1691+
isinstance(item, ContentBlock) for item in result):
16911692
content_blocks = [block.to_dict() for block in result]
16921693
return json.dumps({
16931694
"type": "multi_content_result",
16941695
"content": json.dumps(content_blocks)
16951696
})
1696-
1697+
16971698
# Handle single ContentBlock
16981699
if isinstance(result, ContentBlock):
16991700
block_dict = result.to_dict()
17001701
return json.dumps({
17011702
"type": result.type,
17021703
"content": json.dumps(block_dict)
17031704
})
1704-
1705+
17051706
# Handle structured content generation when use_result_schema is True
17061707
if use_result_schema:
17071708
# Check if we should create structured content
17081709
if should_create_structured_content(result):
17091710
# Serialize result as JSON for structured content
17101711
# Handle dataclasses properly
17111712
if dataclasses.is_dataclass(result):
1712-
result_json = json.dumps(dataclasses.asdict(result))
1713+
result_json = json.dumps(
1714+
dataclasses.asdict(result))
17131715
elif hasattr(result, '__dict__'):
17141716
# For regular classes with __dict__
17151717
result_json = json.dumps(result.__dict__)
17161718
else:
17171719
# Fallback to str conversion
1718-
result_json = json.dumps(result) if not isinstance(result, str) else result
1719-
1720+
result_json = json.dumps(
1721+
result) if not isinstance(
1722+
result, str) else result
1723+
17201724
# Return McpToolResult format with both text and structured content
17211725
return json.dumps({
17221726
"type": "text",
17231727
"content": json.dumps({"type": "text", "text": result_json}),
17241728
"structuredContent": result_json
17251729
})
1726-
1730+
17271731
return str(result)
17281732

17291733
wrapper.__signature__ = wrapper_sig

azure/functions/decorators/mcp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,44 +177,44 @@ def has_mcp_content_marker(obj: typing.Any) -> bool:
177177
def should_create_structured_content(obj: typing.Any) -> bool:
178178
"""
179179
Determines whether structured content should be created for the given object.
180-
180+
181181
Returns True if:
182182
- The object's class is decorated with a marker that sets __mcp_content__ = True
183183
- The object is not a primitive type (str, int, float, bool, None)
184184
- The object is not a dict or list (unless explicitly marked)
185-
185+
186186
This mimics the .NET implementation's McpContentAttribute checking.
187187
"""
188188
if obj is None:
189189
return False
190-
190+
191191
# Primitive types don't generate structured content unless explicitly marked
192192
if isinstance(obj, (str, int, float, bool)):
193193
return False
194-
194+
195195
# Check for the marker attribute
196196
return has_mcp_content_marker(obj)
197197

198198

199199
def mcp_content(cls):
200200
"""
201-
Decorator to mark a class as an MCP result type that should be serialized
201+
Decorator to mark a class as an MCP result type that should be serialized
202202
as structured content.
203-
203+
204204
When a function returns an object of a type decorated with this decorator,
205205
the result will be serialized as both text content (for backwards compatibility)
206206
and structured content (for clients that support it).
207-
207+
208208
This is the Python equivalent of C#'s [McpContent] attribute.
209-
209+
210210
Example:
211211
@mcp_content
212212
class ImageMetadata:
213213
def __init__(self, image_id: str, format: str, tags: list):
214214
self.image_id = image_id
215215
self.format = format
216216
self.tags = tags
217-
217+
218218
@app.mcp_tool(use_result_schema=True)
219219
def get_image_info():
220220
return ImageMetadata("logo", "png", ["functions"])

azure/functions/mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CallToolResult:
7777
"""
7878
Result type for MCP tool calls that allows manual construction
7979
of content blocks and structured content.
80-
80+
8181
Example:
8282
return CallToolResult(
8383
content=[

0 commit comments

Comments
 (0)