Skip to content

Commit 9882e20

Browse files
Improve code organization in everything-server
Add descriptive section headers and logical grouping to improve readability: - Group tools by category (simple, complex, async, error handling) - Add explanatory comments for each section - Maintain single-file structure for reference implementation This makes it easier to understand the different features being demonstrated without changing any functionality.
1 parent 670936e commit 9882e20

File tree

1 file changed

+27
-6
lines changed
  • examples/servers/everything-server/mcp_everything_server

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353

5454
# ===== TOOLS =====
5555

56+
# --- Simple Content Tools ---
57+
# Tools that return a single content type (text, image, audio)
58+
5659

5760
@mcp.tool()
5861
def test_simple_text() -> str:
@@ -72,6 +75,10 @@ def test_audio_content() -> list[AudioContent]:
7275
return [AudioContent(type="audio", data=TEST_AUDIO_BASE64, mimeType="audio/wav")]
7376

7477

78+
# --- Complex Content Tools ---
79+
# Tools with embedded resources or multiple content types
80+
81+
7582
@mcp.tool()
7683
def test_embedded_resource() -> list[EmbeddedResource]:
7784
"""Tests embedded resource content response"""
@@ -104,6 +111,10 @@ def test_multiple_content_types() -> list[TextContent | ImageContent | EmbeddedR
104111
]
105112

106113

114+
# --- Async Tools ---
115+
# Tools that demonstrate async operations, logging, progress, sampling, and elicitation
116+
117+
107118
@mcp.tool()
108119
async def test_tool_with_logging(ctx: Context[ServerSession, None]) -> str:
109120
"""Tests tool that emits log messages during execution"""
@@ -133,12 +144,6 @@ async def test_tool_with_progress(ctx: Context[ServerSession, None]) -> str:
133144
return str(progress_token)
134145

135146

136-
@mcp.tool()
137-
def test_error_handling() -> str:
138-
"""Tests error response handling"""
139-
raise RuntimeError("This tool intentionally returns an error for testing")
140-
141-
142147
class SamplingInput(BaseModel):
143148
prompt: str = Field(description="The prompt to send to the LLM")
144149

@@ -189,8 +194,20 @@ async def test_elicitation(message: str, ctx: Context[ServerSession, None]) -> s
189194
return f"Elicitation not supported or error: {str(e)}"
190195

191196

197+
# --- Error Handling Tools ---
198+
# Tools that test error handling behavior
199+
200+
201+
@mcp.tool()
202+
def test_error_handling() -> str:
203+
"""Tests error response handling"""
204+
raise RuntimeError("This tool intentionally returns an error for testing")
205+
206+
192207
# ===== RESOURCES =====
193208

209+
# Static and dynamic resources demonstrating text, binary, templates, and subscriptions
210+
194211

195212
@mcp.resource("test://static-text")
196213
def static_text_resource() -> str:
@@ -222,6 +239,8 @@ def watched_resource() -> str:
222239

223240
# ===== PROMPTS =====
224241

242+
# Prompts demonstrating simple text, arguments, embedded resources, and images
243+
225244

226245
@mcp.prompt()
227246
def test_simple_prompt() -> list[UserMessage]:
@@ -269,6 +288,8 @@ def test_prompt_with_image() -> list[UserMessage]:
269288

270289
# ===== CUSTOM REQUEST HANDLERS =====
271290

291+
# Handlers for logging level control, resource subscriptions, and completion
292+
272293

273294
def setup_custom_handlers():
274295
"""Set up custom request handlers for logging and completion."""

0 commit comments

Comments
 (0)