We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/pydantic/pydantic-ai'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
from typing import Any
from pydantic_ai import ModelMessage, ModelRequestPart, ModelResponsePart
def part_types_from_messages(messages: list[ModelMessage]) -> list[Any]:
"""Utility function used when you are not interested in the content of the messages, but only that the part is there.
As an example, the following messages:
```python
[
ModelRequest(parts=[UserPromptPart(content='')], kind='request'),
ModelResponse(parts=[TextPart(content='')], kind='response'),
]
```
Will return:
```python
[
[UserPromptPart],
[TextPart],
]
```
So each list represents either `ModelRequest` or `ModelResponse` and the parts that are present in the message.
"""
parts: list[Any] = []
for message in messages:
message_parts: list[type[ModelResponsePart | ModelRequestPart]] = []
for part in message.parts:
message_parts.append(type(part))
parts.append(message_parts)
return parts