MCPico
MCP, made simple.
A small, fully typed Python SDK for the Model Context Protocol: client and server, over stdio and Streamable HTTP, with OAuth 2.1. It speaks protocol revision 2026-07-28, and 2025-11-25 for older peers.
from mcpico import Server
server = Server("demo")
@server.tool
def add(a: int, b: int = 0) -> int:
"""Add two numbers."""
return a + b
server.run() # stdio; server.run("http", port=8000) for Streamable HTTP
Input and output schemas come from type hints, docstrings become descriptions, and arguments are validated before your function runs.
Install
pip install mcpico # core and stdio
pip install "mcpico[http]" # Streamable HTTP (client and server)
pip install "mcpico[auth]" # OAuth 2.1
With uv:
uv add mcpico
uv add "mcpico[http]"
uv add "mcpico[auth]"
Python 3.12 or newer.
Servers
Tools
from typing import Annotated
import msgspec
from mcpico import Context, Server
server = Server("weather", "1.0", instructions="Forecasts for European cities.")
class Forecast(msgspec.Struct):
city: str
celsius: float
@server.tool
async def forecast(
city: Annotated[str, msgspec.Meta(description="City name")], ctx: Context
) -> Forecast:
"""Tomorrow's forecast."""
await ctx.report_progress(1, 2, "fetching")
return Forecast(city, 21.5)
- Parameters annotated with
Contextare injected rather than exposed to clients. - Functions returning
str, content blocks orNoneproduce plain content. Anything else is structured content, with an output schema derived from the return type. - Exceptions become tool errors (
isError: true) that the model can see. - Pass
input_schema=oroutput_schema=to use hand-written JSON Schemas instead.
Resources and prompts
@server.resource("file:///readme.txt", mime_type="text/plain")
def readme() -> str:
return "Hello"
@server.resource("users://{user_id}/avatar", mime_type="image/png")
def avatar(user_id: int) -> bytes: # bytes are sent as a blob
...
@server.prompt
def review(code: str, language: str = "python") -> str:
"""Review some code."""
return f"Please review this {language} code:\n\n{code}"
URIs containing {variable} (one path segment) or {+variable} (any text) register templates.
Asking the user
A tool, resource or prompt can ask the client for input. The server holds no session for this:
it returns the question, and the client retries the request with the answer. The handler then
runs again from the start, and elicit calls that were already answered return their answers.
class Confirm(msgspec.Struct):
confirm: bool
@server.tool
def delete_project(name: str, ctx: Context) -> str:
answer = ctx.elicit(f"Really delete {name}?", Confirm)
if answer is None or not answer.confirm: # None: declined or cancelled
return "Kept."
...
return "Deleted."
The form is derived from the struct or dataclass, whose fields must be strings, numbers,
booleans or enums (X | None makes a field optional). Pass a JSON Schema instead to get the raw
ElicitResult. Code before an elicit call can run more than once, so keep side effects after the last one.
ctx.elicit_url(...) sends the user to a URL instead. The state carried between rounds is signed,
bound to the request and the caller, and expires. Pass state_secret= to Server when several
processes serve the same clients.
Protocol versions
A server answers 2026-07-28 and 2025-11-25 clients on the same endpoint, from the same tools,
resources and prompts. Requests carrying 2026-07-28 metadata are served statelessly; an
initialize request opens a 2025-11-25 session (one per stdio process, or per Mcp-Session-Id
over HTTP), in which elicit becomes an elicitation/create request to the client.
ctx.protocol_version tells a handler which revision is in use. To serve only some revisions:
from mcpico.types import LATEST_PROTOCOL_VERSION
server = Server("demo", protocol_versions=[LATEST_PROTOCOL_VERSION])
Change notifications
server.add_tool(some_function) # clients listening for tool changes are told
server.notify_resource_updated("file:///readme.txt")
Running
server.run() # stdio
server.run("http", host="127.0.0.1", port=8000) # Streamable HTTP, on Granian
Inside an existing event loop, use await server.serve(...) and cancel the task to stop. The HTTP
server shuts down gracefully: it ends open subscription streams and finishes in-flight requests.
mcpico.http.serve_async also takes ready= (an asyncio.Event set once the server accepts
connections) and ssl_cert/ssl_key for HTTPS.
For other deployments, create_app returns a standard ASGI application:
from mcpico.http import create_app
app = create_app(server, allowed_origins=["https://app.example.com"])
granian --interface asgi --workers 4 myserver:app
Requests are independent, so workers share nothing but a common state_secret. Change
notifications reach only subscribers connected to the same process. 2025-11-25 sessions live in
the process that opened them: route them by Mcp-Session-Id, or serve only 2026-07-28.
Browser requests from origins other than localhost are rejected unless listed in
allowed_origins.
Clients
import asyncio
from mcpico import Client, StdioTransport
async def main() -> None:
async with Client(StdioTransport("python", ["server.py"])) as client:
tools = await client.list_tools()
result = await client.call_tool("add", {"a": 1, "b": 2})
print(result.parse(int))
asyncio.run(main())
Transports
StdioTransport starts the server as a subprocess; the command and arguments may be paths.
Over Streamable HTTP:
from mcpico.http import HttpTransport
client = Client(HttpTransport("https://mcp.example.com/mcp"))
Results
result = await client.call_tool("weather", {"city": "Oslo"})
weather = result.parse(Weather) # structured content; raises ToolError if the tool failed
print(result.text) # the text blocks, joined
note = await client.read_resource("notes://todo")
print(note.text) # or note.data for binary contents
Structured content is checked against the tool's output schema, and list_* methods follow
pagination.
Questions, progress and timeouts
from mcpico.types import ElicitRequest, ElicitResult
async def ask(request: ElicitRequest) -> ElicitResult:
print(request.message)
return ElicitResult(action="accept", content={"confirm": True})
async with Client(transport, elicitation=ask) as client:
await client.call_tool("delete_project", {"name": "old"}, timeout=30, progress=print)
A timeout or a cancelled task also cancels the request on the server.
Change notifications
async with client.listen(tools=True) as subscription:
async for notification in subscription:
print(notification.method)
Protocol versions
The client speaks 2026-07-28 first. When a server does not understand it, the client falls back
to a 2025-11-25 initialize session, with the same API.
Client(..., protocol_versions=[...])restricts the versions it may use.- A custom transport implements
SessionTransportto support the fallback.
Authorization
A server checks bearer tokens and publishes its Protected Resource Metadata:
from mcpico.auth import ProtectedResource
auth = ProtectedResource.jwt(
"https://mcp.example.com/mcp",
issuer="https://auth.example.com",
jwks_uri="https://auth.example.com/.well-known/jwks.json",
required_scopes=("mcp",),
)
server.run("http", host="0.0.0.0", port=8000, auth=auth)
Handlers read the validated token from ctx.access_token, and can raise
InsufficientScopeError(["admin"]) to ask the client to step up. Implement TokenVerifier to
validate tokens some other way, such as introspection, and pass it to ProtectedResource(...).
A client uses OAuth, an httpx2.Auth. It discovers the authorization server, runs the
authorization code flow with PKCE, and refreshes tokens:
from mcpico.auth.client import ClientCredentials, LoopbackBrowser, OAuth
browser = LoopbackBrowser(8765) # opens the system browser, listens for the redirect
oauth = OAuth(
authorize=browser,
redirect_uri=browser.redirect_uri,
credentials={"https://auth.example.com": ClientCredentials("my-client-id")},
)
client = Client(HttpTransport("https://mcp.example.com/mcp", auth=oauth))
authorize can be any async function that sends the user to a URL and returns the URL they were
redirected to. Without it, the client credentials grant is used. Instead of pre-registered credentials,
client_metadata_url= identifies the client with a Client ID Metadata Document.
Scope
MCPico implements the current protocol revision, and revision 2025-11-25 for clients and servers
that do not speak it yet. Features the specification deprecates or removed are not provided in
either: roots, sampling, logging and dynamic client registration. With 2025-11-25 peers,
Client.listen is unavailable and HTTP sessions are not resumable.
Development
uv sync --all-extras
uv run ruff format --check .
uv run ruff check .
uv run pyright
uv run mypy
uv run pyrefly check
uv run ty check # advisory
uv run pytest
The documentation site, with an API reference generated from the docstrings, is in
docs/.
License
MIT
Metadata
Release files for mcpico 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcpico-0.1.1.tar.gz | 74.3 kB | With provenance | Details for mcpico-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcpico-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for mcpico-0.1.1-py3-none-any.whl |
Total release size: 142.7 kB
Release files / mcpico-0.1.1.tar.gz
| Download URL | mcpico-0.1.1.tar.gz |
|---|---|
| Size | 74.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f61c7e091ce6025fa99ba5352afa6426b9c7fa901ee82c243a24dada6d15cbbd
|
|
BLAKE2b-256 checksum How to use checksums |
6ddeb0768fb1002da8898b4987da54a6895f3e762a78755fdf57c2aa4efdcc30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / mcpico-0.1.1-py3-none-any.whl
| Download URL | mcpico-0.1.1-py3-none-any.whl |
|---|---|
| Size | 68.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04c28c7fff3e5d306bc7693160ca77b8dd196a1601d6074cb48caf2d66782489
|
|
BLAKE2b-256 checksum How to use checksums |
b7372b3248f8bfe00b568c29dc8a1864a9db2f54ee52b5310fa67700f0ac6486
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for mcpico 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mcpico-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.