python-sdk/examples/servers/simple-resource
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Peter Alexander 356dfa692b
Update simple-resource example to use non-deprecated read_resource return type (#1331)
Co-authored-by: Claude <noreply@anthropic.com>
2025-09-01 17:58:01 +01:00
..
mcp_simple_resource Update simple-resource example to use non-deprecated read_resource return type (#1331) 2025-09-01 17:58:01 +01:00
.python-version pin to lowest supported python version 2024-11-13 10:44:54 +00:00
pyproject.toml Update dependencies and fix type issues (#1268) 2025-08-14 10:40:47 +01:00
README.md Fix READMEs of examples 2024-12-03 22:35:52 +00:00

MCP Simple Resource

A simple MCP server that exposes sample text files as resources.

Usage

Start the server using either stdio (default) or SSE transport:

# Using stdio transport (default)
uv run mcp-simple-resource

# Using SSE transport on custom port
uv run mcp-simple-resource --transport sse --port 8000

The server exposes some basic text file resources that can be read by clients.

Example

Using the MCP client, you can retrieve resources like this using the STDIO transport:

import asyncio
from mcp.types import AnyUrl
from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client


async def main():
    async with stdio_client(
        StdioServerParameters(command="uv", args=["run", "mcp-simple-resource"])
    ) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # List available resources
            resources = await session.list_resources()
            print(resources)

            # Get a specific resource
            resource = await session.read_resource(AnyUrl("file:///greeting.txt"))
            print(resource)


asyncio.run(main())