Skip to content

Commit c400095

Browse files
authored
Merge pull request #82 from miguelg719/80
Updated example in README.md for increased outreach
2 parents 131902f + 840ea48 commit c400095

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Connections between clients and servers are established through transports like
7575

7676
MCP servers follow a decorator approach to register handlers for MCP primitives like resources, prompts, and tools. The goal is to provide a simple interface for exposing capabilities to LLM clients.
7777

78+
**example_server.py**
79+
7880
```python
7981
# /// script
8082
# dependencies = [
@@ -150,39 +152,52 @@ if __name__ == "__main__":
150152

151153
### Creating a Client
152154

155+
**example_client.py**
156+
153157
```python
154158
from mcp import ClientSession, StdioServerParameters
155159
from mcp.client.stdio import stdio_client
156160

157161
# Create server parameters for stdio connection
158162
server_params = StdioServerParameters(
159-
command="path/to/server",
160-
args=[], # Optional command line arguments
163+
command="python", # Executable
164+
args=["example_server.py"], # Optional command line arguments
161165
env=None # Optional environment variables
162166
)
163167

164-
async with stdio_client(server_params) as (read, write):
165-
async with ClientSession(read, write) as session:
166-
# Initialize the connection
167-
await session.initialize()
168+
async def run():
169+
async with stdio_client(server_params) as (read, write):
170+
async with ClientSession(read, write) as session:
171+
# Initialize the connection
172+
await session.initialize()
173+
174+
# The example server only supports prompt primitives:
175+
176+
# List available prompts
177+
prompts = await session.list_prompts()
168178

169-
# List available resources
170-
resources = await session.list_resources()
179+
# Get a prompt
180+
prompt = await session.get_prompt("example-prompt", arguments={"arg1": "value"})
171181

172-
# List available prompts
173-
prompts = await session.list_prompts()
182+
"""
183+
Other example calls include:
174184
175-
# List available tools
176-
tools = await session.list_tools()
185+
# List available resources
186+
resources = await session.list_resources()
177187
178-
# Read a resource
179-
resource = await session.read_resource("file://some/path")
188+
# List available tools
189+
tools = await session.list_tools()
180190
181-
# Call a tool
182-
result = await session.call_tool("tool-name", arguments={"arg1": "value"})
191+
# Read a resource
192+
resource = await session.read_resource("file://some/path")
183193
184-
# Get a prompt
185-
prompt = await session.get_prompt("prompt-name", arguments={"arg1": "value"})
194+
# Call a tool
195+
result = await session.call_tool("tool-name", arguments={"arg1": "value"})
196+
"""
197+
198+
if __name__ == "__main__":
199+
import asyncio
200+
asyncio.run(run())
186201
```
187202

188203
## Primitives

0 commit comments

Comments
 (0)