python-sdk
Официальныйот modelcontextprotocol
The official Python SDK for Model Context Protocol servers and clients
Установка
pip install "mcp[cli]"Описание
# MCP Python SDK <div align="center"> <strong>Python implementation of the Model Context Protocol (MCP)</strong> [![PyPI][pypi-badge]][pypi-url] [![MIT licensed][mit-badge]][mit-url] [![Python Version][python-badge]][python-url] [![Documentation][docs-badge]][docs-url] [![Protocol][protocol-badge]][protocol-url] [![Specification][spec-badge]][spec-url] </div> <!-- omit in toc --> ## Table of Contents - [MCP Python SDK](#mcp-python-sdk) - [Overview](#overview) - [Installation](#installation) - [Adding MCP to your python project](#adding-mcp-to-your-python-project) - [Running the standalone MCP development tools](#running-the-standalone-mcp-development-tools) - [Quickstart](#quickstart) - [What is MCP?](#what-is-mcp) - [Core Concepts](#core-concepts) - [Server](#server) - [Resources](#resources) - [Tools](#tools) - [Structured Output](#structured-output) - [Prompts](#prompts) - [Images](#images) - [Context](#context) - [Getting Context in Functions](#getting-context-in-functions) - [Context Properties and Methods](#context-properties-and-methods) - [Completions](#completions) - [Elicitation](#elicitation) - [Sampling](#sampling) - [Logging and Notifications](#logging-and-notifications) - [Authentication](#authentication) - [FastMCP Properties](#fastmcp-properties) - [Session Properties and Methods](#session-properties-and-methods) - [Request Context Properties](#request-context-properties) - [Running Your Server](#running-your-server) - [Development Mode](#development-mode) - [Claude Desktop Integration](#claude-desktop-integration) - [Direct Execution](#direct-execution) - [Streamable HTTP Transport](#streamable-http-transport) - [CORS Configuration for Browser-Based Clients](#cors-configuration-for-browser-based-clients) - [Mounting to an Existing ASGI Server](#mounting-to-an-existing-asgi-server) - [StreamableHTTP servers](#streamablehttp-servers) - [Basic mounting](#basic-mounting) - [Host-based routing](#host-based-routing) - [Multiple servers with path configuration](#multiple-servers-with-path-configuration) - [Path configuration at initialization](#path-configuration-at-initialization) - [SSE servers](#sse-servers) - [Advanced Usage](#advanced-usage) - [Low-Level Server](#low-level-server) - [Structured Output Support](#structured-output-support) - [Pagination (Advanced)](#pagination-advanced) - [Writing MCP Clients](#writing-mcp-clients) - [Client Display Utilities](#client-display-utilities) - [OAuth Authentication for Clients](#oauth-authentication-for-clients) - [Parsing Tool Results](#parsing-tool-results) - [MCP Primitives](#mcp-primitives) - [Server Capabilities](#server-capabilities) - [Documentation](#documentation) - [Contributing](#contributing) - [License](#license) [pypi-badge]: https://img.shields.io/pypi/v/mcp.svg [pypi-url]: https://pypi.org/project/mcp/ [mit-badge]: https://img.shields.io/pypi/l/mcp.svg [mit-url]: https://github.com/modelcontextprotocol/python-sdk/blob/main/LICENSE [python-badge]: https://img.shields.io/pypi/pyversions/mcp.svg [python-url]: https://www.python.org/downloads/ [docs-badge]: https://img.shields.io/badge/docs-python--sdk-blue.svg [docs-url]: https://modelcontextprotocol.github.io/python-sdk/ [protocol-badge]: https://img.shields.io/badge/protocol-modelcontextprotocol.io-blue.svg [protocol-url]: https://modelcontextprotocol.io [spec-badge]: https://img.shields.io/badge/spec-spec.modelcontextprotocol.io-blue.svg [spec-url]: https://modelcontextprotocol.io/specification/latest ## 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, SSE, and Streamable HTTP - Handle all MCP protocol messages and lifecycle events ## Installation ### Adding MCP to your python project We recommend using [uv](https://docs.astral.sh/uv/) to manage your Python projects. If you haven't created a uv-managed project yet, create one: ```bash uv init mcp-server-demo cd mcp-server-demo ``` Then add MCP to your project dependencies: ```bash uv add "mcp[cli]" ``` Alternatively, for projects using pip for dependencies: ```bash pip install "mcp[cli]" ``` ### Running the standalone MCP development tools To run the mcp command with uv: ```bash uv run mcp ``` ## Quickstart Let's create a simple MCP server that exposes a calculator tool and some data: <!-- snippet-source examples/snippets/servers/fastmcp_quickstart.py --> ```python """ FastMCP quickstart example. Run from the repository
Отзывы (0)
Пока нет отзывов. Будьте первым!
Статистика
Информация
Технологии
Похожие серверы
GitHub MCP
Полная интеграция с GitHub API: репозитории, issues, pull requests, actions и многое другое.
Filesystem MCP
Безопасный доступ к файловой системе для чтения, записи и управления файлами с настраиваемыми разрешениями.
Context7 MCP
Доступ к актуальной документации библиотек и фреймворков.
Serena MCP
Мощный MCP сервер для семантической навигации по коду и рефакторинга.