refactor: use snake case instead of camel case in types (#1894)
This commit is contained in:
parent
7080fcf1e6
commit
e94b386a13
10 changed files with 1063 additions and 1057 deletions
|
|
@ -98,13 +98,13 @@ def test_simple_text() -> str:
|
|||
@mcp.tool()
|
||||
def test_image_content() -> list[ImageContent]:
|
||||
"""Tests image content response"""
|
||||
return [ImageContent(type="image", data=TEST_IMAGE_BASE64, mimeType="image/png")]
|
||||
return [ImageContent(type="image", data=TEST_IMAGE_BASE64, mime_type="image/png")]
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def test_audio_content() -> list[AudioContent]:
|
||||
"""Tests audio content response"""
|
||||
return [AudioContent(type="audio", data=TEST_AUDIO_BASE64, mimeType="audio/wav")]
|
||||
return [AudioContent(type="audio", data=TEST_AUDIO_BASE64, mime_type="audio/wav")]
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
@ -115,7 +115,7 @@ def test_embedded_resource() -> list[EmbeddedResource]:
|
|||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="test://embedded-resource",
|
||||
mimeType="text/plain",
|
||||
mime_type="text/plain",
|
||||
text="This is an embedded resource content.",
|
||||
),
|
||||
)
|
||||
|
|
@ -127,12 +127,12 @@ def test_multiple_content_types() -> list[TextContent | ImageContent | EmbeddedR
|
|||
"""Tests response with multiple content types (text, image, resource)"""
|
||||
return [
|
||||
TextContent(type="text", text="Multiple content types test:"),
|
||||
ImageContent(type="image", data=TEST_IMAGE_BASE64, mimeType="image/png"),
|
||||
ImageContent(type="image", data=TEST_IMAGE_BASE64, mime_type="image/png"),
|
||||
EmbeddedResource(
|
||||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="test://mixed-content-resource",
|
||||
mimeType="application/json",
|
||||
mime_type="application/json",
|
||||
text='{"test": "data", "value": 123}',
|
||||
),
|
||||
),
|
||||
|
|
@ -164,7 +164,7 @@ async def test_tool_with_progress(ctx: Context[ServerSession, None]) -> str:
|
|||
await ctx.report_progress(progress=100, total=100, message="Completed step 100 of 100")
|
||||
|
||||
# Return progress token as string
|
||||
progress_token = ctx.request_context.meta.progressToken if ctx.request_context and ctx.request_context.meta else 0
|
||||
progress_token = ctx.request_context.meta.progress_token if ctx.request_context and ctx.request_context.meta else 0
|
||||
return str(progress_token)
|
||||
|
||||
|
||||
|
|
@ -373,7 +373,7 @@ def test_prompt_with_embedded_resource(resourceUri: str) -> list[UserMessage]:
|
|||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri=resourceUri,
|
||||
mimeType="text/plain",
|
||||
mime_type="text/plain",
|
||||
text="Embedded resource content for testing.",
|
||||
),
|
||||
),
|
||||
|
|
@ -386,7 +386,7 @@ def test_prompt_with_embedded_resource(resourceUri: str) -> list[UserMessage]:
|
|||
def test_prompt_with_image() -> list[UserMessage]:
|
||||
"""A prompt that includes image content"""
|
||||
return [
|
||||
UserMessage(role="user", content=ImageContent(type="image", data=TEST_IMAGE_BASE64, mimeType="image/png")),
|
||||
UserMessage(role="user", content=ImageContent(type="image", data=TEST_IMAGE_BASE64, mime_type="image/png")),
|
||||
UserMessage(role="user", content=TextContent(type="text", text="Please analyze the image above.")),
|
||||
]
|
||||
|
||||
|
|
@ -427,7 +427,7 @@ async def _handle_completion(
|
|||
"""Handle completion requests"""
|
||||
# Basic completion support - returns empty array for conformance
|
||||
# Real implementations would provide contextual suggestions
|
||||
return Completion(values=[], total=0, hasMore=False)
|
||||
return Completion(values=[], total=0, has_more=False)
|
||||
|
||||
|
||||
# CLI
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ SAMPLE_TOOLS = [
|
|||
name=f"tool_{i}",
|
||||
title=f"Tool {i}",
|
||||
description=f"This is sample tool number {i}",
|
||||
inputSchema={"type": "object", "properties": {"input": {"type": "string"}}},
|
||||
input_schema={"type": "object", "properties": {"input": {"type": "string"}}},
|
||||
)
|
||||
for i in range(1, 26) # 25 tools total
|
||||
]
|
||||
|
|
@ -71,7 +71,7 @@ def main(port: int, transport: str) -> int:
|
|||
start_idx = int(cursor)
|
||||
except (ValueError, TypeError):
|
||||
# Invalid cursor, return empty
|
||||
return types.ListToolsResult(tools=[], nextCursor=None)
|
||||
return types.ListToolsResult(tools=[], next_cursor=None)
|
||||
|
||||
# Get the page of tools
|
||||
page_tools = SAMPLE_TOOLS[start_idx : start_idx + page_size]
|
||||
|
|
@ -81,7 +81,7 @@ def main(port: int, transport: str) -> int:
|
|||
if start_idx + page_size < len(SAMPLE_TOOLS):
|
||||
next_cursor = str(start_idx + page_size)
|
||||
|
||||
return types.ListToolsResult(tools=page_tools, nextCursor=next_cursor)
|
||||
return types.ListToolsResult(tools=page_tools, next_cursor=next_cursor)
|
||||
|
||||
# Paginated list_resources - returns 10 resources per page
|
||||
@app.list_resources()
|
||||
|
|
@ -100,7 +100,7 @@ def main(port: int, transport: str) -> int:
|
|||
start_idx = int(cursor)
|
||||
except (ValueError, TypeError):
|
||||
# Invalid cursor, return empty
|
||||
return types.ListResourcesResult(resources=[], nextCursor=None)
|
||||
return types.ListResourcesResult(resources=[], next_cursor=None)
|
||||
|
||||
# Get the page of resources
|
||||
page_resources = SAMPLE_RESOURCES[start_idx : start_idx + page_size]
|
||||
|
|
@ -110,7 +110,7 @@ def main(port: int, transport: str) -> int:
|
|||
if start_idx + page_size < len(SAMPLE_RESOURCES):
|
||||
next_cursor = str(start_idx + page_size)
|
||||
|
||||
return types.ListResourcesResult(resources=page_resources, nextCursor=next_cursor)
|
||||
return types.ListResourcesResult(resources=page_resources, next_cursor=next_cursor)
|
||||
|
||||
# Paginated list_prompts - returns 7 prompts per page
|
||||
@app.list_prompts()
|
||||
|
|
@ -129,7 +129,7 @@ def main(port: int, transport: str) -> int:
|
|||
start_idx = int(cursor)
|
||||
except (ValueError, TypeError):
|
||||
# Invalid cursor, return empty
|
||||
return types.ListPromptsResult(prompts=[], nextCursor=None)
|
||||
return types.ListPromptsResult(prompts=[], next_cursor=None)
|
||||
|
||||
# Get the page of prompts
|
||||
page_prompts = SAMPLE_PROMPTS[start_idx : start_idx + page_size]
|
||||
|
|
@ -139,7 +139,7 @@ def main(port: int, transport: str) -> int:
|
|||
if start_idx + page_size < len(SAMPLE_PROMPTS):
|
||||
next_cursor = str(start_idx + page_size)
|
||||
|
||||
return types.ListPromptsResult(prompts=page_prompts, nextCursor=next_cursor)
|
||||
return types.ListPromptsResult(prompts=page_prompts, next_cursor=next_cursor)
|
||||
|
||||
# Implement call_tool handler
|
||||
@app.call_tool()
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def main(port: int, transport: str) -> int:
|
|||
name=name,
|
||||
title=SAMPLE_RESOURCES[name]["title"],
|
||||
description=f"A sample text resource named {name}",
|
||||
mimeType="text/plain",
|
||||
mime_type="text/plain",
|
||||
)
|
||||
for name in SAMPLE_RESOURCES.keys()
|
||||
]
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ def main(
|
|||
types.Tool(
|
||||
name="start-notification-stream",
|
||||
description=("Sends a stream of notifications with configurable count and interval"),
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"required": ["interval", "count", "caller"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ def main(
|
|||
types.Tool(
|
||||
name="start-notification-stream",
|
||||
description=("Sends a stream of notifications with configurable count and interval"),
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"required": ["interval", "count", "caller"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ async def list_tools() -> list[types.Tool]:
|
|||
types.Tool(
|
||||
name="confirm_delete",
|
||||
description="Asks for confirmation before deleting (demonstrates elicitation)",
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"properties": {"filename": {"type": "string"}},
|
||||
},
|
||||
execution=types.ToolExecution(taskSupport=types.TASK_REQUIRED),
|
||||
execution=types.ToolExecution(task_support=types.TASK_REQUIRED),
|
||||
),
|
||||
types.Tool(
|
||||
name="write_haiku",
|
||||
description="Asks LLM to write a haiku (demonstrates sampling)",
|
||||
inputSchema={"type": "object", "properties": {"topic": {"type": "string"}}},
|
||||
execution=types.ToolExecution(taskSupport=types.TASK_REQUIRED),
|
||||
input_schema={"type": "object", "properties": {"topic": {"type": "string"}}},
|
||||
execution=types.ToolExecution(task_support=types.TASK_REQUIRED),
|
||||
),
|
||||
]
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ async def handle_confirm_delete(arguments: dict[str, Any]) -> types.CreateTaskRe
|
|||
|
||||
result = await task.elicit(
|
||||
message=f"Are you sure you want to delete '{filename}'?",
|
||||
requestedSchema={
|
||||
requested_schema={
|
||||
"type": "object",
|
||||
"properties": {"confirm": {"type": "boolean"}},
|
||||
"required": ["confirm"],
|
||||
|
|
@ -121,7 +121,7 @@ async def handle_call_tool(name: str, arguments: dict[str, Any]) -> types.CallTo
|
|||
else:
|
||||
return types.CallToolResult(
|
||||
content=[types.TextContent(type="text", text=f"Unknown tool: {name}")],
|
||||
isError=True,
|
||||
is_error=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ async def list_tools() -> list[types.Tool]:
|
|||
types.Tool(
|
||||
name="long_running_task",
|
||||
description="A task that takes a few seconds to complete with status updates",
|
||||
inputSchema={"type": "object", "properties": {}},
|
||||
execution=types.ToolExecution(taskSupport=types.TASK_REQUIRED),
|
||||
input_schema={"type": "object", "properties": {}},
|
||||
execution=types.ToolExecution(task_support=types.TASK_REQUIRED),
|
||||
)
|
||||
]
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ async def handle_call_tool(name: str, arguments: dict[str, Any]) -> types.CallTo
|
|||
else:
|
||||
return types.CallToolResult(
|
||||
content=[types.TextContent(type="text", text=f"Unknown tool: {name}")],
|
||||
isError=True,
|
||||
is_error=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def main(port: int, transport: str) -> int:
|
|||
name="fetch",
|
||||
title="Website Fetcher",
|
||||
description="Fetches a website and returns its content",
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"required": ["url"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ def main(port: int, log_level: str, retry_interval: int) -> int:
|
|||
"Process a batch of items with periodic checkpoints. "
|
||||
"Demonstrates SSE polling where server closes stream periodically."
|
||||
),
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"items": {
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ async def list_tools() -> list[types.Tool]:
|
|||
types.Tool(
|
||||
name="get_weather",
|
||||
description="Get weather information (simulated)",
|
||||
inputSchema={
|
||||
input_schema={
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string", "description": "City name"}},
|
||||
"required": ["city"],
|
||||
},
|
||||
outputSchema={
|
||||
output_schema={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"temperature": {"type": "number"},
|
||||
|
|
|
|||
Loading…
Reference in a new issue