Skip to content

Commit 200f701

Browse files
authored
Merge branch 'main' into fix-pydantic-2.12-field-defaults
2 parents e091c48 + be73067 commit 200f701

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Applied 120 line-length rule to all files: https://github.com/modelcontextprotocol/python-sdk/pull/856
22
543961968c0634e93d919d509cce23a1d6a56c21
3+
4+
# Added 100% code coverage baseline with pragma comments: https://github.com/modelcontextprotocol/python-sdk/pull/1553
5+
89e9c43acf7e23cf766357d776ec1ce63ac2c58e

examples/servers/everything-server/mcp_everything_server/server.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,38 @@ async def test_elicitation(message: str, ctx: Context[ServerSession, None]) -> s
166166
return f"Elicitation not supported or error: {str(e)}"
167167

168168

169+
class SEP1034DefaultsSchema(BaseModel):
170+
"""Schema for testing SEP-1034 elicitation with default values for all primitive types"""
171+
172+
name: str = Field(default="John Doe", description="User name")
173+
age: int = Field(default=30, description="User age")
174+
score: float = Field(default=95.5, description="User score")
175+
status: str = Field(
176+
default="active",
177+
description="User status",
178+
json_schema_extra={"enum": ["active", "inactive", "pending"]},
179+
)
180+
verified: bool = Field(default=True, description="Verification status")
181+
182+
183+
@mcp.tool()
184+
async def test_elicitation_sep1034_defaults(ctx: Context[ServerSession, None]) -> str:
185+
"""Tests elicitation with default values for all primitive types (SEP-1034)"""
186+
try:
187+
# Request user input with defaults for all primitive types
188+
result = await ctx.elicit(message="Please provide user information", schema=SEP1034DefaultsSchema)
189+
190+
# Type-safe discriminated union narrowing using action field
191+
if result.action == "accept":
192+
content = result.data.model_dump_json()
193+
else: # decline or cancel
194+
content = "{}"
195+
196+
return f"Elicitation result: action={result.action}, content={content}"
197+
except Exception as e:
198+
return f"Elicitation not supported or error: {str(e)}"
199+
200+
169201
@mcp.tool()
170202
def test_error_handling() -> str:
171203
"""Tests error response handling"""

0 commit comments

Comments
 (0)