Exercise: Building a client
In this exercise, you will build a client that connects to the server and consumes its features. You will use the SDK to build the client and call the server. The client will be a simple command-line application that allows you to select a feature and provide its parameters. The client will then call the server and display the results.
Set up the client to connect to the server
Let’s first create the client code needed to establish a connection to the server:
from mcp import ClientSession, StdioServerParameters, types
from mcp.client.stdio import stdio_client
# Create server parameters for stdio connection
server_params = StdioServerParameters(
    command="mcp",  # Executable
    args=["run", "server.py"],  # Optional command line arguments
    env=None,  # Optional environment variables
)
async def run():
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(
   ... 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                