Get the FREE Ultimate OpenClaw Setup Guide →

python-sdk

The official Python SDK for Model Context Protocol servers and clients

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-python-sdk uvx mcp

How to use

The MCP Python SDK allows developers to create and manage servers that expose data and functionality for LLM applications. With this SDK, you can build MCP clients that connect to any MCP server, create servers that expose resources, prompts, and tools, and utilize standard transports like stdio, SSE, and Streamable HTTP. The SDK also provides functionalities for handling protocol messages and lifecycle events, making it a comprehensive solution for integrating LLMs with context management.

To use the tools provided by the MCP Python SDK, you can create a server that defines various resources and tools. For example, you can create a calculator tool that performs arithmetic operations or define resources that return personalized greetings. The SDK supports running servers in different modes, including development mode and integration with existing ASGI servers, allowing for flexibility in deployment and usage.

How to install

  1. Ensure you have Python installed on your machine. You can download it from https://www.python.org/downloads/.
  2. Install the uv package by running:
    pip install uv
    
  3. Create a new uv managed project:
    uv init mcp-server-demo
    cd mcp-server-demo
    
  4. Add the MCP SDK to your project dependencies:
    uv add "mcp[cli]"
    
  5. To run the MCP command, use:
    uv run mcp
    

Additional notes

When running the server, ensure that the transport mode is correctly set for your use case, such as streamable HTTP. If you encounter issues, check the server logs for any error messages that can guide you in troubleshooting. Additionally, consider configuring environment variables for sensitive data or settings that may vary between development and production environments.

Related MCP Servers

Sponsor this space

Reach thousands of developers