Add resource Link (#974)

This commit is contained in:
Inna Harper 2025-06-17 20:23:07 +01:00 • committed by GitHub
commit d0443a1832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 22 deletions

View file

@ -7,16 +7,16 @@ from typing import Any, Literal
import pydantic_core
from pydantic import BaseModel, Field, TypeAdapter, validate_call
from mcp.types import Content, TextContent
from mcp.types import ContentBlock, TextContent
class Message(BaseModel):
"""Base class for all prompt messages."""
role: Literal["user", "assistant"]
content: Content
content: ContentBlock
def __init__(self, content: str | Content, **kwargs: Any):
def __init__(self, content: str | ContentBlock, **kwargs: Any):
if isinstance(content, str):
content = TextContent(type="text", text=content)
super().__init__(content=content, **kwargs)
@ -27,7 +27,7 @@ class UserMessage(Message):
role: Literal["user", "assistant"] = "user"
def __init__(self, content: str | Content, **kwargs: Any):
def __init__(self, content: str | ContentBlock, **kwargs: Any):
super().__init__(content=content, **kwargs)
@ -36,7 +36,7 @@ class AssistantMessage(Message):
role: Literal["user", "assistant"] = "assistant"
def __init__(self, content: str | Content, **kwargs: Any):
def __init__(self, content: str | ContentBlock, **kwargs: Any):
super().__init__(content=content, **kwargs)

View file

@ -54,7 +54,7 @@ from mcp.server.transport_security import TransportSecuritySettings
from mcp.shared.context import LifespanContextT, RequestContext, RequestT
from mcp.types import (
AnyFunction,
Content,
ContentBlock,
GetPromptResult,
TextContent,
ToolAnnotations,
@ -260,7 +260,7 @@ class FastMCP:
request_context = None
return Context(request_context=request_context, fastmcp=self)
async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[Content]:
async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[ContentBlock]:
"""Call a tool by name with arguments."""
context = self.get_context()
result = await self._tool_manager.call_tool(name, arguments, context=context)
@ -878,12 +878,12 @@ class FastMCP:
def _convert_to_content(
result: Any,
) -> Sequence[Content]:
) -> Sequence[ContentBlock]:
"""Convert a result to a sequence of content objects."""
if result is None:
return []
if isinstance(result, Content):
if isinstance(result, ContentBlock):
return [result]
if isinstance(result, Image):

View file

@ -384,7 +384,7 @@ class Server(Generic[LifespanResultT, RequestT]):
def decorator(
func: Callable[
...,
Awaitable[Iterable[types.Content]],
Awaitable[Iterable[types.ContentBlock]],
],
):
logger.debug("Registering handler for CallToolRequest")