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.1.tar.gz (78.2 kB view details)

Uploaded Source

Built Distribution

mcp-0.9.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp-0.9.1.tar.gz
  • Upload date:
  • Size: 78.2 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.1.tar.gz
Algorithm Hash digest
SHA256 e8509a37c2ab546095788ed170e0fb4d7ce0cf5a3ee56b6449c78af27321a425
MD5 9695144b3835673ae9929b8cf7429c17
BLAKE2b-256 e71c932818470ffd49c33509110c835101a8dc4c9cdd06028b9f647fb3dde237

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

  • Download URL: mcp-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 31.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f640fcfb0be486aa510594df309920ae1d375cdca1f8aff21db3a96d837f303
MD5 5abddc60d6f65a247ef8fa9710148a03
BLAKE2b-256 b3a02ee813d456b57a726d583868417d1ad900fbe12ee3c8cd866e3e804ca486

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp-0.9.1-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