Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
d138f33
1
Parent(s): 51adb4d
Rename dirs
Browse files- src/fastmcp/__init__.py +2 -0
- src/fastmcp/{client → clients}/__init__.py +2 -2
- src/fastmcp/{client → clients}/base.py +0 -0
- src/fastmcp/{client/memory.py → clients/fastmcp_client.py} +3 -3
- src/fastmcp/{client → clients}/sse.py +1 -1
- src/fastmcp/{client → clients}/stdio.py +1 -1
- src/fastmcp/{client → clients}/websocket.py +1 -1
- tests/{client → clients}/__init__.py +0 -0
- tests/{client/test_memory_client.py → clients/test_fastmcp_client.py} +9 -9
src/fastmcp/__init__.py
CHANGED
|
@@ -2,9 +2,11 @@
|
|
| 2 |
|
| 3 |
from importlib.metadata import version
|
| 4 |
from fastmcp.server import FastMCP, Context
|
|
|
|
| 5 |
|
| 6 |
__version__ = version("fastmcp")
|
| 7 |
__all__ = [
|
| 8 |
"FastMCP",
|
| 9 |
"Context",
|
|
|
|
| 10 |
]
|
|
|
|
| 2 |
|
| 3 |
from importlib.metadata import version
|
| 4 |
from fastmcp.server import FastMCP, Context
|
| 5 |
+
from . import clients
|
| 6 |
|
| 7 |
__version__ = version("fastmcp")
|
| 8 |
__all__ = [
|
| 9 |
"FastMCP",
|
| 10 |
"Context",
|
| 11 |
+
"clients",
|
| 12 |
]
|
src/fastmcp/{client → clients}/__init__.py
RENAMED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
from .websocket import WebSocketClient
|
| 2 |
from .sse import SSEClient
|
| 3 |
from .stdio import StdioClient, UvxClient
|
| 4 |
-
from .
|
| 5 |
|
| 6 |
__all__ = [
|
| 7 |
"StdioClient",
|
| 8 |
"SSEClient",
|
| 9 |
"WebSocketClient",
|
| 10 |
"UvxClient",
|
| 11 |
-
"
|
| 12 |
]
|
|
|
|
| 1 |
from .websocket import WebSocketClient
|
| 2 |
from .sse import SSEClient
|
| 3 |
from .stdio import StdioClient, UvxClient
|
| 4 |
+
from .fastmcp_client import FastMCPClient
|
| 5 |
|
| 6 |
__all__ = [
|
| 7 |
"StdioClient",
|
| 8 |
"SSEClient",
|
| 9 |
"WebSocketClient",
|
| 10 |
"UvxClient",
|
| 11 |
+
"FastMCPClient",
|
| 12 |
]
|
src/fastmcp/{client → clients}/base.py
RENAMED
|
File without changes
|
src/fastmcp/{client/memory.py → clients/fastmcp_client.py}
RENAMED
|
@@ -4,14 +4,14 @@ from typing import TypeVar
|
|
| 4 |
from mcp.shared.memory import create_connected_server_and_client_session
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
-
from fastmcp.
|
| 8 |
from fastmcp.server.server import FastMCP
|
| 9 |
|
| 10 |
T = TypeVar("T")
|
| 11 |
|
| 12 |
|
| 13 |
-
class
|
| 14 |
-
"""Client that connects to an in-memory
|
| 15 |
|
| 16 |
This client creates and manages an in-memory connection to a server,
|
| 17 |
without using any external processes or network connections.
|
|
|
|
| 4 |
from mcp.shared.memory import create_connected_server_and_client_session
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
+
from fastmcp.clients.base import BaseClient, ClientKwargs
|
| 8 |
from fastmcp.server.server import FastMCP
|
| 9 |
|
| 10 |
T = TypeVar("T")
|
| 11 |
|
| 12 |
|
| 13 |
+
class FastMCPClient(BaseClient):
|
| 14 |
+
"""Client that connects directly to an in-memory FastMCP server.
|
| 15 |
|
| 16 |
This client creates and manages an in-memory connection to a server,
|
| 17 |
without using any external processes or network connections.
|
src/fastmcp/{client → clients}/sse.py
RENAMED
|
@@ -4,7 +4,7 @@ from mcp import ClientSession
|
|
| 4 |
from mcp.client.sse import sse_client
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
-
from fastmcp.
|
| 8 |
|
| 9 |
|
| 10 |
class SSEClient(BaseClient):
|
|
|
|
| 4 |
from mcp.client.sse import sse_client
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
+
from fastmcp.clients.base import BaseClient, ClientKwargs
|
| 8 |
|
| 9 |
|
| 10 |
class SSEClient(BaseClient):
|
src/fastmcp/{client → clients}/stdio.py
RENAMED
|
@@ -6,7 +6,7 @@ from mcp import ClientSession, StdioServerParameters
|
|
| 6 |
from mcp.client.stdio import stdio_client
|
| 7 |
from typing_extensions import Unpack
|
| 8 |
|
| 9 |
-
from fastmcp.
|
| 10 |
|
| 11 |
|
| 12 |
class StdioClient(BaseClient):
|
|
|
|
| 6 |
from mcp.client.stdio import stdio_client
|
| 7 |
from typing_extensions import Unpack
|
| 8 |
|
| 9 |
+
from fastmcp.clients.base import BaseClient, ClientKwargs
|
| 10 |
|
| 11 |
|
| 12 |
class StdioClient(BaseClient):
|
src/fastmcp/{client → clients}/websocket.py
RENAMED
|
@@ -4,7 +4,7 @@ from mcp import ClientSession
|
|
| 4 |
from mcp.client.websocket import websocket_client
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
-
from fastmcp.
|
| 8 |
|
| 9 |
|
| 10 |
class WebSocketClient(BaseClient):
|
|
|
|
| 4 |
from mcp.client.websocket import websocket_client
|
| 5 |
from typing_extensions import Unpack
|
| 6 |
|
| 7 |
+
from fastmcp.clients.base import BaseClient, ClientKwargs
|
| 8 |
|
| 9 |
|
| 10 |
class WebSocketClient(BaseClient):
|
tests/{client → clients}/__init__.py
RENAMED
|
File without changes
|
tests/{client/test_memory_client.py → clients/test_fastmcp_client.py}
RENAMED
|
@@ -3,7 +3,7 @@ from typing import cast
|
|
| 3 |
import pytest
|
| 4 |
from pydantic import AnyUrl
|
| 5 |
|
| 6 |
-
from fastmcp.
|
| 7 |
from fastmcp.server.server import FastMCP
|
| 8 |
|
| 9 |
|
|
@@ -50,7 +50,7 @@ def fastmcp_server():
|
|
| 50 |
|
| 51 |
async def test_list_tools(fastmcp_server):
|
| 52 |
"""Test listing tools with InMemoryClient."""
|
| 53 |
-
client =
|
| 54 |
|
| 55 |
async with client:
|
| 56 |
result = await client.list_tools()
|
|
@@ -64,7 +64,7 @@ async def test_list_tools(fastmcp_server):
|
|
| 64 |
|
| 65 |
async def test_call_tool(fastmcp_server):
|
| 66 |
"""Test calling a tool with InMemoryClient."""
|
| 67 |
-
client =
|
| 68 |
|
| 69 |
async with client:
|
| 70 |
result = await client.call_tool("greet", {"name": "World"})
|
|
@@ -76,7 +76,7 @@ async def test_call_tool(fastmcp_server):
|
|
| 76 |
|
| 77 |
async def test_list_resources(fastmcp_server):
|
| 78 |
"""Test listing resources with InMemoryClient."""
|
| 79 |
-
client =
|
| 80 |
|
| 81 |
async with client:
|
| 82 |
result = await client.list_resources()
|
|
@@ -88,7 +88,7 @@ async def test_list_resources(fastmcp_server):
|
|
| 88 |
|
| 89 |
async def test_list_prompts(fastmcp_server):
|
| 90 |
"""Test listing prompts with InMemoryClient."""
|
| 91 |
-
client =
|
| 92 |
|
| 93 |
async with client:
|
| 94 |
result = await client.list_prompts()
|
|
@@ -100,7 +100,7 @@ async def test_list_prompts(fastmcp_server):
|
|
| 100 |
|
| 101 |
async def test_get_prompt(fastmcp_server):
|
| 102 |
"""Test getting a prompt with InMemoryClient."""
|
| 103 |
-
client =
|
| 104 |
|
| 105 |
async with client:
|
| 106 |
result = await client.get_prompt("welcome", {"name": "Developer"})
|
|
@@ -112,7 +112,7 @@ async def test_get_prompt(fastmcp_server):
|
|
| 112 |
|
| 113 |
async def test_read_resource(fastmcp_server):
|
| 114 |
"""Test reading a resource with InMemoryClient."""
|
| 115 |
-
client =
|
| 116 |
|
| 117 |
async with client:
|
| 118 |
# Use the URI from the resource we know exists in our server
|
|
@@ -130,7 +130,7 @@ async def test_read_resource(fastmcp_server):
|
|
| 130 |
|
| 131 |
async def test_client_connection(fastmcp_server):
|
| 132 |
"""Test that the client connects and disconnects properly."""
|
| 133 |
-
client =
|
| 134 |
|
| 135 |
# Before connection
|
| 136 |
assert not client.is_connected()
|
|
@@ -145,7 +145,7 @@ async def test_client_connection(fastmcp_server):
|
|
| 145 |
|
| 146 |
async def test_resource_template(fastmcp_server):
|
| 147 |
"""Test using a resource template with InMemoryClient."""
|
| 148 |
-
client =
|
| 149 |
|
| 150 |
async with client:
|
| 151 |
# First, list templates
|
|
|
|
| 3 |
import pytest
|
| 4 |
from pydantic import AnyUrl
|
| 5 |
|
| 6 |
+
from fastmcp.clients import FastMCPClient
|
| 7 |
from fastmcp.server.server import FastMCP
|
| 8 |
|
| 9 |
|
|
|
|
| 50 |
|
| 51 |
async def test_list_tools(fastmcp_server):
|
| 52 |
"""Test listing tools with InMemoryClient."""
|
| 53 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 54 |
|
| 55 |
async with client:
|
| 56 |
result = await client.list_tools()
|
|
|
|
| 64 |
|
| 65 |
async def test_call_tool(fastmcp_server):
|
| 66 |
"""Test calling a tool with InMemoryClient."""
|
| 67 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 68 |
|
| 69 |
async with client:
|
| 70 |
result = await client.call_tool("greet", {"name": "World"})
|
|
|
|
| 76 |
|
| 77 |
async def test_list_resources(fastmcp_server):
|
| 78 |
"""Test listing resources with InMemoryClient."""
|
| 79 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 80 |
|
| 81 |
async with client:
|
| 82 |
result = await client.list_resources()
|
|
|
|
| 88 |
|
| 89 |
async def test_list_prompts(fastmcp_server):
|
| 90 |
"""Test listing prompts with InMemoryClient."""
|
| 91 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 92 |
|
| 93 |
async with client:
|
| 94 |
result = await client.list_prompts()
|
|
|
|
| 100 |
|
| 101 |
async def test_get_prompt(fastmcp_server):
|
| 102 |
"""Test getting a prompt with InMemoryClient."""
|
| 103 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 104 |
|
| 105 |
async with client:
|
| 106 |
result = await client.get_prompt("welcome", {"name": "Developer"})
|
|
|
|
| 112 |
|
| 113 |
async def test_read_resource(fastmcp_server):
|
| 114 |
"""Test reading a resource with InMemoryClient."""
|
| 115 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 116 |
|
| 117 |
async with client:
|
| 118 |
# Use the URI from the resource we know exists in our server
|
|
|
|
| 130 |
|
| 131 |
async def test_client_connection(fastmcp_server):
|
| 132 |
"""Test that the client connects and disconnects properly."""
|
| 133 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 134 |
|
| 135 |
# Before connection
|
| 136 |
assert not client.is_connected()
|
|
|
|
| 145 |
|
| 146 |
async def test_resource_template(fastmcp_server):
|
| 147 |
"""Test using a resource template with InMemoryClient."""
|
| 148 |
+
client = FastMCPClient(server=fastmcp_server)
|
| 149 |
|
| 150 |
async with client:
|
| 151 |
# First, list templates
|