Skip to content

Commit 44ec763

Browse files
committed
Fix READMEs of examples
1 parent 15ed7cb commit 44ec763

File tree

8 files changed

+83
-64
lines changed

8 files changed

+83
-64
lines changed

examples/servers/simple-prompt/README.md

+31-18
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Start the server using either stdio (default) or SSE transport:
88

99
```bash
1010
# Using stdio transport (default)
11-
mcp-simple-prompt
11+
uv mcp-simple-prompt
1212

1313
# Using SSE transport on custom port
14-
mcp-simple-prompt --transport sse --port 8000
14+
uv run mcp-simple-prompt --transport sse --port 8000
1515
```
1616

1717
The server exposes a prompt named "simple" that accepts two optional arguments:
@@ -21,22 +21,35 @@ The server exposes a prompt named "simple" that accepts two optional arguments:
2121

2222
## Example
2323

24-
Using the MCP client, you can retrieve the prompt like this:
24+
Using the MCP client, you can retrieve the prompt like this using the STDIO transport:
2525

2626
```python
27-
from mcp.client import ClientSession
28-
29-
async with ClientSession() as session:
30-
await session.initialize()
31-
32-
# List available prompts
33-
prompts = await session.list_prompts()
34-
print(prompts)
35-
36-
# Get the prompt with arguments
37-
prompt = await session.get_prompt("simple", {
38-
"context": "User is a software developer",
39-
"topic": "Python async programming"
40-
})
41-
print(prompt)
27+
import asyncio
28+
from mcp.client.session import ClientSession
29+
from mcp.client.stdio import StdioServerParameters, stdio_client
30+
31+
32+
async def main():
33+
async with stdio_client(
34+
StdioServerParameters(command="uv", args=["run", "mcp-simple-prompt"])
35+
) as (read, write):
36+
async with ClientSession(read, write) as session:
37+
await session.initialize()
38+
39+
# List available prompts
40+
prompts = await session.list_prompts()
41+
print(prompts)
42+
43+
# Get the prompt with arguments
44+
prompt = await session.get_prompt(
45+
"simple",
46+
{
47+
"context": "User is a software developer",
48+
"topic": "Python async programming",
49+
},
50+
)
51+
print(prompt)
52+
53+
54+
asyncio.run(main())
4255
```
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
22

3-
from server import main
3+
from .server import main
44

55
sys.exit(main())

examples/servers/simple-prompt/mcp_simple_prompt/server.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ def create_messages(
3737
return messages
3838

3939

40-
@click.group()
41-
def cli():
42-
pass
43-
44-
40+
@click.command()
4541
@click.option("--port", default=8000, help="Port to listen on for SSE")
4642
@click.option(
4743
"--transport",

examples/servers/simple-resource/README.md

+24-12
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,41 @@ Start the server using either stdio (default) or SSE transport:
88

99
```bash
1010
# Using stdio transport (default)
11-
mcp-simple-resource
11+
uv run mcp-simple-resource
1212

1313
# Using SSE transport on custom port
14-
mcp-simple-resource --transport sse --port 8000
14+
uv run mcp-simple-resource --transport sse --port 8000
1515
```
1616

1717
The server exposes some basic text file resources that can be read by clients.
1818

1919
## Example
2020

21-
Using the MCP client, you can read the resources like this:
21+
Using the MCP client, you can retrieve resources like this using the STDIO transport:
2222

2323
```python
24-
from mcp.client import ClientSession
24+
import asyncio
25+
from mcp.types import AnyUrl
26+
from mcp.client.session import ClientSession
27+
from mcp.client.stdio import StdioServerParameters, stdio_client
2528

26-
async with ClientSession() as session:
27-
await session.initialize()
2829

29-
# List available resources
30-
resources = await session.list_resources()
31-
print(resources)
30+
async def main():
31+
async with stdio_client(
32+
StdioServerParameters(command="uv", args=["run", "mcp-simple-resource"])
33+
) as (read, write):
34+
async with ClientSession(read, write) as session:
35+
await session.initialize()
36+
37+
# List available resources
38+
resources = await session.list_resources()
39+
print(resources)
40+
41+
# Get a specific resource
42+
resource = await session.read_resource(AnyUrl("file:///greeting.txt"))
43+
print(resource)
44+
45+
46+
asyncio.run(main())
3247

33-
# Read a specific resource
34-
resource = await session.read_resource(resources[0].uri)
35-
print(resource)
3648
```

examples/servers/simple-resource/mcp_simple_resource/server.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
}
1111

1212

13-
@click.group()
14-
def cli():
15-
pass
16-
17-
18-
@cli.command()
13+
@click.command()
1914
@click.option("--port", default=8000, help="Port to listen on for SSE")
2015
@click.option(
2116
"--transport",
+23-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# MCP Simple Tool
21

32
A simple MCP server that exposes a website fetching tool.
43

@@ -8,10 +7,10 @@ Start the server using either stdio (default) or SSE transport:
87

98
```bash
109
# Using stdio transport (default)
11-
mcp-simple-tool
10+
uv run mcp-simple-tool
1211

1312
# Using SSE transport on custom port
14-
mcp-simple-tool --transport sse --port 8000
13+
uv run mcp-simple-tool --transport sse --port 8000
1514
```
1615

1716
The server exposes a tool named "fetch" that accepts one required argument:
@@ -20,21 +19,30 @@ The server exposes a tool named "fetch" that accepts one required argument:
2019

2120
## Example
2221

23-
Using the MCP client, you can use the tool like this:
22+
Using the MCP client, you can use the tool like this using the STDIO transport:
2423

2524
```python
26-
from mcp.client import ClientSession
25+
import asyncio
26+
from mcp.client.session import ClientSession
27+
from mcp.client.stdio import StdioServerParameters, stdio_client
2728

28-
async with ClientSession() as session:
29-
await session.initialize()
3029

31-
# List available tools
32-
tools = await session.list_tools()
33-
print(tools)
30+
async def main():
31+
async with stdio_client(
32+
StdioServerParameters(command="uv", args=["run", "mcp-simple-tool"])
33+
) as (read, write):
34+
async with ClientSession(read, write) as session:
35+
await session.initialize()
36+
37+
# List available tools
38+
tools = await session.list_tools()
39+
print(tools)
40+
41+
# Call the fetch tool
42+
result = await session.call_tool("fetch", {"url": "https://example.com"})
43+
print(result)
44+
45+
46+
asyncio.run(main())
3447

35-
# Call the fetch tool
36-
result = await session.call_tool("fetch", {
37-
"url": "https://example.com"
38-
})
39-
print(result)
4048
```

examples/servers/simple-tool/mcp_simple_tool/server.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ async def fetch_website(
1717
return [types.TextContent(type="text", text=response.text)]
1818

1919

20-
@click.group()
21-
def cli():
22-
pass
23-
24-
25-
@cli.command()
20+
@click.command()
2621
@click.option("--port", default=8000, help="Port to listen on for SSE")
2722
@click.option(
2823
"--transport",

uv.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)