Fix READMEs of examples
This commit is contained in:
parent
15ed7cb2dc
commit
44ec763f92
8 changed files with 83 additions and 64 deletions
|
|
@ -8,10 +8,10 @@ Start the server using either stdio (default) or SSE transport:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Using stdio transport (default)
|
# Using stdio transport (default)
|
||||||
mcp-simple-prompt
|
uv mcp-simple-prompt
|
||||||
|
|
||||||
# Using SSE transport on custom port
|
# Using SSE transport on custom port
|
||||||
mcp-simple-prompt --transport sse --port 8000
|
uv run mcp-simple-prompt --transport sse --port 8000
|
||||||
```
|
```
|
||||||
|
|
||||||
The server exposes a prompt named "simple" that accepts two optional arguments:
|
The server exposes a prompt named "simple" that accepts two optional arguments:
|
||||||
|
|
@ -21,12 +21,19 @@ The server exposes a prompt named "simple" that accepts two optional arguments:
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Using the MCP client, you can retrieve the prompt like this:
|
Using the MCP client, you can retrieve the prompt like this using the STDIO transport:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from mcp.client import ClientSession
|
import asyncio
|
||||||
|
from mcp.client.session import ClientSession
|
||||||
|
from mcp.client.stdio import StdioServerParameters, stdio_client
|
||||||
|
|
||||||
async with ClientSession() as session:
|
|
||||||
|
async def main():
|
||||||
|
async with stdio_client(
|
||||||
|
StdioServerParameters(command="uv", args=["run", "mcp-simple-prompt"])
|
||||||
|
) as (read, write):
|
||||||
|
async with ClientSession(read, write) as session:
|
||||||
await session.initialize()
|
await session.initialize()
|
||||||
|
|
||||||
# List available prompts
|
# List available prompts
|
||||||
|
|
@ -34,9 +41,15 @@ async with ClientSession() as session:
|
||||||
print(prompts)
|
print(prompts)
|
||||||
|
|
||||||
# Get the prompt with arguments
|
# Get the prompt with arguments
|
||||||
prompt = await session.get_prompt("simple", {
|
prompt = await session.get_prompt(
|
||||||
|
"simple",
|
||||||
|
{
|
||||||
"context": "User is a software developer",
|
"context": "User is a software developer",
|
||||||
"topic": "Python async programming"
|
"topic": "Python async programming",
|
||||||
})
|
},
|
||||||
|
)
|
||||||
print(prompt)
|
print(prompt)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from server import main
|
from .server import main
|
||||||
|
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,7 @@ def create_messages(
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.command()
|
||||||
def cli():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--transport",
|
"--transport",
|
||||||
|
|
|
||||||
|
|
@ -8,29 +8,41 @@ Start the server using either stdio (default) or SSE transport:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Using stdio transport (default)
|
# Using stdio transport (default)
|
||||||
mcp-simple-resource
|
uv run mcp-simple-resource
|
||||||
|
|
||||||
# Using SSE transport on custom port
|
# 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.
|
The server exposes some basic text file resources that can be read by clients.
|
||||||
|
|
||||||
## Example
|
## 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
|
```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:
|
|
||||||
|
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()
|
await session.initialize()
|
||||||
|
|
||||||
# List available resources
|
# List available resources
|
||||||
resources = await session.list_resources()
|
resources = await session.list_resources()
|
||||||
print(resources)
|
print(resources)
|
||||||
|
|
||||||
# Read a specific resource
|
# Get a specific resource
|
||||||
resource = await session.read_resource(resources[0].uri)
|
resource = await session.read_resource(AnyUrl("file:///greeting.txt"))
|
||||||
print(resource)
|
print(resource)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,7 @@ SAMPLE_RESOURCES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.command()
|
||||||
def cli():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--transport",
|
"--transport",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# MCP Simple Tool
|
|
||||||
|
|
||||||
A simple MCP server that exposes a website fetching tool.
|
A simple MCP server that exposes a website fetching tool.
|
||||||
|
|
||||||
|
|
@ -8,10 +7,10 @@ Start the server using either stdio (default) or SSE transport:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Using stdio transport (default)
|
# Using stdio transport (default)
|
||||||
mcp-simple-tool
|
uv run mcp-simple-tool
|
||||||
|
|
||||||
# Using SSE transport on custom port
|
# Using SSE transport on custom port
|
||||||
mcp-simple-tool --transport sse --port 8000
|
uv run mcp-simple-tool --transport sse --port 8000
|
||||||
```
|
```
|
||||||
|
|
||||||
The server exposes a tool named "fetch" that accepts one required argument:
|
The server exposes a tool named "fetch" that accepts one required argument:
|
||||||
|
|
@ -20,12 +19,19 @@ The server exposes a tool named "fetch" that accepts one required argument:
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Using the MCP client, you can use the tool like this:
|
Using the MCP client, you can use the tool like this using the STDIO transport:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from mcp.client import ClientSession
|
import asyncio
|
||||||
|
from mcp.client.session import ClientSession
|
||||||
|
from mcp.client.stdio import StdioServerParameters, stdio_client
|
||||||
|
|
||||||
async with ClientSession() as session:
|
|
||||||
|
async def main():
|
||||||
|
async with stdio_client(
|
||||||
|
StdioServerParameters(command="uv", args=["run", "mcp-simple-tool"])
|
||||||
|
) as (read, write):
|
||||||
|
async with ClientSession(read, write) as session:
|
||||||
await session.initialize()
|
await session.initialize()
|
||||||
|
|
||||||
# List available tools
|
# List available tools
|
||||||
|
|
@ -33,8 +39,10 @@ async with ClientSession() as session:
|
||||||
print(tools)
|
print(tools)
|
||||||
|
|
||||||
# Call the fetch tool
|
# Call the fetch tool
|
||||||
result = await session.call_tool("fetch", {
|
result = await session.call_tool("fetch", {"url": "https://example.com"})
|
||||||
"url": "https://example.com"
|
|
||||||
})
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,7 @@ async def fetch_website(
|
||||||
return [types.TextContent(type="text", text=response.text)]
|
return [types.TextContent(type="text", text=response.text)]
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.command()
|
||||||
def cli():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
@click.option("--port", default=8000, help="Port to listen on for SSE")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--transport",
|
"--transport",
|
||||||
|
|
|
||||||
2
uv.lock
generated
2
uv.lock
generated
|
|
@ -171,7 +171,7 @@ wheels = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mcp"
|
name = "mcp"
|
||||||
version = "1.0.0.dev0"
|
version = "1.1.1.dev0"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "anyio" },
|
{ name = "anyio" },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue