Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/mcp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,19 @@ class EmptyResult(Result):
"""A response that indicates success but carries no data."""


class Implementation(BaseModel):
"""Describes the name and version of an MCP implementation."""
class BaseMetadata(BaseModel):
"""Base class for entities with name and optional title fields."""

name: str
"""The programmatic name of the entity."""

title: str | None = None
"""An optional human-readable title for the entity."""


class Implementation(BaseMetadata):
"""Describes the name and version of an MCP implementation."""

version: str
model_config = ConfigDict(extra="allow")

Expand Down Expand Up @@ -382,13 +391,11 @@ class Annotations(BaseModel):
model_config = ConfigDict(extra="allow")


class Resource(BaseModel):
class Resource(BaseMetadata):
"""A known resource that the server is capable of reading."""

uri: Annotated[AnyUrl, UrlConstraints(host_required=False)]
"""The URI of this resource."""
name: str
"""A human-readable name for this resource."""
description: str | None = None
"""A description of what this resource represents."""
mimeType: str | None = None
Expand All @@ -409,16 +416,14 @@ class Resource(BaseModel):
model_config = ConfigDict(extra="allow")


class ResourceTemplate(BaseModel):
class ResourceTemplate(BaseMetadata):
"""A template description for resources available on the server."""

uriTemplate: str
"""
A URI template (according to RFC 6570) that can be used to construct resource
URIs.
"""
name: str
"""A human-readable name for the type of resource this template refers to."""
description: str | None = None
"""A human-readable description of what this template is for."""
mimeType: str | None = None
Expand Down Expand Up @@ -601,11 +606,9 @@ class PromptArgument(BaseModel):
model_config = ConfigDict(extra="allow")


class Prompt(BaseModel):
class Prompt(BaseMetadata):
"""A prompt or prompt template that the server offers."""

name: str
"""The name of the prompt or prompt template."""
description: str | None = None
"""An optional description of what this prompt provides."""
arguments: list[PromptArgument] | None = None
Expand Down Expand Up @@ -808,11 +811,9 @@ class ToolAnnotations(BaseModel):
model_config = ConfigDict(extra="allow")


class Tool(BaseModel):
class Tool(BaseMetadata):
"""Definition for a tool the client can call."""

name: str
"""The name of the tool."""
description: str | None = None
"""A human-readable description of the tool."""
inputSchema: dict[str, Any]
Expand Down