Skip to main content

Model Context Protocol implementation for Python

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp-0.9.0.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

mcp-0.9.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp-0.9.0.tar.gz.

File metadata

  • Download URL: mcp-0.9.0.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mcp-0.9.0.tar.gz
Algorithm Hash digest
SHA256 1d7e3f8d78bf5b37c98a233fce8cebbb86c57d8964d2c3b03cf08cdebd103d9a
MD5 6533f8e8ff591a5d5cbbf14f0b8a84e3
BLAKE2b-256 cdbbfd56a5c331a6c95a4f2ec907683db3382d30b99b808ef6f46fa4f08a4b74

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp-0.9.0.tar.gz:

Publisher: publish-pypi.yml on modelcontextprotocol/python-sdk

Attestations:

File details

Details for the file mcp-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: mcp-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mcp-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e09aca08eadaf0552541aaa71271b44f99a6a5d16e5b1b03c421366f72b51753
MD5 ebd475a849e4878c403e0e9998bc967d
BLAKE2b-256 6f07077116e6a23dd0546391f5caa81b4f52938d8a81f2449c55c0b50c0215bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp-0.9.0-py3-none-any.whl:

Publisher: publish-pypi.yml on modelcontextprotocol/python-sdk

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page