mirror of
https://github.com/open-webui/mcpo
synced 2025-06-26 18:26:58 +00:00
feat: image content handling
This commit is contained in:
parent
74dd291192
commit
074a8d4a0e
@ -77,13 +77,26 @@ async def create_dynamic_endpoints(app: FastAPI, api_dependency=None):
|
|||||||
result = await session.call_tool(endpoint_name, arguments=args)
|
result = await session.call_tool(endpoint_name, arguments=args)
|
||||||
response = []
|
response = []
|
||||||
for content in result.content:
|
for content in result.content:
|
||||||
text = content.text
|
if isinstance(content, types.TextContent):
|
||||||
if isinstance(text, str):
|
text = content.text
|
||||||
try:
|
if isinstance(text, str):
|
||||||
text = json.loads(text)
|
try:
|
||||||
except json.JSONDecodeError:
|
text = json.loads(text)
|
||||||
pass
|
except json.JSONDecodeError:
|
||||||
response.append(text)
|
pass
|
||||||
|
response.append(text)
|
||||||
|
elif isinstance(content, types.ImageContent):
|
||||||
|
image_data = content.data
|
||||||
|
|
||||||
|
if isinstance(image_data, bytes):
|
||||||
|
image_data = image_data.decode("utf-8")
|
||||||
|
|
||||||
|
image_data = f"data:{content.mimeType};base64,{image_data}"
|
||||||
|
response.append(image_data)
|
||||||
|
elif isinstance(content, types.EmbeddedResource):
|
||||||
|
# TODO: Handle embedded resources
|
||||||
|
response.append("Embedded resource not supported yet.")
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
return tool_endpoint
|
return tool_endpoint
|
||||||
|
Loading…
Reference in New Issue
Block a user