Skip to content

Commit be73067

Browse files
Add SEP-1034 conformance test support to everything-server (#1604)
Co-authored-by: Max Isbey <[email protected]>
1 parent 720d713 commit be73067

File tree

1 file changed

+32
-0
lines changed
  • examples/servers/everything-server/mcp_everything_server

1 file changed

+32
-0
lines changed

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)