Mirror of https://github.com/modelcontextprotocol/python-sdk — The official Python SDK for Model Context Protocol servers and clients
  • Python 99.8%
  • Shell 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
David Soria Parra f5d82bd229
Remove helper types
The helper types in mcp.server.types got really confusioning during
implementation as they overlapped with mcp.types. I now believe it
is better if we stay more low level to the spec types.

To do this, we now only use mcp.types everywhere. We renamed mcp.server.types
to mcp.server.models and removed it to the absolute minimum.
2024-11-11 20:05:51 +00:00
.devcontainer Initial import 2024-09-24 22:04:19 +01:00
.github/workflows github: add workflows to check formatting and typecheck 2024-10-11 16:17:04 +01:00
src/mcp Remove helper types 2024-11-11 20:05:51 +00:00
tests Remove helper types 2024-11-11 20:05:51 +00:00
.gitignore Initial import 2024-09-24 22:04:19 +01:00
.python-version python-version: Pin our python version 2024-10-11 12:09:17 +01:00
LICENSE Add LICENSE file 2024-11-07 14:59:39 +00:00
pyproject.toml update pyproject toml 2024-11-11 15:40:11 +00:00
README.md update package name in readme 2024-11-11 16:22:26 +00:00
RELEASE.md A short overview of how to do a release 2024-10-21 15:54:17 +01:00
uv.lock Remove helper types 2024-11-11 20:05:51 +00:00

MCP Python SDK

Python implementation of the Model Context Protocol (MCP), providing both client and server capabilities for integrating with LLM surfaces.

Overview

The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Python SDK implements the full MCP specification, making it easy to:

  • Build MCP clients that can connect to any MCP server
  • Create MCP servers that expose resources, prompts and tools
  • Use standard transports like stdio and SSE
  • Handle all MCP protocol messages and lifecycle events

Installation

uv add mcp

Quick Start

Creating a Client

from mcp import ClientSession
from mcp.client.stdio import stdio_client

async with stdio_client(command="path/to/server") as (read, write):
    async with ClientSession(read, write) as session:
        # Initialize the connection
        await session.initialize()

        # List available resources
        resources = await session.list_resources()

Creating a Server

from mcp.server import Server
from mcp.server.stdio import stdio_server

# Create a server instance
server = Server("example-server")

# Add capabilities
@server.list_resources()
async def list_resources():
    return [
        {
            "uri": "file:///example.txt",
            "name": "Example Resource"
        }
    ]

# Run the server
async with stdio_server() as (read, write):
    await server.run(read, write, server.create_initialization_options())

Documentation

Contributing

Issues and pull requests are welcome on GitHub at https://github.com/modelcontextprotocol/python-sdk.

License

This project is licensed under the MIT License - see the LICENSE file for details.