You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-18Lines changed: 33 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,8 @@ Connections between clients and servers are established through transports like
75
75
76
76
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.
77
77
78
+
**example_server.py**
79
+
78
80
```python
79
81
# /// script
80
82
# dependencies = [
@@ -150,39 +152,52 @@ if __name__ == "__main__":
150
152
151
153
### Creating a Client
152
154
155
+
**example_client.py**
156
+
153
157
```python
154
158
from mcp import ClientSession, StdioServerParameters
155
159
from mcp.client.stdio import stdio_client
156
160
157
161
# Create server parameters for stdio connection
158
162
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
161
165
env=None# Optional environment variables
162
166
)
163
167
164
-
asyncwith stdio_client(server_params) as (read, write):
165
-
asyncwith ClientSession(read, write) as session:
166
-
# Initialize the connection
167
-
await session.initialize()
168
+
asyncdefrun():
169
+
asyncwith stdio_client(server_params) as (read, write):
170
+
asyncwith ClientSession(read, write) as session:
171
+
# Initialize the connection
172
+
await session.initialize()
173
+
174
+
# The example server only supports prompt primitives:
0 commit comments