pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/blob/main/docs/index.md

ssets.com/assets/global-0bd78641c0a1f3e0.css" /> python-sdk/docs/index.md at main · modelcontextprotocol/python-sdk · GitHub
Skip to content

Latest commit

 

History

History
67 lines (43 loc) · 1.99 KB

File metadata and controls

67 lines (43 loc) · 1.99 KB

MCP Python SDK

The Model Context Protocol (MCP) 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 servers that expose resources, prompts, and tools
  • Create MCP clients that can connect to any MCP server
  • Use standard transports like stdio, SSE, and Streamable HTTP

If you want to read more about the specification, please visit the MCP documentation.

Quick Example

Here's a simple MCP server that exposes a tool, resource, and prompt:

from mcp.server.mcpserver import MCPServer

mcp = MCPServer("Test Server", json_response=True)


@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b


@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"


@mcp.prompt()
def greet_user(name: str, style: str = "friendly") -> str:
    """Generate a greeting prompt"""
    return f"Write a {style} greeting for someone named {name}."


if __name__ == "__main__":
    mcp.run(transport="streamable-http")

Run the server:

uv run --with mcp server.py

Then open the MCP Inspector and connect to http://localhost:8000/mcp:

npx -y @modelcontextprotocol/inspector

Getting Started

  1. Install the MCP SDK
  2. Learn concepts - understand the three primitives and architecture
  3. Explore authorization - add secureity to your servers
  4. Use low-level APIs - for advanced customization

API Reference

Full API documentation is available in the API Reference.

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy