mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Fix READMEs of examples
This commit is contained in:
@@ -8,29 +8,41 @@ Start the server using either stdio (default) or SSE transport:
|
||||
|
||||
```bash
|
||||
# Using stdio transport (default)
|
||||
mcp-simple-resource
|
||||
uv run mcp-simple-resource
|
||||
|
||||
# Using SSE transport on custom port
|
||||
mcp-simple-resource --transport sse --port 8000
|
||||
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 read the resources like this:
|
||||
Using the MCP client, you can retrieve resources like this using the STDIO transport:
|
||||
|
||||
```python
|
||||
from mcp.client import ClientSession
|
||||
import asyncio
|
||||
from mcp.types import AnyUrl
|
||||
from mcp.client.session import ClientSession
|
||||
from mcp.client.stdio import StdioServerParameters, stdio_client
|
||||
|
||||
async with ClientSession() as session:
|
||||
await session.initialize()
|
||||
|
||||
# List available resources
|
||||
resources = await session.list_resources()
|
||||
print(resources)
|
||||
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())
|
||||
|
||||
# Read a specific resource
|
||||
resource = await session.read_resource(resources[0].uri)
|
||||
print(resource)
|
||||
```
|
||||
|
||||
@@ -10,12 +10,7 @@ SAMPLE_RESOURCES = {
|
||||
}
|
||||
|
||||
|
||||
@click.group()
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.command()
|
||||
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
||||
@click.option(
|
||||
"--transport",
|
||||
|
||||
Reference in New Issue
Block a user