Skip to content

Commit 0a894ae

Browse files
Add SEP-1034 elicitation defaults support to everything-server
Adds a new tool `test_elicitation_sep1034_defaults` that demonstrates elicitation with default values for all JSON Schema primitive types (string, integer, number, enum, boolean) as specified in SEP-1034. This enables conformance testing of SEP-1034 against the Python SDK implementation. All 5 conformance checks pass: - String default value support - Integer default value support - Number default value support - Enum default value support - Boolean default value support (regression test) The implementation uses Pydantic Field defaults which are automatically included in the generated JSON schema passed to the elicitation request.
1 parent da4fce2 commit 0a894ae

File tree

1 file changed

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

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import base64
1010
import json
1111
import logging
12+
from typing import Literal
1213

1314
import click
1415
from mcp.server.fastmcp import Context, FastMCP
@@ -166,6 +167,38 @@ async def test_elicitation(message: str, ctx: Context[ServerSession, None]) -> s
166167
return f"Elicitation not supported or error: {str(e)}"
167168

168169

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

0 commit comments

Comments
 (0)