-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Embed code snippets for README from executable examples #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e7d79e0
everything server for REAME snippets
ihrpr f02996c
simplitfy readme for everything server
ihrpr 1bbacf7
more comment simplifications
ihrpr da0c986
security suggestions
ihrpr 6e5b666
CI fixes
ihrpr d67ad08
remove readme from lint
ihrpr c4486f8
update contributing
ihrpr 3a70805
120 for docs as well...
ihrpr 3203841
use ruff in snippets tests
ihrpr 61ec764
Merge branch 'main' into ihrpr/readme-from-examples
ihrpr 73676a5
use small servers
ihrpr a9e8122
add snipets to workspace
ihrpr 16ac8eb
ruff
ihrpr 6c8011b
update server names in tests
ihrpr b318929
remove characters
ihrpr 7457804
replace chars
ihrpr d1604b1
remove everything server
ihrpr ddb2440
update docs
ihrpr 395f60c
simplify init
ihrpr 982b115
ruff
ihrpr 78ff6c9
clean up after review comments
ihrpr 81b423e
remove line extractoin
ihrpr d42be5a
indent
ihrpr 4f326bd
Merge branch 'main' into ihrpr/readme-from-examples
ihrpr b1a0913
ruff
ihrpr 926c5f8
readme after ruff
ihrpr 478ce05
tests
ihrpr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -419,21 +419,27 @@ def create_thumbnail(image_path: str) -> Image: | |
|
|
||
| The Context object gives your tools and resources access to MCP capabilities: | ||
|
|
||
| <!-- snippet-source examples/servers/everything/src/everything/server.py#L43-L58 --> | ||
|
||
| ```python | ||
| from mcp.server.fastmcp import FastMCP, Context | ||
|
|
||
| mcp = FastMCP("My App") | ||
|
|
||
| # Tool with context for logging and progress | ||
| @mcp.tool(description="A tool that demonstrates logging and progress", title="Progress Tool") | ||
| async def tool_with_progress(message: str, ctx: Context, steps: int = 3) -> str: | ||
| await ctx.info(f"Starting processing of '{message}' with {steps} steps") | ||
|
|
||
| # Send progress notifications | ||
| for i in range(steps): | ||
| progress_value = (i + 1) / steps | ||
| await ctx.report_progress( | ||
| progress=progress_value, | ||
| total=1.0, | ||
| message=f"Processing step {i + 1} of {steps}", | ||
| ) | ||
| await ctx.debug(f"Completed step {i + 1}") | ||
|
|
||
| @mcp.tool() | ||
| async def long_task(files: list[str], ctx: Context) -> str: | ||
| """Process multiple files with progress tracking""" | ||
| for i, file in enumerate(files): | ||
| ctx.info(f"Processing {file}") | ||
| await ctx.report_progress(i, len(files)) | ||
| data, mime_type = await ctx.read_resource(f"file://{file}") | ||
| return "Processing complete" | ||
| return f"Processed '{message}' in {steps} steps" | ||
| ``` | ||
| _Full example: [examples/servers/everything/src/everything/server.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/servers/everything/src/everything/server.py#L43-L58)_ | ||
| <!-- /snippet-source --> | ||
|
|
||
| ### Completions | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # MCP Everything Server | ||
|
|
||
| A comprehensive example MCP server that demonstrates all features of the Model Context Protocol, including: | ||
|
|
||
| - Tools with progress reporting, logging, and elicitation | ||
| - Resource handling (static, dynamic, and templated) | ||
| - Prompts with arguments | ||
| - Completion support for resource templates and prompts | ||
| - Request context propagation | ||
| - Notifications and logging | ||
| - Sampling capabilities | ||
| - Structured output | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Running the server | ||
|
|
||
| ```bash | ||
| uv run mcp-server-everything | ||
| ``` | ||
|
|
||
| ### Testing with MCP Inspector | ||
|
|
||
| ```bash | ||
| mcp dev "uv run mcp-server-everything" | ||
| ``` | ||
|
|
||
| ### Installing in Claude Desktop | ||
|
|
||
| ```bash | ||
| mcp install "uv run mcp-server-everything" --name "Everything Server" | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| This server demonstrates: | ||
|
|
||
| - **Tools**: Echo, progress tracking, sampling, notifications, context access, elicitation | ||
| - **Resources**: Static resources, dynamic resources with parameters, resource templates | ||
| - **Prompts**: Simple and complex prompts with arguments | ||
| - **Completions**: Context-aware completion for prompts and resource templates | ||
| - **Notifications**: Progress updates, logging at different levels, resource/tool list changes | ||
| - **Elicitation**: Interactive user input during tool execution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [project] | ||
| name = "mcp-server-everything" | ||
| version = "0.1.0" | ||
| description = "Comprehensive MCP server demonstrating all protocol features" | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "mcp", | ||
| "pydantic>=2.0", | ||
| "httpx", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| mcp-server-everything = "everything.__main__:main" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """MCP Everything Server - Comprehensive example demonstrating all MCP features.""" | ||
|
|
||
| from .server import create_everything_server | ||
|
|
||
| __all__ = ["create_everything_server"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Main entry point for the Everything Server.""" | ||
|
|
||
| from .server import create_everything_server | ||
|
|
||
|
|
||
| def main(): | ||
| """Run the everything server.""" | ||
| mcp = create_everything_server() | ||
| # Use FastMCP's built-in run method for better CLI integration | ||
| mcp.run(transport="sse") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.